global-registry-bindings 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -35
  3. data/lib/global_registry_bindings/entity/entity_type_methods.rb +35 -33
  4. data/lib/global_registry_bindings/entity/mdm_methods.rb +9 -19
  5. data/lib/global_registry_bindings/entity/push_entity_methods.rb +31 -38
  6. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +61 -47
  7. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +48 -37
  8. data/lib/global_registry_bindings/exceptions.rb +1 -0
  9. data/lib/global_registry_bindings/global_registry_bindings.rb +129 -46
  10. data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb} +5 -5
  11. data/lib/global_registry_bindings/model/entity.rb +64 -0
  12. data/lib/global_registry_bindings/model/pull_mdm.rb +23 -0
  13. data/lib/global_registry_bindings/model/push_entity.rb +21 -0
  14. data/lib/global_registry_bindings/model/push_relationship.rb +79 -0
  15. data/lib/global_registry_bindings/model/relationship.rb +68 -0
  16. data/lib/global_registry_bindings/options.rb +26 -59
  17. data/lib/global_registry_bindings/options/entity_class_options.rb +34 -0
  18. data/lib/global_registry_bindings/options/entity_instance_options.rb +90 -0
  19. data/lib/global_registry_bindings/options/entity_options_parser.rb +76 -0
  20. data/lib/global_registry_bindings/options/relationship_class_options.rb +37 -0
  21. data/lib/global_registry_bindings/options/relationship_instance_options.rb +131 -0
  22. data/lib/global_registry_bindings/options/relationship_options_parser.rb +98 -0
  23. data/lib/global_registry_bindings/railtie.rb +2 -1
  24. data/lib/global_registry_bindings/version.rb +1 -1
  25. data/lib/global_registry_bindings/worker.rb +25 -0
  26. data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb} +1 -6
  27. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +12 -13
  28. data/lib/global_registry_bindings/workers/push_entity_worker.rb +24 -0
  29. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +17 -7
  30. data/spec/acceptance/global_registry_bindings_spec.rb +50 -40
  31. data/spec/factories/factories.rb +24 -0
  32. data/spec/fixtures/get_entity_types_area.json +44 -0
  33. data/spec/fixtures/post_entities_community.json +8 -0
  34. data/spec/fixtures/post_relationship_types_fancy_org_area.json +16 -0
  35. data/spec/fixtures/put_entities_community_relationship.json +16 -0
  36. data/spec/fixtures/put_entities_fancy_org_area_relationship.json +8 -0
  37. data/spec/fixtures/put_entities_fancy_org_relationship.json +17 -0
  38. data/spec/fixtures/put_entities_person_country_relationship.json +23 -0
  39. data/spec/fixtures/put_entities_relationship_400.json +3 -0
  40. data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +25 -0
  41. data/spec/helpers/sidekiq_helpers.rb +14 -0
  42. data/spec/internal/app/models/address.rb +7 -2
  43. data/spec/internal/app/models/area.rb +7 -0
  44. data/spec/internal/app/models/assignment.rb +5 -4
  45. data/spec/internal/app/models/community.rb +19 -0
  46. data/spec/internal/app/models/country.rb +8 -0
  47. data/spec/internal/app/models/namespaced/person.rb +48 -2
  48. data/spec/internal/app/models/organization.rb +26 -3
  49. data/spec/internal/db/schema.rb +28 -0
  50. data/spec/internal/log/test.log +71023 -0
  51. data/spec/models/address_spec.rb +6 -204
  52. data/spec/models/assignment_spec.rb +40 -186
  53. data/spec/models/organization_spec.rb +106 -92
  54. data/spec/models/person_spec.rb +158 -214
  55. data/spec/models/user_edited_person_spec.rb +2 -2
  56. data/spec/spec_helper.rb +5 -6
  57. data/spec/workers/delete_gr_entity_worker_spec.rb +4 -4
  58. data/spec/workers/pull_mdm_id_worker_spec.rb +94 -32
  59. data/spec/workers/push_entity_worker_spec.rb +476 -0
  60. data/spec/workers/push_relationship_worker_spec.rb +344 -15
  61. metadata +45 -10
  62. data/lib/global_registry_bindings/entity/entity_methods.rb +0 -62
  63. data/lib/global_registry_bindings/options/class_options.rb +0 -62
  64. data/lib/global_registry_bindings/options/instance_options.rb +0 -63
  65. data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +0 -22
  66. data/spec/workers/push_gr_entity_worker_spec.rb +0 -27
