Enhanced tests.

This commit is contained in:
Martin Edenhofer 2016-04-26 08:48:44 +02:00
parent 671f513461
commit c3743682ec
6 changed files with 340 additions and 30 deletions

View file

@ -149,6 +149,15 @@ class Transaction::ClearbitEnrichment
# create new organization # create new organization
if !external_syn_organization if !external_syn_organization
# if organization is already assigned, do not create a new one
if user.organization_id
if user_has_changed
user.save
Observer::Transaction.commit
end
return
end
# can't create organization without name # can't create organization without name
if organization_sync_values['organization.name'].empty? if organization_sync_values['organization.name'].empty?
Observer::Transaction.commit Observer::Transaction.commit

View file

@ -0,0 +1,96 @@
{
"person": null,
"company": {
"id": "273d8666-9d70-43dc-836b-a47a88293905-3",
"name": "Znuny / ES for OTRS",
"legalName": null,
"domain": "znuny.com",
"domainAliases": [
"znuny.de"
],
"url": "http://znuny.com",
"site": {
"url": "http://znuny.com",
"title": "Support, Consulting, Development and Training for OTRS - Znuny GmbH",
"h1": "We make OTRS support easy!",
"metaDescription": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH",
"metaAuthor": null,
"phoneNumbers": [
"+49 30 6098541",
"+49 4107 15880339",
"+49 8601 81017925",
"+49 4107 15880186",
"+49 8602 16139061"
],
"emailAddresses": [
"info@znuny.com"
]
},
"category": {
"sector": "Industrials",
"industryGroup": "Commercial & Professional Services",
"industry": "Professional Services",
"subIndustry": "Consulting"
},
"tags": [
"Consulting & Professional Services",
"Corporate & Business",
"Information Technology & Services"
],
"description": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH",
"foundedDate": null,
"location": "Marienstraße 11, 10117 Berlin, Germany",
"timeZone": "Europe/Berlin",
"utcOffset": 2,
"geo": {
"streetNumber": "11",
"streetName": "Marienstraße",
"subPremise": null,
"city": "Berlin",
"postalCode": "10117",
"state": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DE",
"lat": 52.52182,
"lng": 13.38268
},
"logo": "https://logo.clearbit.com/znuny.com",
"facebook": {
"handle": null
},
"linkedin": {
"handle": "company/znuny-gmbh"
},
"twitter": {
"handle": "znuny",
"id": "293437546",
"bio": "Enterprise Services for OTRS! We love to do what we can do!",
"followers": 85,
"following": 63,
"location": "Berlin",
"site": "http://t.co/miuzrhoHeG",
"avatar": "https://pbs.twimg.com/profile_images/2460325455/hix7so4b0h0miq9gwkw8_normal.png"
},
"crunchbase": {
"handle": null
},
"emailProvider": false,
"type": "private",
"ticker": null,
"phone": null,
"metrics": {
"alexaUsRank": null,
"alexaGlobalRank": 10086408,
"googleRank": 3,
"employees": null,
"marketCap": null,
"raised": null,
"annualRevenue": null
},
"tech": [
"google_analytics",
"ruby_on_rails"
]
}
}

View file

