Skip to content

Commit

Permalink
Remove 'fail' restriction on sbJson contact contactType. Closes issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
stansmith907 committed Sep 14, 2017
1 parent 3df3e1d commit fc6c22b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 105 deletions.
12 changes: 7 additions & 5 deletions lib/adiwg/mdtranslator/readers/sbJson/modules/module_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ def self.unpack(hSbJson, aContacts, hResponseObj)

hContact[:contactId] = UUIDTools::UUID.random_create.to_s

# contact - contactType (required) [ person | organization ]
# contact - contactType [ person | organization ]
if hSbContact.has_key?('contactType')
if %w(person organization).include?(hSbContact['contactType'])
if hSbContact['contactType'].nil? || hSbContact['contactType'] == ''
hResponseObj[:readerExecutionMessages] << 'Contact contactType is missing'
hContact[:isOrganization] = false
elsif %w(person organization).include?(hSbContact['contactType'])
hContact[:isOrganization] = true if hSbContact['contactType'] == 'organization'
else
hResponseObj[:readerExecutionMessages] << 'Contact contactType must be person or organization'
hResponseObj[:readerExecutionPass] = false
return nil
end
end
if hSbContact['contactType'].nil? || hSbContact['contactType'] == ''
else
hResponseObj[:readerExecutionMessages] << 'Contact contactType is missing'
return nil
hContact[:isOrganization] = false
end

# contact - name (required)
Expand Down
133 changes: 35 additions & 98 deletions test/readers/sbJson/tc_sbjson_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,39 @@ def test_complete_contact

# test response object
assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_empty_elements

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(1)
hIn0 = hIn['contacts'][0]
hIn0['oldPartyId'] = ''
hIn0['sourceId'] = ''
hIn0['organizationsPerson'] = ''
hIn0['ttyPhone'] = ''
hIn0['officePhone'] = ''
hIn0['faxPhone'] = ''
hIn0['hours'] = ''
hIn0['instructions'] = ''
hIn0['email'] = ''
hIn0['active'] = ''
hIn0['jobTitle'] = ''
hIn0['personalTitle'] = ''
hIn0['firstName'] = ''
hIn0['middleName'] = ''
hIn0['lastName'] = ''
hIn0['note'] = ''
hIn0['aliases'] = []
hIn0['fbmsCodes'] = []
hIn0['logoUrl'] = ''
hIn0['smallLogoUrl'] = ''
hIn0['organization'] = {}
hIn0['primaryLocation'] = {}
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hContact = hIn['contacts'][0]
hContact['contactType'] = ''
hContact['oldPartyId'] = ''
hContact['sourceId'] = ''
hContact['organizationsPerson'] = ''
hContact['ttyPhone'] = ''
hContact['officePhone'] = ''
hContact['faxPhone'] = ''
hContact['hours'] = ''
hContact['instructions'] = ''
hContact['email'] = ''
hContact['active'] = ''
hContact['jobTitle'] = ''
hContact['personalTitle'] = ''
hContact['firstName'] = ''
hContact['middleName'] = ''
hContact['lastName'] = ''
hContact['note'] = ''
hContact['aliases'] = []
hContact['fbmsCodes'] = []
hContact['logoUrl'] = ''
hContact['smallLogoUrl'] = ''
hContact['organization'] = {}
hContact['primaryLocation'] = {}

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -143,8 +144,8 @@ def test_contact_empty_elements
hContact = metadata[0]
refute_nil hContact[:contactId]
refute hContact[:isOrganization]
assert_equal 'Robert N Prescott', hContact[:name]
assert_equal 'Distributor', hContact[:contactType]
assert_equal 'Jordan S Read', hContact[:name]
assert_equal 'Metadata Contact', hContact[:contactType]

# empty elements
assert_nil hContact[:positionName]
Expand All @@ -158,15 +159,15 @@ def test_contact_empty_elements
assert_nil hContact[:contactInstructions]

assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_missing_elements

hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -192,16 +193,16 @@ def test_contact_missing_elements
assert_nil hContact[:contactInstructions]

assert hResponse[:readerExecutionPass]
assert_empty hResponse[:readerExecutionMessages]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_name_empty

hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['name'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -214,42 +215,10 @@ def test_contact_name_empty

def test_contact_name_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('name')
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_contactType_empty

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['contactType'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_contactType_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('contactType')
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn['contacts'][0].delete('name')

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand All @@ -262,42 +231,10 @@ def test_contact_contactType_missing

def test_contact_contactType_invalid

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['contactType'] = 'badName'
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_type_empty

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0]['type'] = ''
hResponse = Marshal::load(Marshal.dump(@@responseObj))

metadata = @@NameSpace.unpack(hIn, [], hResponse)

# test array
assert_nil metadata
refute hResponse[:readerExecutionPass]
refute_empty hResponse[:readerExecutionMessages]

end

def test_contact_type_missing

hIn = Marshal::load(Marshal.dump(@@hIn))
hIn['contacts'].delete_at(0)
hIn['contacts'][0].delete('type')
hResponse = Marshal::load(Marshal.dump(@@responseObj))
hIn['contacts'][0]['contactType'] = 'badName'

metadata = @@NameSpace.unpack(hIn, [], hResponse)

Expand Down
3 changes: 1 addition & 2 deletions test/readers/sbJson/testData/contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
},
{
"name": "Jordan S Read",
"type": "Metadata Contact",
"contactType": "person"
"type": "Metadata Contact"
}
]
}

0 comments on commit fc6c22b

Please sign in to comment.