@@ -2,108 +2,122 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe 'Organization' do
6
- describe ':push_entity_to_global_registry_async' do
7
- it 'should enqueue sidekiq job' do
8
- org = build(:organization)
9
- expect do
10
- org.push_entity_to_global_registry_async
11
- end.to change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
12
- end
13
- end
5
+ RSpec.describe Organization do
6
+ describe 'after_commit on: :create' do
7
+ context 'without parent' do
8
+ it 'should enqueue sidekiq jobs' do
9
+ organization = build(:organization)
10
+ expect do
11
+ organization.save
12
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
13
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
14
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
15
+ )
16
+ )
17
+ end
14
18
 
15
- describe ':delete_entity_from_global_registry_async' do
16
- it 'should enqueue sidekiq job' do
17
- organization = build(:organization, gr_id: '22527d88-3cba-11e7-b876-129bd0521531')
18
- expect do
19
- organization.delete_entity_from_global_registry_async
20
- end.to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size).by(1)
19
+ context 'with area' do
20
+ it 'should enqueue sidekiq jobs' do
21
+ area = build(:area)
22
+ organization = build(:organization, area: area)
23
+ expect do
24
+ organization.save
25
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2).and(
26
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
27
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
28
+ )
29
+ )
30
+ end
31
+ end
21
32
  end
22
33
 
23
- it 'should not enqueue sidekiq job when missing global_registry_id' do
24
- organization = build(:organization)
25
- expect do
26
- organization.delete_entity_from_global_registry_async
27
- end.not_to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size)
28
- end
29
- end
34
+ context 'with parent' do
35
+ it 'should enqueue sidekiq jobs' do
36
+ parent = build(:organization)
37
+ organization = build(:organization, parent: parent)
38
+ expect do
39
+ organization.save
40
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2).and(
41
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
42
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
43
+ )
44
+ )
45
+ end
30
46
 
31
- describe ':push_entity_to_global_registry' do
32
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
33
- context 'create' do
34
- context '\'fancy_org\' entity_type does not exist' do
35
- let!(:requests) do
36
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
37
- .with(query: { 'filters[name]' => 'fancy_org', 'filters[parent_id]' => nil })
38
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
39
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
40
- .with(body: { entity_type: { name: 'fancy_org', parent_id: nil, field_type: 'entity' } })
41
- .to_return(body: file_fixture('post_entity_types_fancy_org.json'), status: 200),
42
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
43
- .with(body: { entity_type: { name: 'name', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
44
- field_type: 'string' } })
45
- .to_return(status: 200),
46
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
47
- .with(body: { entity_type: { name: 'description', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
48
- field_type: 'string' } })
49
- .to_return(status: 200),
50
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
51
- .with(body: { entity_type: { name: 'start_date', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
52
- field_type: 'date' } })
53
- .to_return(status: 200)]
47
+ context 'with area' do
48
+ it 'should enqueue sidekiq jobs' do
49
+ area = build(:area)
50
+ parent = build(:organization)
51
+ organization = build(:organization, area: area, parent: parent)
52
+ expect do
53
+ organization.save
54
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(3).and(
55
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
56
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
57
+ )
58
+ )
54
59
  end
60
+ end
61
+ end
62
+ end
55
63
 
