global-registry-bindings 0.6.2 → 0.6.3

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/lib/global_registry_bindings/entity/entity_type_methods.rb +16 -18
  3. data/lib/global_registry_bindings/entity/mdm_methods.rb +11 -12
  4. data/lib/global_registry_bindings/entity/push_entity_methods.rb +23 -23
  5. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +18 -18
  6. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +26 -26
  7. data/lib/global_registry_bindings/exceptions.rb +7 -2
  8. data/lib/global_registry_bindings/global_registry_bindings.rb +19 -19
  9. data/lib/global_registry_bindings/model/delete_entity.rb +4 -4
  10. data/lib/global_registry_bindings/model/entity.rb +25 -25
  11. data/lib/global_registry_bindings/model/pull_mdm.rb +5 -5
  12. data/lib/global_registry_bindings/model/push_entity.rb +4 -4
  13. data/lib/global_registry_bindings/model/push_relationship.rb +10 -8
  14. data/lib/global_registry_bindings/model/relationship.rb +18 -18
  15. data/lib/global_registry_bindings/options/entity_class_options.rb +15 -15
  16. data/lib/global_registry_bindings/options/entity_instance_options.rb +11 -11
  17. data/lib/global_registry_bindings/options/entity_options_parser.rb +3 -3
  18. data/lib/global_registry_bindings/options/relationship_class_options.rb +22 -22
  19. data/lib/global_registry_bindings/options/relationship_instance_options.rb +12 -12
  20. data/lib/global_registry_bindings/options/relationship_options_parser.rb +7 -7
  21. data/lib/global_registry_bindings/options.rb +6 -6
  22. data/lib/global_registry_bindings/railtie.rb +7 -7
  23. data/lib/global_registry_bindings/testing.rb +3 -3
  24. data/lib/global_registry_bindings/version.rb +3 -3
  25. data/lib/global_registry_bindings/worker.rb +5 -5
  26. data/lib/global_registry_bindings/workers/delete_entity_worker.rb +3 -3
  27. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +5 -5
  28. data/lib/global_registry_bindings/workers/push_entity_worker.rb +6 -6
  29. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +6 -6
  30. data/lib/global_registry_bindings.rb +3 -3
  31. metadata +16 -156
  32. data/spec/acceptance/global_registry_bindings_spec.rb +0 -191
  33. data/spec/factories/factories.rb +0 -72
  34. data/spec/fixtures/get_entities_person.json +0 -8
  35. data/spec/fixtures/get_entities_person_mdm.json +0 -13
  36. data/spec/fixtures/get_entities_person_relationship.json +0 -32
  37. data/spec/fixtures/get_entity_types.json +0 -9
  38. data/spec/fixtures/get_entity_types_address.json +0 -59
  39. data/spec/fixtures/get_entity_types_address_partial.json +0 -43
  40. data/spec/fixtures/get_entity_types_area.json +0 -44
  41. data/spec/fixtures/get_entity_types_community.json +0 -18
  42. data/spec/fixtures/get_entity_types_fancy_org.json +0 -43
  43. data/spec/fixtures/get_entity_types_fancy_org_assignment.json +0 -35
  44. data/spec/fixtures/get_entity_types_fancy_org_partial.json +0 -35
  45. data/spec/fixtures/get_entity_types_ministry.json +0 -18
  46. data/spec/fixtures/get_entity_types_person.json +0 -42
  47. data/spec/fixtures/get_entity_types_person_partial.json +0 -34
  48. data/spec/fixtures/get_relationship_types.json +0 -9
  49. data/spec/fixtures/get_relationship_types_person_fancy_org.json +0 -41
  50. data/spec/fixtures/get_relationship_types_person_fancy_org_partial.json +0 -33
  51. data/spec/fixtures/post_entities_community.json +0 -8
  52. data/spec/fixtures/post_entities_fancy_org.json +0 -8
  53. data/spec/fixtures/post_entities_fancy_org_parent.json +0 -8
  54. data/spec/fixtures/post_entities_person.json +0 -8
  55. data/spec/fixtures/post_entity_types_address.json +0 -9
  56. data/spec/fixtures/post_entity_types_fancy_org.json +0 -9
  57. data/spec/fixtures/post_entity_types_person.json +0 -9
  58. data/spec/fixtures/post_relationship_types_assigned_by.json +0 -16
  59. data/spec/fixtures/post_relationship_types_community_ministry.json +0 -16
  60. data/spec/fixtures/post_relationship_types_fancy_org_area.json +0 -16
  61. data/spec/fixtures/post_relationship_types_person_fancy_org.json +0 -16
  62. data/spec/fixtures/put_entities_address.json +0 -20
  63. data/spec/fixtures/put_entities_community_relationship.json +0 -16
  64. data/spec/fixtures/put_entities_fancy_org_area_relationship.json +0 -8
  65. data/spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json +0 -20
  66. data/spec/fixtures/put_entities_fancy_org_relationship.json +0 -17
  67. data/spec/fixtures/put_entities_person_country_relationship.json +0 -23
  68. data/spec/fixtures/put_entities_person_relationship.json +0 -29
  69. data/spec/fixtures/put_entities_relationship.json +0 -8
  70. data/spec/fixtures/put_entities_relationship_400.json +0 -3
  71. data/spec/fixtures/put_relationship_types_fields.json +0 -33
  72. data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +0 -25
  73. data/spec/helpers/sidekiq_helpers.rb +0 -14
  74. data/spec/internal/app/models/address.rb +0 -17
  75. data/spec/internal/app/models/application_record.rb +0 -5
  76. data/spec/internal/app/models/area.rb +0 -7
  77. data/spec/internal/app/models/assignment.rb +0 -21
  78. data/spec/internal/app/models/community.rb +0 -20
  79. data/spec/internal/app/models/country.rb +0 -8
  80. data/spec/internal/app/models/default.rb +0 -6
  81. data/spec/internal/app/models/namespaced/person/user_edited.rb +0 -8
  82. data/spec/internal/app/models/namespaced/person.rb +0 -68
  83. data/spec/internal/app/models/organization.rb +0 -37
  84. data/spec/internal/config/database.yml +0 -4
  85. data/spec/internal/config/initializers/global_registry.rb +0 -8
  86. data/spec/internal/config/routes.rb +0 -5
  87. data/spec/internal/db/schema.rb +0 -75
  88. data/spec/internal/db/test.sqlite +0 -0
  89. data/spec/internal/log/test.log +0 -1457
  90. data/spec/models/address_spec.rb +0 -30
  91. data/spec/models/assignment_spec.rb +0 -54
  92. data/spec/models/organization_spec.rb +0 -125
  93. data/spec/models/person_spec.rb +0 -191
  94. data/spec/models/testing_spec.rb +0 -55
  95. data/spec/models/user_edited_person_spec.rb +0 -14
  96. data/spec/options/if_unless_spec.rb +0 -147
  97. data/spec/spec_helper.rb +0 -52
  98. data/spec/workers/delete_gr_entity_worker_spec.rb +0 -33
  99. data/spec/workers/pull_mdm_id_worker_spec.rb +0 -133
  100. data/spec/workers/push_entity_worker_spec.rb +0 -506
  101. data/spec/workers/push_relationship_worker_spec.rb +0 -503
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe GlobalRegistry::Bindings::Workers::DeleteEntityWorker do
6
- context 'entity 22527d88-3cba-11e7-b876-129bd0521531' do
7
- context 'valid global_registry_id' do
8
- let!(:request) do
9
- stub_request(:delete, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
10
- .to_return(status: 200)
11
- end
12
-
13
- it 'should delete the entity' do
14
- worker = GlobalRegistry::Bindings::Workers::DeleteEntityWorker.new
15
- worker.perform('22527d88-3cba-11e7-b876-129bd0521531')
16
- expect(request).to have_been_requested.once
17
- end
18
- end
19
-
20
- context 'unknown global_registry_id' do
21
- let!(:request) do
22
- stub_request(:delete, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
23
- .to_return(status: 404)
24
- end
25
-
26
- it 'should delete the entity' do
27
- worker = GlobalRegistry::Bindings::Workers::DeleteEntityWorker.new
28
- worker.perform('22527d88-3cba-11e7-b876-129bd0521531')
29
- expect(request).to have_been_requested.once
30
- end
31
- end
32
- end
33
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe GlobalRegistry::Bindings::Workers::PullMdmIdWorker do
6
- context Namespaced::Person do
7
- let(:person) { create(:person) }
8
-
9
- context 'with valid id' do
10
- it 'should call #pull_mdm_id_from_global_registry' do
11
- expect(Namespaced::Person).to receive(:find).with(person.id).and_return(person)
12
-
13
- worker_name =
14
- "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry_entity.mdm_worker_class_name}"
15
- worker = worker_name.constantize.new
16
- expect(worker).to receive(:pull_mdm_id_from_global_registry)
17
- worker.perform('Namespaced::Person', person.id)
18
- expect(worker.model).to be person
19
- end
20
- end
21
-
22
- context ActiveRecord::RecordNotFound do
23
- it 'should fail silently' do
24
- expect(Namespaced::Person).to receive(:find).with(person.id).and_raise(ActiveRecord::RecordNotFound)
25
- expect(GlobalRegistry::Bindings::Workers::PullMdmIdWorker).not_to receive(:pull_mdm_id_from_global_registry)
26
-
27
- worker_name =
28
- "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry_entity.mdm_worker_class_name}"
29
- worker = worker_name.constantize.new
30
- worker.perform(Namespaced::Person, person.id)
31
- expect(worker.model).to be nil
32
- end
33
- end
34
-
35
- context RestClient::ResourceNotFound do
36
- it 'should log a message' do
37
- expect(Namespaced::Person).to receive(:find).with(person.id).and_raise(RestClient::ResourceNotFound)
38
- expect(GlobalRegistry::Bindings::Workers::PullMdmIdWorker).not_to receive(:pull_mdm_id_from_global_registry)
39
- expect(Rails.logger).to receive(:info).with('GR entity for GlobalRegistry::Bindings::Workers::PullNamespaced' \
40
- 'PersonMdmIdWorker 1 does not exist; will _not_ retry')
41
-
42
- worker_name =
43
- "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry_entity.mdm_worker_class_name}"
44
- worker = worker_name.constantize.new
45
- worker.perform(Namespaced::Person, person.id)
46
- expect(worker.model).to be nil
47
- end
48
- end
49
- end
50
-
51
- describe '#pull_mdm_id_from_global_registry' do
52
- context Namespaced::Person do
53
- let(:worker) { GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.new }
54
- before do
55
- worker.model = person
56
- end
57
-
58
- context 'model missing global_registry_id' do
59
- let(:person) { create(:person) }
60
-
61
- it 'should raise an exception' do
62
- expect do
63
- worker.pull_mdm_id_from_global_registry
64
- end.to raise_error GlobalRegistry::Bindings::RecordMissingGlobalRegistryId,
65
- "Namespaced::Person(#{person.id}) has no global_registry_id; will retry"
66
- end
67
- end
68
-
69
- context 'entity missing mdm id' do
70
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
71
- let!(:request) do
72
- stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
73
- .with(query: { 'filters[owned_by]' => 'mdm' })
74
- .to_return(body: file_fixture('get_entities_person.json'), status: 200)
75
- end
76
-
77
- it 'should raise an exception' do
78
- expect do
79
- worker.pull_mdm_id_from_global_registry
80
- end.to raise_error GlobalRegistry::Bindings::EntityMissingMdmId,
81
- "GR entity #{person.global_registry_id} for Namespaced::Person(#{person.id}) has " \
82
- 'no mdm id; will retry'
83
- end
84
- end
85
-
86
- context 'entity missing mdm id' do
87
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
88
- let!(:request) do
89
- stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
90
- .with(query: { 'filters[owned_by]' => 'mdm' })
91
- .to_return(body: file_fixture('get_entities_person_mdm.json'), status: 200)
92
- end
93
-
94
- it 'should raise an exception' do
95
- expect do
96
- worker.pull_mdm_id_from_global_registry
97
- expect(person.global_registry_mdm_id).to eq 'c81340b2-7e57-4978-b6b9-396f21bb0bb2'
98
- end.not_to raise_error
99
- end
100
- end
101
- end
102
- end
103
-
104
- describe '#mdm_worker_class' do
105
- before do
106
- module MdmTest
107
- class Klass
108
- def self.global_registry_entity
109
- @gr ||= Object.new
110
- end
111
- end
112
- end
113
- end
114
- after do
115
- MdmTest.send :remove_const, :Klass
116
- GlobalRegistry::Bindings::Workers.send :remove_const, :PullMdmTestKlassMdmIdWorker
117
- end
118
-
119
- it 'generates worker class with mdm timeout set' do
120
- expect(MdmTest::Klass.global_registry_entity).to(
121
- receive(:mdm_worker_class_name).and_return('PullMdmTestKlassMdmIdWorker')
122
- )
123
- expect(MdmTest::Klass.global_registry_entity).to(
124
- receive(:mdm_timeout).and_return(33.minutes)
125
- )
126
-
127
- GlobalRegistry::Bindings::Workers.mdm_worker_class(MdmTest::Klass)
128
- expect(GlobalRegistry::Bindings::Workers.const_defined?(:PullMdmTestKlassMdmIdWorker)).to be true
129
- expect(GlobalRegistry::Bindings::Workers::PullMdmTestKlassMdmIdWorker.get_sidekiq_options)
130
- .to include('unique' => :until_timeout, 'unique_expiration' => 33.minutes)
131
- end
132
- end
133
- end
@@ -1,506 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
6
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
7
- describe '#perform(model_class, id)' do
8
- context Namespaced::Person do
9
- let(:person) { create(:person) }
10
- context 'with valid id' do
11
- it 'should call #push_entity_to_global_registry' do
12
- expect(Namespaced::Person).to receive(:find).with(person.id).and_return(person)
13
-
14
- worker = GlobalRegistry::Bindings::Workers::PushEntityWorker.new
15
- expect(worker).to receive(:push_entity_to_global_registry)
16
- worker.perform('Namespaced::Person', person.id)
17
- expect(worker.model).to be person
18
- end
19
- end
20
-
21
- context 'with valid id and fingerprint' do
22
- it 'should call #push_entity_to_global_registry' do
23
- expect(Namespaced::Person).to receive(:find).with(person.id).and_return(person)
24
-
25
- worker = GlobalRegistry::Bindings::Workers::PushEntityWorker.new
26
- expect(worker).to receive(:push_entity_to_global_registry)
27
- worker.perform('Namespaced::Person', person.id)
28
- expect(worker.model).to be person
29
- end
30
- end
31
-
32
- context 'with invalid id' do
33
- it 'should fail silently' do
34
- expect(Namespaced::Person).to receive(:find).with(person.id).and_raise(ActiveRecord::RecordNotFound)
35
- expect(GlobalRegistry::Bindings::Workers::PushEntityWorker).not_to receive(:push_entity_to_global_registry)
36
-
37
- worker = GlobalRegistry::Bindings::Workers::PushEntityWorker.new
38
- worker.perform(Namespaced::Person, person.id)
39
- expect(worker.model).to be nil
40
- end
41
- end
42
- end
43
- end
44
-
45
- describe '#push_entity_to_global_registry' do
46
- describe Organization do
47
- let(:worker) { GlobalRegistry::Bindings::Workers::PushEntityWorker.new organization }
48
- context 'and unknown \'fancy_org\' entity_type' do
49
- let!(:requests) do
50
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
51
- .with(query: { 'filters[name]' => 'fancy_org', 'filters[parent_id]' => nil })
52
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
53
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
54
- .with(body: { entity_type: { name: 'fancy_org', parent_id: nil, field_type: 'entity' } })
55
- .to_return(body: file_fixture('post_entity_types_fancy_org.json'), status: 200),
56
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
57
- .with(body: { entity_type: { name: 'name', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
58
- field_type: 'string' } })
59
- .to_return(status: 200),
60
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
61
- .with(body: { entity_type: { name: 'description', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
62
- field_type: 'string' } })
63
- .to_return(status: 200),
64
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
65
- .with(body: { entity_type: { name: 'start_date', parent_id: '025a1128-3f33-11e7-b876-129bd0521531',
66
- field_type: 'date' } })
67
- .to_return(status: 200)]
68
- end
69
-
70
- context 'with root level organization' do
71
- let(:organization) { create(:organization) }
72
- let!(:sub_requests) do
73
- [stub_request(:post, 'https://backend.global-registry.org/entities')
74
- .with(body: { entity: { fancy_org: { name: 'Organization', description: 'Fancy Organization',
75
- start_date: '2001-02-03', parent_id: nil,
76
- client_integration_id: organization.id,
77
- client_updated_at: '2001-02-03 00:00:00' } } })
78
- .to_return(body: file_fixture('post_entities_fancy_org.json'), status: 200)]
79
- end
80
-
81
- it 'should create \'fancy_org\' entity_type and push entity to Global Registry' do
82
- worker.push_entity_to_global_registry
83
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
84
- expect(organization.gr_id).to eq 'aebb4170-3f34-11e7-bba6-129bd0521531'
85
- end
86
- end
87
-
88
- context 'with organization with parent missing global_registry_id' do
89
- let(:parent) { create(:organization, name: 'Parent', description: 'Parent Fancy Organization') }
90
- let(:organization) { create(:organization, parent: parent) }
91
-
92
- it 'should create \'fancy_org\' entity_type raise an exception' do
93
- expect do
94
- worker.push_entity_to_global_registry
95
- requests.each { |r| expect(r).to have_been_requested.once }
96
- end.to raise_error GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId,
97
- "Organization(#{organization.id}) has parent entity Organization(#{parent.id}) " \
98
- 'missing global_registry_id; will retry.'
99
- end
100
- end
101
-
102
- context 'organization with an existing parent' do
103
- let(:parent) do
104
- create :organization, name: 'Parent', description: 'Parent Fancy Organization',
105
- gr_id: 'cd5da38a-c336-46a7-b818-dcdd51c4acde'
106
- end
107
- let(:organization) { create(:organization, parent: parent) }
108
- let!(:sub_requests) do
109
- [stub_request(:post, 'https://backend.global-registry.org/entities')
110
- .with(body: { entity: { fancy_org: { name: 'Organization', description: 'Fancy Organization',
111
- start_date: '2001-02-03',
112
- parent_id: 'cd5da38a-c336-46a7-b818-dcdd51c4acde',
113
- client_integration_id: organization.id,
114
- client_updated_at: '2001-02-03 00:00:00' } } })
115
- .to_return(body: file_fixture('post_entities_fancy_org.json'), status: 200)]
116
- end
117
-
118
- it 'should create \'fancy_org\' entity_type and push both entities' do
119
- worker.push_entity_to_global_registry
120
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
121
- expect(parent.gr_id).to eq 'cd5da38a-c336-46a7-b818-dcdd51c4acde'
122
- expect(organization.gr_id).to eq 'aebb4170-3f34-11e7-bba6-129bd0521531'
123
- end
124
- end
125
- end
126
- end
127
-
128
- describe Namespaced::Person do
129
- let(:worker) { GlobalRegistry::Bindings::Workers::PushEntityWorker.new person }
130
- let(:entity_body) do
131
- { entity: { person: { first_name: 'Tony', last_name: 'Stark',
132
- client_integration_id: person.id,
133
- client_updated_at: '2001-02-03 00:00:00',
134
- authentication: {
135
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
136
- } } } }
137
- end
138
- context 'as create' do
139
- let(:person) { create(:person, global_registry_fingerprint: 'abc123') }
140
-
141
- context '\'person\' entity_type does not exist' do
142
- let!(:requests) do
143
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
144
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
145
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
146
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
147
- .with(body: { entity_type: { name: 'person', parent_id: nil, field_type: 'entity' } })
148
- .to_return(body: file_fixture('post_entity_types_person.json'), status: 200),
149
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
150
- .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
151
- field_type: 'string' } })
152
- .to_return(status: 200),
153
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
154
- .with(body: { entity_type: { name: 'last_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
155
- field_type: 'string' } })
156
- .to_return(status: 200),
157
- stub_request(:post, 'https://backend.global-registry.org/entities')
158
- .with(body: entity_body)
159
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
160
- end
161
-
162
- it 'should create \'person\' entity_type and push entity' do
163
- worker.push_entity_to_global_registry
164
- requests.each { |r| expect(r).to have_been_requested.once }
165
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
166
- expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
167
- end
168
- end
169
-
170
- context '\'person\' entity_type exists' do
171
- let!(:requests) do
172
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
173
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
174
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
175
- stub_request(:post, 'https://backend.global-registry.org/entities')
176
- .with(body: entity_body)
177
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
178
- end
179
-
180
- it 'should skip creating entity_type and push the entity' do
181
- worker.push_entity_to_global_registry
182
- requests.each { |r| expect(r).to have_been_requested.once }
183
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
184
- expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
185
- end
186
- end
187
-
188
- context 'partial \'person\' entity_type exists' do
189
- let!(:requests) do
190
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
191
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
192
- .to_return(body: file_fixture('get_entity_types_person_partial.json'), status: 200),
193
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
194
- .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
195
- field_type: 'string' } })
196
- .to_return(status: 200),
197
- stub_request(:post, 'https://backend.global-registry.org/entities')
198
- .with(body: entity_body)
199
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
200
- end
201
-
202
- it 'should skip creating entity_type and push the entity' do
203
- worker.push_entity_to_global_registry
204
- requests.each { |r| expect(r).to have_been_requested.once }
205
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
206
- expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
207
- end
208
- end
209
-
210
- context '\'person\' entity_type is cached' do
211
- before :each do
212
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
213
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
214
- end
215
-
216
- it 'should skip creating entity_type and push the entity' do
217
- request = stub_request(:post, 'https://backend.global-registry.org/entities')
218
- .with(body: entity_body)
219
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
220
- worker.push_entity_to_global_registry
221
- expect(request).to have_been_requested.once
222
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
223
- expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
224
- end
225
- end
226
- end
227
-
228
- context 'as an update' do
229
- let(:person) do
230
- create(:person, global_registry_id: 'f8d20318-2ff2-4a98-a5eb-e9d840508bf1',
231
- global_registry_fingerprint: 'abc123')
232
- end
233
- context '\'person\' entity_type is cached' do
234
- before :each do
235
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
236
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
237
- end
238
-
239
- it 'should skip creating entity_type and update the entity' do
240
- request = stub_request(:put,
241
- 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
242
- .with(body: entity_body)
243
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
244
- worker.push_entity_to_global_registry
245
- expect(request).to have_been_requested.once
246
- end
247
-
248
- context 'invalid entity id' do
249
- let!(:requests) { [update_request, create_request] }
250
- let!(:update_request) do
251
- stub_request(:put, 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
252
- .with(body: entity_body)
253
- .to_return(status: 404)
254
- end
255
- let!(:create_request) do
256
- stub_request(:post, 'https://backend.global-registry.org/entities')
257
- .with(body: entity_body)
258
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
259
- end
260
-
261
- it 'should push entity as create' do
262
- worker.push_entity_to_global_registry
263
- requests.each { |r| expect(r).to have_been_requested.once }
264
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
265
- expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
266
- end
267
-
268
- context 'response is also not found on create' do
269
- let!(:create_request) do
270
- stub_request(:post, 'https://backend.global-registry.org/entities')
271
- .with(body: entity_body)
272
- .to_return(status: 404)
273
- end
274
-
275
- it 'should raise an error' do
276
- expect { worker.push_entity_to_global_registry }.to raise_error(RestClient::NotFound)
277
- end
278
- end
279
- end
280
-
281
- context 'fingerprints match' do
282
- it 'should do nothing' do
283
- request = stub_request(:put,
284
- 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
285
- .with(body: entity_body)
286
- .to_return(body: file_fixture('post_entities_person.json'), status: 200)
287
- person.global_registry_fingerprint = '4c671c203b5dd19cdc1920ba5434cf64'
288
- worker.push_entity_to_global_registry
289
- expect(request).not_to have_been_requested
290
- end
291
- end
292
- end
293
- end
294
- end
295
-
296
- describe Address do
297
- let(:worker) { GlobalRegistry::Bindings::Workers::PushEntityWorker.new address }
298
- context 'as create' do
299
- context '\'address\' record does not belong to a person' do
300
- let(:address) { create(:address) }
301
-
302
- it 'should not create \'address\' entity_type and skip push of entity' do
303
- worker.push_entity_to_global_registry
304
- end
305
- end
306
-
307
- context '\'address\' entity_type does not exist' do
308
- let!(:requests) do
309
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
310
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
311
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
312
- stub_request(:get, 'https://backend.global-registry.org/entity_types')
313
- .with(query: { 'filters[name]' => 'address',
314
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
315
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
316
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
317
- .with(body: { entity_type: { name: 'address', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
318
- field_type: 'entity' } })
319
- .to_return(body: file_fixture('post_entity_types_address.json'), status: 200),
320
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
321
- .with(body: { entity_type: { name: 'zip', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
322
- field_type: 'string' } })
323
- .to_return(status: 200),
324
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
325
- .with(body: { entity_type: { name: 'line1', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
326
- field_type: 'string' } })
327
- .to_return(status: 200),
328
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
329
- .with(body: { entity_type: { name: 'line2', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
330
- field_type: 'string' } })
331
- .to_return(status: 200),
332
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
333
- .with(body: { entity_type: { name: 'primary', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
334
- field_type: 'boolean' } })
335
- .to_return(status: 200),
336
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
337
- .with(body: { entity_type: { name: 'postal_code', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
338
- field_type: 'string' } })
339
- .to_return(status: 200)]
340
- end
341
-
342
- context '\'address\' record belongs to a person without global registry id' do
343
- let(:person) { create(:person) }
344
- let(:address) { create(:address, person: person) }
345
-
346
- it 'should create \'address\' entity_type and raise an error' do
347
- expect do
348
- worker.push_entity_to_global_registry
349
- end.to raise_error GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId,
350
- "Address(#{address.id}) has parent entity Namespaced::Person(#{person.id}) " \
351
- 'missing global_registry_id; will retry.'
352
- requests.each { |r| expect(r).to have_been_requested.once }
353
- expect(person.global_registry_id).to be nil
354
- expect(address.global_registry_id).to be nil
355
- end
356
- end
357
-
358
- context '\'address\' record belongs to an existing person entity' do
359
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
360
- let(:address) { create(:address, person: person) }
361
- let!(:sub_requests) do
362
- [stub_request(:put,
363
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
364
- .with(body: { entity: { person: { client_integration_id: person.id,
365
- address: {
366
- zip: '90265', primary: 'true',
367
- line1: '10880 Malibu Point', postal_code: '90265',
368
- client_integration_id: address.id,
369
- client_updated_at: '2001-02-03 00:00:00'
370
- } } } })
371
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)]
372
- end
373
-
374
- it 'should create \'address\' entity_type and push address entity' do
375
- worker.push_entity_to_global_registry
376
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
377
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
378
- end
379
- end
380
- end
381
-
382
- context '\'address\' and \'person\' entity_types exist' do
383
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
384
- let(:address) { create(:address, person: person) }
385
- let!(:requests) do
386
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
387
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
388
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
389
- stub_request(:put,
390
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
391
- .with(body: { entity: { person: { client_integration_id: person.id,
392
- address: {
393
- zip: '90265', primary: 'true',
394
- line1: '10880 Malibu Point', postal_code: '90265',
395
- client_integration_id: address.id,
396
- client_updated_at: '2001-02-03 00:00:00'
397
- } } } })
398
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)]
399
- end
400
-
401
- context '\'address\' entity_type has partial fields' do
402
- let!(:sub_requests) do
403
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
404
- .with(query: { 'filters[name]' => 'address',
405
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
406
- .to_return(body: file_fixture('get_entity_types_address_partial.json'), status: 200),
407
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
408
- .with(body: { entity_type: { name: 'line2', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
409
- field_type: 'string' } })
410
- .to_return(status: 200),
411
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
412
- .with(body: { entity_type: { name: 'primary', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
413
- field_type: 'boolean' } })
414
- .to_return(status: 200)]
415
- end
416
-
417
- it 'should add missing fields and push address entity' do
418
- worker.push_entity_to_global_registry
419
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
420
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
421
- end
422
- end
423
-
424
- context '\'address\' entity_type has all fields' do
425
- let!(:sub_requests) do
426
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
427
- .with(query: { 'filters[name]' => 'address',
428
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
429
- .to_return(body: file_fixture('get_entity_types_address.json'), status: 200)]
430
- end
431
-
432
- it 'should push address entity' do
433
- worker.push_entity_to_global_registry
434
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
435
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
436
- end
437
- end
438
- end
439
- end
440
-
441
- context 'as an update' do
442
- before :each do
443
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
444
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
445
- address_entity_types = JSON.parse(file_fixture('get_entity_types_address.json').read)
446
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::address',
447
- address_entity_types['entity_types'].first)
448
- end
449
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
450
- let(:address) do
451
- create(:address, person: person, global_registry_id: '0a594356-3f1c-11e7-bba6-129bd0521531')
452
- end
453
- let!(:request) do
454
- stub_request(:put,
455
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
456
- .with(body: { entity: { person: { client_integration_id: person.id,
457
- address: {
458
- zip: '90265', primary: 'false',
459
- line1: '100 Sesame Street', postal_code: '90265',
460
- client_integration_id: address.id,
461
- client_updated_at: '2001-02-03 00:00:00'
462
- } } } })
463
- .to_return(response)
464
- end
465
- let!(:response) { { body: file_fixture('put_entities_address.json'), status: 200 } }
466
-
467
- subject do
468
- address.address1 = '100 Sesame Street'
469
- address.primary = false
470
- worker.push_entity_to_global_registry
471
- end
472
-
473
- it 'should push address entity' do
474
- expect { subject }.to_not(change { address.global_registry_id })
475
- expect(request).to have_been_requested.once
476
- end
477
-
478
- context 'response not found' do
479
- let!(:response) { { status: 404 } }
480
-
481
- it 'should raise an error' do
482
- expect { subject }.to raise_error(RestClient::NotFound)
483
- expect(request).to have_been_requested.once
484
- end
485
- end
486
- end
487
- end
488
-
489
- describe Community do
490
- let(:worker) { GlobalRegistry::Bindings::Workers::PushEntityWorker.new community }
491
- let(:community) { create(:community, infobase_id: 234) }
492
- let!(:request) do
493
- stub_request(:post, 'https://backend.global-registry.org/entities')
494
- .with(body: { entity: { community: { name: 'Community', client_integration_id: community.id,
495
- client_updated_at: '2001-02-03 00:00:00' } } })
496
- .to_return(body: file_fixture('post_entities_community.json'), status: 200)
497
- end
498
-
499
- it 'should push community entity' do
500
- worker.push_entity_to_global_registry
501
- expect(request).to have_been_requested.once
502
- expect(community.global_registry_id).to eq '6133f6fe-c63a-425a-bb46-68917c689723'
503
- end
504
- end
505
- end
506
- end