@ -1,16 +1,40 @@
{ {
"person": null, "person": {
"id": "4db7cfeb-8017-4aac-b4b9-debb6d3142c0-4",
"name": {
"fullName": "Fred Jupiter",
"givenName": "Fred",
"familyName": "Jupiter"
},
"email": "testing4@znuny.com",
"gender": null,
"location": "Berlin, Berlin, DE",
"timeZone": "Europe/Berlin",
"utcOffset": 2,
"geo": {
"city": "Berlin",
"state": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DE",
"lat": 52.52000659999999,
"lng": 13.404954
},
"bio": "some_fred_bio",
"site": "http://example.com/",
"avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/4db7cfeb-8017-4aac-b4b9-debb6d3142c0"
},
"company": { "company": {
"id": "273d8666-9d70-43dc-836b-a47a88293905", "id": "273d8666-9d70-43dc-836b-a47a88293905-4",
"name": "Znuny / ES for OTRS", "name": "ZnunyOfFred",
"legalName": null, "legalName": null,
"domain": "znuny.com", "domain": "fred.znuny.com",
"domainAliases": [ "domainAliases": [
"znuny.de" "znuny.de"
], ],
"url": "http://znuny.com", "url": "http://fred.znuny.com",
"site": { "site": {
"url": "http://znuny.com", "url": "http://fred.znuny.com",
"title": "Support, Consulting, Development and Training for OTRS - Znuny GmbH", "title": "Support, Consulting, Development and Training for OTRS - Znuny GmbH",
"h1": "We make OTRS support easy!", "h1": "We make OTRS support easy!",
"metaDescription": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH", "metaDescription": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH",
@ -37,7 +61,7 @@
"Corporate & Business", "Corporate & Business",
"Information Technology & Services" "Information Technology & Services"
], ],
"description": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH", "description": "ZnunyOfFred GmbH",
"foundedDate": null, "foundedDate": null,
"location": "Marienstraße 11, 10117 Berlin, Germany", "location": "Marienstraße 11, 10117 Berlin, Germany",
"timeZone": "Europe/Berlin", "timeZone": "Europe/Berlin",

View file

@ -1,10 +1,10 @@
{ {
"person": { "person": {
"id": "4db7cfeb-8017-4aac-b4b9-debb6d3142c0-1", "id": "4db7cfeb-8017-4aac-b4b9-debb6d3142c0-5",
"name": { "name": {
"fullName": "Bob Smith", "fullName": "Alex Dont",
"givenName": "Bob", "givenName": "Alex",
"familyName": "Smith" "familyName": "Dont"
}, },
"email": "testing5@znuny.com", "email": "testing5@znuny.com",
"gender": null, "gender": null,
@ -20,14 +20,14 @@
"lat": 52.52000659999999, "lat": 52.52000659999999,
"lng": 13.404954 "lng": 13.404954
}, },
"bio": "some_bio", "bio": "some_bio_alex",
"site": "http://example.com/", "site": "http://example.com/",
"avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/4db7cfeb-8017-4aac-b4b9-debb6d3142c0" "avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/4db7cfeb-8017-4aac-b4b9-debb6d3142c0"
}, },
"company": { "company": {
"id": "273d8666-9d70-43dc-836b-a47a88293905", "id": "273d8666-9d70-43dc-836b-a47a88293905-3",
"name": "Znuny2", "name": "Znuny / ES for OTRS",
"legalName": null, "legalName": "Znuny GmbH",
"domain": "znuny.com", "domain": "znuny.com",
"domainAliases": [ "domainAliases": [
"znuny.de" "znuny.de"
@ -61,7 +61,7 @@
"Corporate & Business", "Corporate & Business",
"Information Technology & Services" "Information Technology & Services"
], ],
"description": "Znuny2 GmbH", "description": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH",
"foundedDate": null, "foundedDate": null,
"location": "Marienstraße 11, 10117 Berlin, Germany", "location": "Marienstraße 11, 10117 Berlin, Germany",
"timeZone": "Europe/Berlin", "timeZone": "Europe/Berlin",

View file

@ -0,0 +1,120 @@
{
"person": {
"id": "4db7cfeb-8017-4aac-b4b9-debb6d3142c0-5",
"name": {
"fullName": "Bob Smith",
"givenName": "Bob",
"familyName": "Smith"
},
"email": "testing6@znuny.com",
"gender": null,
"location": "Berlin, Berlin, DE",
"timeZone": "Europe/Berlin",
"utcOffset": 2,
"geo": {
"city": "Berlin",
"state": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DE",
"lat": 52.52000659999999,
"lng": 13.404954
},
"bio": "some_bio",
"site": "http://example.com/",
"avatar": "https://d1ts43dypk8bqh.cloudfront.net/v1/avatars/4db7cfeb-8017-4aac-b4b9-debb6d3142c0"
},
"company": {
"id": "273d8666-9d70-43dc-836b-a47a88293905-5",
"name": "Znuny2",
"legalName": null,
"domain": "znuny.com",
"domainAliases": [
"znuny.de"
],
"url": "http://znuny.com",
"site": {
"url": "http://znuny.com",
"title": "Support, Consulting, Development and Training for OTRS - Znuny GmbH",
"h1": "We make OTRS support easy!",
"metaDescription": "OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH",
"metaAuthor": null,
"phoneNumbers": [
"+49 30 6098541",
"+49 4107 15880339",
"+49 8601 81017925",
"+49 4107 15880186",
"+49 8602 16139061"
],
"emailAddresses": [
"info@znuny.com"
]
},
"category": {
"sector": "Industrials",
"industryGroup": "Commercial & Professional Services",
"industry": "Professional Services",
"subIndustry": "Consulting"
},
"tags": [
"Consulting & Professional Services",
"Corporate & Business",
"Information Technology & Services"
],
"description": "Znuny2 GmbH",
"foundedDate": null,
"location": "Marienstraße 11, 10117 Berlin, Germany",
"timeZone": "Europe/Berlin",
"utcOffset": 2,
"geo": {
"streetNumber": "11",
"streetName": "Marienstraße",
"subPremise": null,
"city": "Berlin",
"postalCode": "10117",
"state": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DE",
"lat": 52.52182,
"lng": 13.38268
},
"logo": "https://logo.clearbit.com/znuny.com",
"facebook": {
"handle": null
},
"linkedin": {
"handle": "company/znuny-gmbh"
},
"twitter": {
"handle": "znuny",
"id": "293437546",
"bio": "Enterprise Services for OTRS! We love to do what we can do!",
"followers": 85,
"following": 63,
"location": "Berlin",
"site": "http://t.co/miuzrhoHeG",
"avatar": "https://pbs.twimg.com/profile_images/2460325455/hix7so4b0h0miq9gwkw8_normal.png"
},
"crunchbase": {
"handle": null
},
"emailProvider": false,
"type": "private",
"ticker": null,
"phone": null,
"metrics": {
"alexaUsRank": null,
"alexaGlobalRank": 10086408,
"googleRank": 3,
"employees": null,
"marketCap": null,
"raised": null,
"annualRevenue": null
},
"tech": [
"google_analytics",
"ruby_on_rails"
]
}
}

View file

@ -160,7 +160,7 @@ class ClearbitTest < ActiveSupport::TestCase
customer3 = User.create( customer3 = User.create(
firstname: '', firstname: '',
lastname: '', lastname: '',
email: 'testing4@znuny.com', email: 'testing3@znuny.com',
note: '', note: '',
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
@ -186,12 +186,13 @@ class ClearbitTest < ActiveSupport::TestCase
assert_equal(false, organization3_lookup.shared) assert_equal(false, organization3_lookup.shared)
assert_equal('OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH', organization3_lookup.note) assert_equal('OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH', organization3_lookup.note)
# case 4 - no person / real api call # case 4 - person with organization but organization is already assigned (own created)
customer4 = User.create( customer4 = User.create(
firstname: '', firstname: '',
lastname: '', lastname: '',
email: 'testing5@clearbit.com', email: 'testing4@znuny.com',
note: '', note: '',
organization_id: 1,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
@ -200,21 +201,81 @@ class ClearbitTest < ActiveSupport::TestCase
Observer::Transaction.commit Observer::Transaction.commit
Delayed::Worker.new.work_off Delayed::Worker.new.work_off
assert_not(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer4.id)) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer4.id))
customer4_lookup = User.lookup(id: customer4.id) customer4_lookup = User.lookup(id: customer4.id)
assert_not_equal(customer4.updated_at, customer4_lookup.updated_at) assert_not_equal(customer4.updated_at, customer4_lookup.updated_at)
assert_equal('', customer4_lookup.firstname) assert_equal('Fred', customer4_lookup.firstname)
assert_equal('', customer4_lookup.lastname) assert_equal('Jupiter', customer4_lookup.lastname)
assert_equal('', customer4_lookup.note) assert_equal('some_fred_bio', customer4_lookup.note)
assert_equal('http://clearbit.com', customer4_lookup.web) assert_equal('http://fred.znuny.com', customer4_lookup.web)
assert_equal('', customer4_lookup.address) assert_equal('Marienstraße 11, 10117 Berlin, Germany', customer4_lookup.address)
organization4_lookup = Organization.find_by(name: 'Clearbit') organization4_lookup = Organization.find_by(name: 'ZnunyOfFred')
assert(ExternalSync.find_by(source: 'clearbit', object: 'Organization', o_id: organization4_lookup.id)) assert_not(organization4_lookup)
assert_equal(false, organization4_lookup.shared)
assert_equal('Clearbit provides powerful products and data APIs to help your business grow. Contact enrichment, lead generation, financial compliance, and more...', organization4_lookup.note) # case 5 - person with organization but organization is already assigned (own created)
customer5 = User.create(
firstname: '',
lastname: '',
email: 'testing5@znuny.com',
note: '',
organization_id: organization3_lookup.id,
updated_by_id: 1,
created_by_id: 1,
)
assert(customer5)
Observer::Transaction.commit
Delayed::Worker.new.work_off
assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer5.id))
customer5_lookup = User.lookup(id: customer5.id)
assert_not_equal(customer5.updated_at, customer5_lookup.updated_at)
assert_equal('Alex', customer5_lookup.firstname)
assert_equal('Dont', customer5_lookup.lastname)
assert_equal('some_bio_alex', customer5_lookup.note)
assert_equal('http://znuny.com', customer5_lookup.web)
assert_equal('Marienstraße 11, 10117 Berlin, Germany', customer5_lookup.address)
organization5_lookup = Organization.find_by(name: 'Znuny GmbH')
assert_equal(organization3_lookup.id, organization5_lookup.id)
assert(ExternalSync.find_by(source: 'clearbit', object: 'Organization', o_id: organization5_lookup.id))
assert_equal(false, organization5_lookup.shared)
assert_equal('OTRS Support, Consulting, Development, Training and Customizing - Znuny GmbH', organization5_lookup.note)
# case 6 - no person / real api call
customer6 = User.create(
firstname: '',
lastname: '',
email: 'testing6@clearbit.com',
note: '',
updated_by_id: 1,
created_by_id: 1,
)
assert(customer6)
Observer::Transaction.commit
Delayed::Worker.new.work_off
assert_not(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer6.id))
customer6_lookup = User.lookup(id: customer6.id)
assert_not_equal(customer6.updated_at, customer6_lookup.updated_at)
assert_equal('', customer6_lookup.firstname)
assert_equal('', customer6_lookup.lastname)
assert_equal('', customer6_lookup.note)
assert_equal('http://clearbit.com', customer6_lookup.web)
assert_equal('', customer6_lookup.address)
organization6_lookup = Organization.find_by(name: 'Clearbit')
assert(ExternalSync.find_by(source: 'clearbit', object: 'Organization', o_id: organization6_lookup.id))
assert_equal(false, organization6_lookup.shared)
assert_equal('Clearbit provides powerful products and data APIs to help your business grow. Contact enrichment, lead generation, financial compliance, and more...', organization6_lookup.note)
end end
@ -253,7 +314,7 @@ class ClearbitTest < ActiveSupport::TestCase
customer1 = User.create( customer1 = User.create(
firstname: '', firstname: '',
lastname: 'Should be still there', lastname: 'Should be still there',
email: 'testing5@znuny.com', email: 'testing6@znuny.com',
note: '', note: '',
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,