56
- context 'orphan record' do
57
- let(:organization) { create(:organization) }
58
- let!(:sub_requests) do
59
- [stub_request(:post, 'https://backend.global-registry.org/entities')
60
- .with(body: { entity: { fancy_org: { name: 'Organization', description: 'Fancy Organization',
61
- start_date: '2001-02-03', parent_id: nil,
62
- client_integration_id: organization.id,
63
- client_updated_at: '2001-02-03 00:00:00' } } })
64
- .to_return(body: file_fixture('post_entities_fancy_org.json'), status: 200)]
65
- end
66
-
67
- it 'should create \'fancy_org\' entity_type and push entity' do
68
- organization.push_entity_to_global_registry
69
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
70
- expect(organization.gr_id).to eq 'aebb4170-3f34-11e7-bba6-129bd0521531'
71
- end
72
- end
64
+ describe 'after_commit on: :destroy' do
65
+ context 'without parent' do
66
+ it 'should enqueue sidekiq jobs' do
67
+ organization = create(:organization, gr_id: 'abc')
68
+ clear_sidekiq_jobs_and_locks
69
+ expect do
70
+ organization.destroy
71
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
72
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
73
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
74
+ )
75
+ )
76
+ end
73
77
 
74
- context 'record with a parent' do
75
- let(:parent) { create(:organization, name: 'Parent', description: 'Parent Fancy Organization') }
76
- let(:organization) { create(:organization, parent: parent) }
77
- it 'should create \'fancy_org\' entity_type raise an exception' do
78
- expect do
79
- organization.push_entity_to_global_registry
80
- requests.each { |r| expect(r).to have_been_requested.once }
81
- end.to raise_error GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId
82
- end
78
+ context 'with area' do
79
+ it 'should enqueue sidekiq jobs' do
80
+ area = create(:area, global_registry_id: 'efg')
81
+ organization = create(:organization, area: area, gr_id: 'abc', global_registry_area_id: 'ijk')
82
+ clear_sidekiq_jobs_and_locks
83
+ expect do
84
+ organization.destroy
85
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
86
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
87
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(2)
88
+ )
89
+ )
83
90
  end
91
+ end
92
+ end
84
93
 
85
- context 'record with an exiting parent' do
86
- let(:parent) do
87
- create :organization, name: 'Parent', description: 'Parent Fancy Organization',
88
- gr_id: 'cd5da38a-c336-46a7-b818-dcdd51c4acde'
89
- end
90
- let(:organization) { create(:organization, parent: parent) }
91
- let!(:sub_requests) do
92
- [stub_request(:post, 'https://backend.global-registry.org/entities')
93
- .with(body: { entity: { fancy_org: { name: 'Organization', description: 'Fancy Organization',
94
- start_date: '2001-02-03',
95
- parent_id: 'cd5da38a-c336-46a7-b818-dcdd51c4acde',
96
- client_integration_id: organization.id,
97
- client_updated_at: '2001-02-03 00:00:00' } } })
98
- .to_return(body: file_fixture('post_entities_fancy_org.json'), status: 200)]
99
- end
94
+ context 'with parent' do
95
+ it 'should enqueue sidekiq jobs' do
96
+ parent = create(:organization, gr_id: 'xyz')
97
+ organization = create(:organization, parent: parent, gr_id: 'abc')
98
+ clear_sidekiq_jobs_and_locks
99
+ expect do
100
+ organization.destroy
101
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
102
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
103
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
104
+ )
105
+ )
106
+ end
100
107
 
101
- it 'should create \'fancy_org\' entity_type and push both entities' do
102
- organization.push_entity_to_global_registry
103
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
104
- expect(parent.gr_id).to eq 'cd5da38a-c336-46a7-b818-dcdd51c4acde'
105
- expect(organization.gr_id).to eq 'aebb4170-3f34-11e7-bba6-129bd0521531'
106
- end
108
+ context 'with area' do
109
+ it 'should enqueue sidekiq jobs' do
110
+ area = create(:area, global_registry_id: 'efg')
111
+ parent = create(:organization, gr_id: 'xyz')
112
+ organization = create(:organization, area: area, gr_id: 'abc', global_registry_area_id: 'ijk', parent: parent)
113
+ clear_sidekiq_jobs_and_locks
114
+ expect do
115
+ organization.destroy
116
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
117
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
118
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(2)
119
+ )
120
+ )
107
121
  end
108
122
  end
109
123
  end
@@ -2,245 +2,189 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe 'Person' do
6
- describe ':push_entity_to_global_registry_async' do
7
- it 'should enqueue sidekiq job' do
8
- person = build(:person)
9
- expect do
10
- person.push_entity_to_global_registry_async
11
- end.to change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
12
- end
13
- end
14
-
15
- describe ':delete_entity_from_global_registry_async' do
16
- it 'should enqueue sidekiq job' do
17
- person = build(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531')
18
- expect do
19
- person.delete_entity_from_global_registry_async
20
- end.to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size).by(1)
21
- end
22
-
23
- it 'should not enqueue sidekiq job when missing global_registry_id' do
24
- person = build(:person)
25
- expect do
26
- person.delete_entity_from_global_registry_async
27
- end.not_to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size)
28
- end
29
- end
30
-
31
- describe ':push_entity_to_global_registry' do
32
- context 'create' do
33
- let(:person) { create(:person) }
34
-
35
- context '\'person\' entity_type does not exist' do
36
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
37
- let!(:requests) do
38
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
39
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
40
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
41
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
42
- .with(body: { entity_type: { name: 'person', parent_id: nil, field_type: 'entity' } })
43
- .to_return(body: file_fixture('post_entity_types_person.json'), status: 200),
44
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
45
- .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
46
- field_type: 'string' } })
47
- .to_return(status: 200),
48
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
49
- .with(body: { entity_type: { name: 'last_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
50
- field_type: 'string' } })
51
- .to_return(status: 200),
52
- stub_request(:post, 'https://backend.global-registry.org/entities')
53
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
54
- client_integration_id: person.id,
55
- client_updated_at: '2001-02-03 00:00:00',
56
- authentication: {
57
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
58
- } } } })
59
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
60
- end
61
-
62
- it 'should create \'person\' entity_type and push entity' do
63
- person.push_entity_to_global_registry
64
- requests.each { |r| expect(r).to have_been_requested.once }
65
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
66
- end
5
+ RSpec.describe Namespaced::Person do
6
+ describe 'after_commit on: :create' do
7
+ context 'without associations' do
8
+ it 'should enqueue sidekiq jobs' do
9
+ person = build(:person)
10
+ expect do
11
+ person.save
12
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
13
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
14
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
15
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
16
+ )
17
+ )
18
+ )
67
19
  end
20
+ end
68
21
 
69
- context '\'person\' entity_type exists' do
70
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
71
- let!(:requests) do
72
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
73
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
74
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
75
- stub_request(:post, 'https://backend.global-registry.org/entities')
76
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
77
- client_integration_id: person.id,
78
- client_updated_at: '2001-02-03 00:00:00',
79
- authentication: {
80
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
81
- } } } })
82
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
83
- end
84
-
85
- it 'should skip creating entity_type and push the entity' do
86
- person.push_entity_to_global_registry
87
- requests.each { |r| expect(r).to have_been_requested.once }
88
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
89
- end
22
+ context 'with country_of_service' do
23
+ it 'should enqueue sidekiq jobs' do
24
+ country = build(:country)
25
+ person = build(:person, country_of_service: country)
26
+ expect do
27
+ person.save
28
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2).and(
29
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
30
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
31
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
32
+ )
33
+ )
34
+ )
90
35
  end
36
+ end
91
37
 
92
- context 'partial \'person\' entity_type exists' do
93
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
94
- let!(:requests) do
95
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
96
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
97
- .to_return(body: file_fixture('get_entity_types_person_partial.json'), status: 200),
98
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
99
- .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
100
- field_type: 'string' } })
101
- .to_return(status: 200),
102
- stub_request(:post, 'https://backend.global-registry.org/entities')
103
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
104
- client_integration_id: person.id,
105
- client_updated_at: '2001-02-03 00:00:00',
106
- authentication: {
107
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
108
- } } } })
109
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
110
- end
111
-
112
- it 'should skip creating entity_type and push the entity' do
113
- person.push_entity_to_global_registry
114
- requests.each { |r| expect(r).to have_been_requested.once }
115
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
116
- end
38
+ context 'with country_of_residence' do
39
+ it 'should enqueue sidekiq jobs' do
40
+ country = build(:country)
41
+ person = build(:person, country_of_residence: country)
42
+ expect do
43
+ person.save
44
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2).and(
45
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
46
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
47
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
48
+ )
49
+ )
50
+ )
117
51
  end
52
+ end
118
53
 
119
- context '\'person\' entity_type is cached' do
120
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
121
- before :each do
122
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
123
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
124
- end
125
-
126
- it 'should skip creating entity_type and push the entity' do
127
- request = stub_request(:post, 'https://backend.global-registry.org/entities')
128
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
129
- client_integration_id: person.id,
130
- client_updated_at: '2001-02-03 00:00:00',
131
- authentication: {
132
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
133
- } } } })
134
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
135
- person.push_entity_to_global_registry
136
- expect(request).to have_been_requested.once
137
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
138
- end
54
+ context 'with country_of_service and country_of_residence' do
55
+ it 'should enqueue sidekiq jobs' do
56
+ country = build(:country)
57
+ person = build(:person, country_of_residence: country, country_of_service: country)
58
+ expect do
59
+ person.save
60
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2).and(
61
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
62
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(2).and(
63
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
64
+ )
65
+ )
66
+ )
139
67
  end
140
68
  end
69
+ end
141
70
 
142
- context 'update' do
143
- let(:person) { create(:person, global_registry_id: 'f8d20318-2ff2-4a98-a5eb-e9d840508bf1') }
144
- context '\'person\' entity_type is cached' do
145
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
146
- before :each do
147
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
148
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
149
- end
71
+ describe 'after_commit on: :update' do
72
+ context 'update person attribute' do
73
+ it 'should enqueue sidekiq jobs' do
74
+ person = create(:person, global_registry_id: 'dd555dbf-f3db-4158-a50c-50d3f26347e8')
75
+ clear_sidekiq_jobs_and_locks
76
+ expect do
77
+ person.first_name = 'Anthony'
78
+ person.save
79
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
80
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
81
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
82
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
83
+ )
84
+ )
85
+ )
86
+ end
150
87
 
151
- it 'should skip creating entity_type and update the entity' do
152
- request = stub_request(:put,
153
- 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
154
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
155
- client_integration_id: person.id,
156
- client_updated_at: '2001-02-03 00:00:00',
157
- authentication: {
158
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
159
- } } } })
160
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
161
- person.push_entity_to_global_registry
162
- expect(request).to have_been_requested.once
88
+ context 'with associations' do
89
+ it 'should enqueue sidekiq jobs' do
90
+ country = create(:country)
91
+ person = create(:person, country_of_residence: country, country_of_service: country)
92
+ clear_sidekiq_jobs_and_locks
93
+ expect do
94
+ person.first_name = 'Anthony'
95
+ person.save
96
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
97
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
98
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(2).and(
99
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
100
+ )
101
+ )
102
+ )
163
103
  end
164
104
 
165
- context 'invalid entity id' do
166
- let!(:requests) do
167
- [stub_request(:put,
168
- 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
169
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
170
- client_integration_id: person.id,
171
- client_updated_at: '2001-02-03 00:00:00',
172
- authentication: {
173
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
174
- } } } })
175
- .to_return(status: 404),
176
- stub_request(:post, 'https://backend.global-registry.org/entities')
177
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
178
- client_integration_id: person.id,
179
- client_updated_at: '2001-02-03 00:00:00',
180
- authentication: {
181
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
182
- } } } })
183
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
105
+ context 'country_of_residence removed' do
106
+ it 'should enqueue sidekiq jobs' do
107
+ country = create(:country)
108
+ person = create(:person, country_of_residence: country, country_of_service: country,
109
+ country_of_residence_gr_id: '4fa555dd-a067-478e-8765-8faa9483cc56')
110
+ clear_sidekiq_jobs_and_locks
111
+ expect do
112
+ person.country_of_residence = nil
113
+ person.save
114
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
115
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
116
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
117
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
118
+ )
119
+ )
120
+ )
184
121
  end
122
+ end
185
123
 
186
- it 'should push entity as create' do
187
- person.push_entity_to_global_registry
188
- requests.each { |r| expect(r).to have_been_requested.once }
189
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
124
+ context 'country_of_service changed' do
125
+ it 'should enqueue sidekiq jobs' do
126
+ country = create(:country, global_registry_id: 'f078eb70-5ddd-4941-9b06-a39576d9952f')
127
+ country2 = create(:country, name: 'Peru', global_registry_id: 'f078eb70-5ddd-4941-9b06-a39576d9963c')
128
+ person = create(:person, country_of_residence: country, country_of_service: country,
129
+ country_of_residence_gr_id: '4fa555dd-a067-478e-8765-8faa9483cc56',
130
+ country_of_service_gr_id: '89f81f6e-7baf-44d9-8f3a-55bf7c652dcc')
131
+ request = stub_request(:delete,
132
+ 'https://backend.global-registry.org/entities/89f81f6e-7baf-44d9-8f3a-55bf7c652dcc')
133
+ .to_return(status: 200)
134
+
135
+ clear_sidekiq_jobs_and_locks
136
+ expect do
137
+ person.country_of_service = country2
138
+ person.save
139
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1).and(
140
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1).and(
141
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(2).and(
142
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
143
+ )
144
+ )
145
+ )
146
+ expect(request).to have_been_requested.once
190
147
  end
191
148
  end
192
149
  end
193
150
  end
194
151
  end
195
152
 
196
- describe ':pull_mdm_id_from_global_registry_async' do
197
- it 'should enqueue sidekiq job' do
198
- person = build(:person)
199
- expect do
200
- person.pull_mdm_id_from_global_registry_async
201
- end.to change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1)
202
- end
203
- end
204
-
205
- describe ':pull_mdm_id_from_global_registry' do
206
- context 'record missing global_registry_id' do
207
- let(:person) { create(:person) }
208
-
209
- it 'should raise an exception' do
153
+ describe 'after_commit on: :destroy' do
154
+ context 'without associations' do
155
+ it 'should enqueue sidekiq jobs' do
156
+ person = create(:person, global_registry_id: 'dd555dbf-f3db-4158-a50c-50d3f26347e8')
157
+ clear_sidekiq_jobs_and_locks
210
158
  expect do
211
- person.pull_mdm_id_from_global_registry
212
- end.to raise_error GlobalRegistry::Bindings::RecordMissingGlobalRegistryId
159
+ person.destroy
160
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
161
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(0).and(
162
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
163
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
164
+ )
165
+ )
166
+ )
213
167
  end
214
168
  end
215
169
 
216
- context 'entity missing mdm id' do
217
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
218
- let!(:request) do
219
- stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
220
- .with(query: { 'filters[owned_by]' => 'mdm' })
221
- .to_return(body: file_fixture('get_entities_person.json'), status: 200)
222
- end
223
-
224
- it 'should raise an exception' do
225
- expect do
226
- person.pull_mdm_id_from_global_registry
227
- end.to raise_error GlobalRegistry::Bindings::EntityMissingMdmId
228
- end
229
- end
230
-
231
- context 'entity missing mdm id' do
232
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
233
- let!(:request) do
234
- stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
235
- .with(query: { 'filters[owned_by]' => 'mdm' })
236
- .to_return(body: file_fixture('get_entities_person_mdm.json'), status: 200)
237
- end
238
-
239
- it 'should raise an exception' do
170
+ context 'with associations' do
171
+ it 'should enqueue sidekiq jobs' do
172
+ resident = create(:country, global_registry_id: 'f078eb70-5ddd-4941-9b06-a39576d9952f')
173
+ employee = create(:country, global_registry_id: 'f078eb70-5ddd-4941-9b06-a39576d99639')
174
+ person = create(:person, country_of_residence: resident, country_of_service: employee,
175
+ global_registry_id: 'dd555dbf-f3db-4158-a50c-50d3f26347e8',
176
+ country_of_residence_gr_id: '4fa555dd-a067-478e-8765-8faa9483cc56',
177
+ country_of_service_gr_id: '89f81f6e-7baf-44d9-8f3a-55bf7c652dcc')
178
+ clear_sidekiq_jobs_and_locks
240
179
  expect do
241
- person.pull_mdm_id_from_global_registry
242
- expect(person.global_registry_mdm_id).to eq 'c81340b2-7e57-4978-b6b9-396f21bb0bb2'
243
- end.not_to raise_error
180
+ person.destroy
181
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
182
+ change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(0).and(
183
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
184
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(3)
185
+ )
186
+ )
187
+ )
244
188
  end
245
189
  end
246
190
  end