global-registry-bindings 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/global_registry_bindings/entity/entity_type_methods.rb +16 -18
- data/lib/global_registry_bindings/entity/mdm_methods.rb +11 -12
- data/lib/global_registry_bindings/entity/push_entity_methods.rb +23 -23
- data/lib/global_registry_bindings/entity/push_relationship_methods.rb +18 -18
- data/lib/global_registry_bindings/entity/relationship_type_methods.rb +26 -26
- data/lib/global_registry_bindings/exceptions.rb +7 -2
- data/lib/global_registry_bindings/global_registry_bindings.rb +19 -19
- data/lib/global_registry_bindings/model/delete_entity.rb +4 -4
- data/lib/global_registry_bindings/model/entity.rb +25 -25
- data/lib/global_registry_bindings/model/pull_mdm.rb +5 -5
- data/lib/global_registry_bindings/model/push_entity.rb +4 -4
- data/lib/global_registry_bindings/model/push_relationship.rb +10 -8
- data/lib/global_registry_bindings/model/relationship.rb +18 -18
- data/lib/global_registry_bindings/options/entity_class_options.rb +15 -15
- data/lib/global_registry_bindings/options/entity_instance_options.rb +11 -11
- data/lib/global_registry_bindings/options/entity_options_parser.rb +3 -3
- data/lib/global_registry_bindings/options/relationship_class_options.rb +22 -22
- data/lib/global_registry_bindings/options/relationship_instance_options.rb +12 -12
- data/lib/global_registry_bindings/options/relationship_options_parser.rb +7 -7
- data/lib/global_registry_bindings/options.rb +6 -6
- data/lib/global_registry_bindings/railtie.rb +7 -7
- data/lib/global_registry_bindings/testing.rb +3 -3
- data/lib/global_registry_bindings/version.rb +3 -3
- data/lib/global_registry_bindings/worker.rb +5 -5
- data/lib/global_registry_bindings/workers/delete_entity_worker.rb +3 -3
- data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +5 -5
- data/lib/global_registry_bindings/workers/push_entity_worker.rb +6 -6
- data/lib/global_registry_bindings/workers/push_relationship_worker.rb +6 -6
- data/lib/global_registry_bindings.rb +3 -3
- metadata +16 -156
- data/spec/acceptance/global_registry_bindings_spec.rb +0 -191
- data/spec/factories/factories.rb +0 -72
- data/spec/fixtures/get_entities_person.json +0 -8
- data/spec/fixtures/get_entities_person_mdm.json +0 -13
- data/spec/fixtures/get_entities_person_relationship.json +0 -32
- data/spec/fixtures/get_entity_types.json +0 -9
- data/spec/fixtures/get_entity_types_address.json +0 -59
- data/spec/fixtures/get_entity_types_address_partial.json +0 -43
- data/spec/fixtures/get_entity_types_area.json +0 -44
- data/spec/fixtures/get_entity_types_community.json +0 -18
- data/spec/fixtures/get_entity_types_fancy_org.json +0 -43
- data/spec/fixtures/get_entity_types_fancy_org_assignment.json +0 -35
- data/spec/fixtures/get_entity_types_fancy_org_partial.json +0 -35
- data/spec/fixtures/get_entity_types_ministry.json +0 -18
- data/spec/fixtures/get_entity_types_person.json +0 -42
- data/spec/fixtures/get_entity_types_person_partial.json +0 -34
- data/spec/fixtures/get_relationship_types.json +0 -9
- data/spec/fixtures/get_relationship_types_person_fancy_org.json +0 -41
- data/spec/fixtures/get_relationship_types_person_fancy_org_partial.json +0 -33
- data/spec/fixtures/post_entities_community.json +0 -8
- data/spec/fixtures/post_entities_fancy_org.json +0 -8
- data/spec/fixtures/post_entities_fancy_org_parent.json +0 -8
- data/spec/fixtures/post_entities_person.json +0 -8
- data/spec/fixtures/post_entity_types_address.json +0 -9
- data/spec/fixtures/post_entity_types_fancy_org.json +0 -9
- data/spec/fixtures/post_entity_types_person.json +0 -9
- data/spec/fixtures/post_relationship_types_assigned_by.json +0 -16
- data/spec/fixtures/post_relationship_types_community_ministry.json +0 -16
- data/spec/fixtures/post_relationship_types_fancy_org_area.json +0 -16
- data/spec/fixtures/post_relationship_types_person_fancy_org.json +0 -16
- data/spec/fixtures/put_entities_address.json +0 -20
- data/spec/fixtures/put_entities_community_relationship.json +0 -16
- data/spec/fixtures/put_entities_fancy_org_area_relationship.json +0 -8
- data/spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json +0 -20
- data/spec/fixtures/put_entities_fancy_org_relationship.json +0 -17
- data/spec/fixtures/put_entities_person_country_relationship.json +0 -23
- data/spec/fixtures/put_entities_person_relationship.json +0 -29
- data/spec/fixtures/put_entities_relationship.json +0 -8
- data/spec/fixtures/put_entities_relationship_400.json +0 -3
- data/spec/fixtures/put_relationship_types_fields.json +0 -33
- data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +0 -25
- data/spec/helpers/sidekiq_helpers.rb +0 -14
- data/spec/internal/app/models/address.rb +0 -17
- data/spec/internal/app/models/application_record.rb +0 -5
- data/spec/internal/app/models/area.rb +0 -7
- data/spec/internal/app/models/assignment.rb +0 -21
- data/spec/internal/app/models/community.rb +0 -20
- data/spec/internal/app/models/country.rb +0 -8
- data/spec/internal/app/models/default.rb +0 -6
- data/spec/internal/app/models/namespaced/person/user_edited.rb +0 -8
- data/spec/internal/app/models/namespaced/person.rb +0 -68
- data/spec/internal/app/models/organization.rb +0 -37
- data/spec/internal/config/database.yml +0 -4
- data/spec/internal/config/initializers/global_registry.rb +0 -8
- data/spec/internal/config/routes.rb +0 -5
- data/spec/internal/db/schema.rb +0 -75
- data/spec/internal/db/test.sqlite +0 -0
- data/spec/internal/log/test.log +0 -1457
- data/spec/models/address_spec.rb +0 -30
- data/spec/models/assignment_spec.rb +0 -54
- data/spec/models/organization_spec.rb +0 -125
- data/spec/models/person_spec.rb +0 -191
- data/spec/models/testing_spec.rb +0 -55
- data/spec/models/user_edited_person_spec.rb +0 -14
- data/spec/options/if_unless_spec.rb +0 -147
- data/spec/spec_helper.rb +0 -52
- data/spec/workers/delete_gr_entity_worker_spec.rb +0 -33
- data/spec/workers/pull_mdm_id_worker_spec.rb +0 -133
- data/spec/workers/push_entity_worker_spec.rb +0 -506
- data/spec/workers/push_relationship_worker_spec.rb +0 -503
@@ -1,503 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
6
|
-
around { |example| travel_to Time.utc(2001, 2, 3), &example }
|
7
|
-
describe '#perform(model_class, id, type)' do
|
8
|
-
context Assignment do
|
9
|
-
let(:assignment) { create(:assignment) }
|
10
|
-
context 'with valid id' do
|
11
|
-
it 'should call #push_relationship_to_global_registry' do
|
12
|
-
expect(Assignment).to receive(:find).with(assignment.id).and_return(assignment)
|
13
|
-
|
14
|
-
worker = GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new
|
15
|
-
expect(worker).to receive(:push_relationship_to_global_registry)
|
16
|
-
worker.perform('Assignment', assignment.id, :assignment)
|
17
|
-
expect(worker.model).to be assignment
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with invalid id' do
|
22
|
-
it 'should fail silently' do
|
23
|
-
expect(Assignment).to receive(:find).with(assignment.id).and_raise(ActiveRecord::RecordNotFound)
|
24
|
-
expect(GlobalRegistry::Bindings::Workers::PushRelationshipWorker)
|
25
|
-
.not_to receive(:push_relationship_to_global_registry)
|
26
|
-
|
27
|
-
worker = GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new
|
28
|
-
worker.perform(Assignment, assignment.id, :assignment)
|
29
|
-
expect(worker.model).to be nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#push_relationship_to_global_registry' do
|
36
|
-
describe Assignment do
|
37
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new assignment, :fancy_org_assignment }
|
38
|
-
context 'as create' do
|
39
|
-
let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
40
|
-
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
41
|
-
let(:assignment) { create(:assignment, person: person, organization: organization) }
|
42
|
-
let!(:requests) do
|
43
|
-
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
44
|
-
.with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
|
45
|
-
.to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
|
46
|
-
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
47
|
-
.with(query: { 'filters[name]' => 'fancy_org', 'filters[parent_id]' => nil })
|
48
|
-
.to_return(body: file_fixture('get_entity_types_fancy_org.json'), status: 200),
|
49
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
|
50
|
-
.with(body: { entity: { person: { 'fancy_org:relationship': {
|
51
|
-
role: 'leader', hired_at: '2000-12-03 00:00:00',
|
52
|
-
client_integration_id: assignment.id,
|
53
|
-
client_updated_at: '2001-02-03 00:00:00', fancy_org: organization.gr_id
|
54
|
-
} }, client_integration_id: person.id } }, query: { full_response: 'true',
|
55
|
-
fields: 'fancy_org:relationship' })
|
56
|
-
.to_return(body: file_fixture('put_entities_person_relationship.json'), status: 200)]
|
57
|
-
end
|
58
|
-
|
59
|
-
context '\'assignment\' relationship_type does not exist' do
|
60
|
-
let!(:sub_requests) do
|
61
|
-
[stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
62
|
-
.with(query: { 'filters[between]' =>
|
63
|
-
'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
|
64
|
-
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
65
|
-
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
66
|
-
.with(body: { relationship_type: { entity_type1_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
|
67
|
-
entity_type2_id: '025a1128-3f33-11e7-b876-129bd0521531',
|
68
|
-
relationship1: 'person', relationship2: 'fancy_org' } })
|
69
|
-
.to_return(body: file_fixture('post_relationship_types_person_fancy_org.json'), status: 200),
|
70
|
-
stub_request(:put,
|
71
|
-
'https://backend.global-registry.org/relationship_types/5d721db8-4248-11e7-90b4-129bd0521531')
|
72
|
-
.with(body: { relationship_type: { fields: [{ name: 'role', field_type: 'string' },
|
73
|
-
{ name: 'hired_at', field_type: 'datetime' }] } })
|
74
|
-
.to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200),
|
75
|
-
stub_request(:put,
|
76
|
-
'https://backend.global-registry.org/entity_types/5d70b630-4248-11e7-90b4-129bd0521531')
|
77
|
-
.with(body: { entity_type: { id: '5d70b630-4248-11e7-90b4-129bd0521531',
|
78
|
-
name: 'fancy_org_assignment' } })
|
79
|
-
.to_return(status: 200)]
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should create \'assignment\' relationship_type and push relationship' do
|
83
|
-
worker.push_relationship_to_global_registry
|
84
|
-
(requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
|
85
|
-
expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context '\'assignment\' relationship_type partially exists' do
|
90
|
-
let!(:sub_requests) do
|
91
|
-
[stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
92
|
-
.with(query: { 'filters[between]' =>
|
93
|
-
'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
|
94
|
-
.to_return(body: file_fixture('get_relationship_types_person_fancy_org_partial.json'), status: 200),
|
95
|
-
stub_request(:put,
|
96
|
-
'https://backend.global-registry.org/relationship_types/5d721db8-4248-11e7-90b4-129bd0521531')
|
97
|
-
.with(body: { relationship_type: { fields: [{ name: 'role', field_type: 'string' }] } })
|
98
|
-
.to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200)]
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should add fields to relationship type and push relationship' do
|
102
|
-
worker.push_relationship_to_global_registry
|
103
|
-
(requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
|
104
|
-
expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context '\'assignment\' relationship_type exists' do
|
109
|
-
let!(:sub_requests) do
|
110
|
-
[stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
111
|
-
.with(query: { 'filters[between]' =>
|
112
|
-
'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
|
113
|
-
.to_return(body: file_fixture('get_relationship_types_person_fancy_org.json'), status: 200)]
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should add fields to relationship type and push relationship' do
|
117
|
-
worker.push_relationship_to_global_registry
|
118
|
-
(requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
|
119
|
-
expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'as an update' do
|
125
|
-
let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
126
|
-
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
127
|
-
let(:assignment) do
|
128
|
-
create(:assignment, person: person, organization: organization,
|
129
|
-
global_registry_id: '51a014a4-4252-11e7-944f-129bd0521531')
|
130
|
-
end
|
131
|
-
|
132
|
-
context '\'assignment\' relationship_type is cached' do
|
133
|
-
before :each do
|
134
|
-
person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
|
135
|
-
organization_entity_types = JSON.parse(file_fixture('get_entity_types_fancy_org.json').read)
|
136
|
-
assignment_relationship_type = JSON.parse(file_fixture('get_relationship_types_person_fancy_org.json').read)
|
137
|
-
Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
|
138
|
-
Rails.cache.write('GlobalRegistry::Bindings::EntityType::fancy_org',
|
139
|
-
organization_entity_types['entity_types'].first)
|
140
|
-
Rails.cache.write('GlobalRegistry::Bindings::RelationshipType::person::fancy_org::person',
|
141
|
-
assignment_relationship_type['relationship_types'].first)
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'should push relationship' do
|
145
|
-
request = stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
|
146
|
-
.with(body: { entity: { person: { 'fancy_org:relationship': {
|
147
|
-
role: 'leader', hired_at: '2000-12-03 00:00:00',
|
148
|
-
client_integration_id: assignment.id,
|
149
|
-
client_updated_at: '2001-02-03 00:00:00', fancy_org: organization.gr_id
|
150
|
-
} }, client_integration_id: person.id } }, query: { full_response: 'true',
|
151
|
-
fields: 'fancy_org:relationship' })
|
152
|
-
.to_return(body: file_fixture('put_entities_person_relationship.json'), status: 200,
|
153
|
-
headers: { 'Content-Type' => 'application/json' })
|
154
|
-
|
155
|
-
worker.push_relationship_to_global_registry
|
156
|
-
expect(request).to have_been_requested.once
|
157
|
-
expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
|
158
|
-
end
|
159
|
-
|
160
|
-
context '\'fancy_org\' foreign key changed' do
|
161
|
-
let!(:requests) do
|
162
|
-
[stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
|
163
|
-
.with(body: { entity: { person: { 'fancy_org:relationship': {
|
164
|
-
role: 'leader', hired_at: '2000-12-03 00:00:00',
|
165
|
-
client_integration_id: assignment.id,
|
166
|
-
client_updated_at: '2001-02-03 00:00:00', fancy_org: organization.gr_id
|
167
|
-
} }, client_integration_id: person.id } }, query: { full_response: 'true',
|
168
|
-
fields: 'fancy_org:relationship' })
|
169
|
-
.to_return(body: file_fixture('put_entities_relationship_400.json'), status: 400),
|
170
|
-
stub_request(:delete,
|
171
|
-
'https://backend.global-registry.org/entities/51a014a4-4252-11e7-944f-129bd0521531')
|
172
|
-
.to_return(status: 200)]
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should delete relationship and retry' do
|
176
|
-
expect do
|
177
|
-
worker.push_relationship_to_global_registry
|
178
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityExistsWithCID)
|
179
|
-
requests.each { |r| expect(r).to have_been_requested.once }
|
180
|
-
expect(assignment.global_registry_id).to be_nil
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'related entities missing global_registry_id' do
|
187
|
-
context '\'person\' missing global_registry_id' do
|
188
|
-
let(:person) { build(:person) }
|
189
|
-
let(:organization) { build(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
190
|
-
let!(:assignment) { create(:assignment, person: person, organization: organization) }
|
191
|
-
|
192
|
-
it 'should raise an exception' do
|
193
|
-
clear_sidekiq_jobs_and_locks
|
194
|
-
|
195
|
-
expect do
|
196
|
-
worker.push_relationship_to_global_registry
|
197
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
|
198
|
-
change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1)
|
199
|
-
)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context '\'organization\' missing global_registry_id' do
|
204
|
-
let(:person) { build(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
205
|
-
let(:organization) { build(:organization) }
|
206
|
-
let!(:assignment) { create(:assignment, person: person, organization: organization) }
|
207
|
-
|
208
|
-
it 'should raise an exception' do
|
209
|
-
clear_sidekiq_jobs_and_locks
|
210
|
-
|
211
|
-
expect do
|
212
|
-
worker.push_relationship_to_global_registry
|
213
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
|
214
|
-
change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1)
|
215
|
-
)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context '\'person\' and \'organization\' missing global_registry_id' do
|
220
|
-
let(:person) { build(:person) }
|
221
|
-
let(:organization) { build(:organization) }
|
222
|
-
let!(:assignment) { create(:assignment, person: person, organization: organization) }
|
223
|
-
|
224
|
-
it 'should raise an exception' do
|
225
|
-
clear_sidekiq_jobs_and_locks
|
226
|
-
|
227
|
-
expect do
|
228
|
-
worker.push_relationship_to_global_registry
|
229
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
|
230
|
-
change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(2)
|
231
|
-
)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe Assignment do
|
238
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new assignment, :assigned_by }
|
239
|
-
|
240
|
-
context 'as create' do
|
241
|
-
let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
242
|
-
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
243
|
-
|
244
|
-
context '\'assigned_by\' relationship_type does not exist' do
|
245
|
-
let(:assignment) do
|
246
|
-
create(:assignment, person: person, organization: organization, assigned_by: person,
|
247
|
-
global_registry_id: '51a014a4-4252-11e7-944f-129bd0521531')
|
248
|
-
end
|
249
|
-
|
250
|
-
let!(:requests) do
|
251
|
-
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
252
|
-
.with(query: { 'filters[name]' => 'fancy_org_assignment' })
|
253
|
-
.to_return(body: file_fixture('get_entity_types_fancy_org_assignment.json'), status: 200),
|
254
|
-
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
255
|
-
.with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
|
256
|
-
.to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
|
257
|
-
stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
258
|
-
.with(query: { 'filters[between]' =>
|
259
|
-
'5d70b630-4248-11e7-90b4-129bd0521531,ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
|
260
|
-
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
261
|
-
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
262
|
-
.with(body: { relationship_type: { entity_type1_id: '5d70b630-4248-11e7-90b4-129bd0521531',
|
263
|
-
entity_type2_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
|
264
|
-
relationship1: 'assigned_by', relationship2: 'person' } })
|
265
|
-
.to_return(body: file_fixture('post_relationship_types_assigned_by.json'), status: 200),
|
266
|
-
stub_request(:put,
|
267
|
-
'https://backend.global-registry.org/entity_types/4f5d8150-76c7-11e7-b3f0-129bd0521531')
|
268
|
-
.with(body: { entity_type: { id: '4f5d8150-76c7-11e7-b3f0-129bd0521531',
|
269
|
-
name: 'assigned_by' } })
|
270
|
-
.to_return(status: 200),
|
271
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{assignment.global_registry_id}")
|
272
|
-
.with(body: { entity: { fancy_org_assignment: { 'person:relationship': {
|
273
|
-
client_integration_id: assignment.id,
|
274
|
-
client_updated_at: '2001-02-03 00:00:00', person: person.global_registry_id
|
275
|
-
} }, client_integration_id: assignment.id } },
|
276
|
-
query: { full_response: 'true', fields: 'person:relationship' })
|
277
|
-
.to_return(body: file_fixture('put_entities_fancy_org_assignment_assigned_by.json'), status: 200)]
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'should create \'assigned_by\' relationship_type and push relationship' do
|
281
|
-
worker.push_relationship_to_global_registry
|
282
|
-
requests.each { |r| expect(r).to have_been_requested.once }
|
283
|
-
expect(assignment.assigned_by_gr_rel_id).to eq '0fd8b8b8-76c9-11e7-b15c-129bd0521531'
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context 'fancy_org_assignment missing global_registry_id' do
|
288
|
-
let!(:assignment) do
|
289
|
-
create(:assignment, person: person, organization: organization, assigned_by: person)
|
290
|
-
end
|
291
|
-
|
292
|
-
it 'should raise an exception' do
|
293
|
-
clear_sidekiq_jobs_and_locks
|
294
|
-
|
295
|
-
expect do
|
296
|
-
worker.push_relationship_to_global_registry
|
297
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
|
298
|
-
change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1)
|
299
|
-
)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe Organization do
|
306
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new organization, :area }
|
307
|
-
context 'as create' do
|
308
|
-
let(:area) { create(:area, global_registry_id: '0fdb70c5-f51e-4628-a1fe-caa37fae53cd') }
|
309
|
-
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531', area: area) }
|
310
|
-
let!(:requests) do
|
311
|
-
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
312
|
-
.with(query: { 'filters[name]' => 'fancy_org', 'filters[parent_id]' => nil })
|
313
|
-
.to_return(body: file_fixture('get_entity_types_fancy_org.json'), status: 200),
|
314
|
-
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
315
|
-
.with(query: { 'filters[name]' => 'area', 'filters[parent_id]' => nil })
|
316
|
-
.to_return(body: file_fixture('get_entity_types_area.json'), status: 200),
|
317
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{organization.gr_id}")
|
318
|
-
.with(body: { entity: { fancy_org: { 'area:relationship': {
|
319
|
-
priority: 'High',
|
320
|
-
client_integration_id: organization.id,
|
321
|
-
client_updated_at: '2001-02-03 00:00:00', area: area.global_registry_id
|
322
|
-
} }, client_integration_id: organization.id } },
|
323
|
-
query: { full_response: 'true', fields: 'area:relationship' })
|
324
|
-
.to_return(body: file_fixture('put_entities_fancy_org_relationship.json'), status: 200)]
|
325
|
-
end
|
326
|
-
|
327
|
-
context '\'area\' relationship_type does not exist' do
|
328
|
-
let!(:sub_requests) do
|
329
|
-
[stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
330
|
-
.with(query: { 'filters[between]' =>
|
331
|
-
'025a1128-3f33-11e7-b876-129bd0521531,548852c6-d55e-11e3-897f-12725f8f377c' })
|
332
|
-
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
333
|
-
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
334
|
-
.with(body: { relationship_type: { entity_type1_id: '025a1128-3f33-11e7-b876-129bd0521531',
|
335
|
-
entity_type2_id: '548852c6-d55e-11e3-897f-12725f8f377c',
|
336
|
-
relationship1: 'fancy_org', relationship2: 'area' } })
|
337
|
-
.to_return(body: file_fixture('post_relationship_types_fancy_org_area.json'), status: 200),
|
338
|
-
stub_request(:put,
|
339
|
-
'https://backend.global-registry.org/relationship_types/f03b947e-6644-11e7-93dd-129bd0521531')
|
340
|
-
.with(body: { relationship_type: { fields: [{ name: 'priority', field_type: 'string' }] } })
|
341
|
-
.to_return(body: file_fixture('put_relationship_types_fields_fancy_org_area.json'), status: 200)]
|
342
|
-
end
|
343
|
-
|
344
|
-
it 'should create \'area\' relationship_type and push relationship' do
|
345
|
-
worker.push_relationship_to_global_registry
|
346
|
-
(requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
|
347
|
-
expect(organization.global_registry_area_id).to eq 'c99d7d7e-8b14-4fe6-9c11-e5359ee03637'
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
describe Namespaced::Person do
|
354
|
-
describe 'country_of_service' do
|
355
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new person, :country_of_service }
|
356
|
-
context 'as create' do
|
357
|
-
let(:country) { create(:country, global_registry_id: '0f9089a3-2b93-4de8-9b81-92be0261f325') }
|
358
|
-
let(:person) do
|
359
|
-
create(:person, global_registry_id: '2f0c62f1-5738-4860-88bd-5706fb801d7b', country_of_service: country)
|
360
|
-
end
|
361
|
-
let!(:request) do
|
362
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
|
363
|
-
.with(body: { entity: { person: { 'country:relationship': {
|
364
|
-
client_integration_id: "cos_#{person.id}",
|
365
|
-
client_updated_at: '2001-02-03 00:00:00', country_of_service: true,
|
366
|
-
country: country.global_registry_id
|
367
|
-
} }, client_integration_id: person.id } },
|
368
|
-
query: { full_response: 'true', fields: 'country:relationship' })
|
369
|
-
.to_return(body: file_fixture('put_entities_person_country_relationship.json'), status: 200)
|
370
|
-
end
|
371
|
-
|
372
|
-
it 'should push relationship' do
|
373
|
-
worker.push_relationship_to_global_registry
|
374
|
-
expect(request).to have_been_requested.once
|
375
|
-
expect(person.country_of_service_gr_id).to eq '420d2fd1-7a73-41ed-9d8f-5dc79b00a688'
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
context 'missing related model' do
|
380
|
-
let(:person) do
|
381
|
-
create(:person, global_registry_id: '2f0c62f1-5738-4860-88bd-5706fb801d7b', country_of_service_id: 12_345)
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'should do nothing' do
|
385
|
-
worker.push_relationship_to_global_registry
|
386
|
-
expect(person.country_of_service_gr_id).to be nil
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
describe 'country_of_residence' do
|
392
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new person, :country_of_residence }
|
393
|
-
context 'as create' do
|
394
|
-
let(:country) { create(:country, global_registry_id: '7cdaf399-d449-4008-8c6b-3c64a2b2730c') }
|
395
|
-
let(:person) do
|
396
|
-
create(:person, global_registry_id: '2f0c62f1-5738-4860-88bd-5706fb801d7b', country_of_residence: country)
|
397
|
-
end
|
398
|
-
let!(:request) do
|
399
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
|
400
|
-
.with(body: { entity: { person: { 'country:relationship': {
|
401
|
-
client_integration_id: "cor_#{person.id}",
|
402
|
-
client_updated_at: '2001-02-03 00:00:00', country_of_residence: true,
|
403
|
-
country: country.global_registry_id
|
404
|
-
} }, client_integration_id: person.id } },
|
405
|
-
query: { full_response: 'true', fields: 'country:relationship' })
|
406
|
-
.to_return(body: file_fixture('put_entities_person_country_relationship.json'), status: 200)
|
407
|
-
end
|
408
|
-
|
409
|
-
it 'should push relationship' do
|
410
|
-
worker.push_relationship_to_global_registry
|
411
|
-
expect(request).to have_been_requested.once
|
412
|
-
expect(person.country_of_residence_gr_id).to eq 'a4c030ce-13f2-44f5-8131-4003eb21c0ae'
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
describe Community do
|
419
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new community, :infobase_ministry }
|
420
|
-
|
421
|
-
context '\'ministry\' entity_type does not exist' do
|
422
|
-
let(:community) do
|
423
|
-
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723', infobase_id: 2345)
|
424
|
-
end
|
425
|
-
let!(:requests) do
|
426
|
-
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
427
|
-
.with(query: { 'filters[name]' => 'ministry' })
|
428
|
-
.to_return(body: file_fixture('get_entity_types.json'), status: 200),
|
429
|
-
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
430
|
-
.with(query: { 'filters[name]' => 'community' })
|
431
|
-
.to_return(body: file_fixture('get_entity_types_community.json'), status: 200)]
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'should raise an exception' do
|
435
|
-
expect do
|
436
|
-
worker.push_relationship_to_global_registry
|
437
|
-
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityTypeMissing)
|
438
|
-
requests.each { |r| expect(r).to have_been_requested.once }
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
context '\'ministry\' entity_type exists' do
|
443
|
-
context 'ministry global_registry_id not found' do
|
444
|
-
let(:community) do
|
445
|
-
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723',
|
446
|
-
infobase_id: 2345, infobase_gr_id: 'ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
447
|
-
end
|
448
|
-
let!(:requests) do
|
449
|
-
[stub_request(:delete,
|
450
|
-
'https://backend.global-registry.org/entities/ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
451
|
-
.to_return(status: 200)]
|
452
|
-
end
|
453
|
-
|
454
|
-
it 'should delete existing relationship' do
|
455
|
-
allow(community).to receive(:pull_infobase_global_registry_id)
|
456
|
-
worker.push_relationship_to_global_registry
|
457
|
-
requests.each { |r| expect(r).to have_been_requested.once }
|
458
|
-
expect(community.infobase_gr_id).to be nil
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
context 'ministry global_registry_id exists' do
|
463
|
-
let(:community) do
|
464
|
-
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723', infobase_id: 2345)
|
465
|
-
end
|
466
|
-
let!(:requests) do
|
467
|
-
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
468
|
-
.with(query: { 'filters[name]' => 'ministry' })
|
469
|
-
.to_return(body: file_fixture('get_entity_types_ministry.json'), status: 200),
|
470
|
-
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
471
|
-
.with(query: { 'filters[name]' => 'community' })
|
472
|
-
.to_return(body: file_fixture('get_entity_types_community.json'), status: 200),
|
473
|
-
stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
474
|
-
.with(query: { 'filters[between]' =>
|
475
|
-
'3d8a68df-72f3-45f0-848b-4a6322448a6c,f0f0876b-0ebe-4680-9e48-1c3b72523d07' })
|
476
|
-
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
477
|
-
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
478
|
-
.with(body: { relationship_type: { entity_type1_id: '3d8a68df-72f3-45f0-848b-4a6322448a6c',
|
479
|
-
entity_type2_id: 'f0f0876b-0ebe-4680-9e48-1c3b72523d07',
|
480
|
-
relationship1: 'community', relationship2: 'ministry' } })
|
481
|
-
.to_return(body: file_fixture('post_relationship_types_community_ministry.json'), status: 200),
|
482
|
-
stub_request(:put, "https://backend.global-registry.org/entities/#{community.global_registry_id}")
|
483
|
-
.with(body: { entity: { community: { 'ministry:relationship': {
|
484
|
-
client_integration_id: community.id, client_updated_at: '2001-02-03 00:00:00',
|
485
|
-
ministry: '41f767fd-86f4-42e2-8d24-cbc3f697b794'
|
486
|
-
} }, client_integration_id: community.id } },
|
487
|
-
query: { full_response: 'true', fields: 'ministry:relationship' })
|
488
|
-
.to_return(body: file_fixture('put_entities_community_relationship.json'), status: 200),
|
489
|
-
stub_request(:put,
|
490
|
-
'https://backend.global-registry.org/entity_types/f854900f-9dcf-473a-be1b-399dda75edae')
|
491
|
-
.with(body: { entity_type: { id: 'f854900f-9dcf-473a-be1b-399dda75edae', name: 'infobase_ministry' } })
|
492
|
-
.to_return(status: 200)]
|
493
|
-
end
|
494
|
-
it 'should push relationship_type and infobase_ministry relationship' do
|
495
|
-
worker.push_relationship_to_global_registry
|
496
|
-
requests.each { |r| expect(r).to have_been_requested.once }
|
497
|
-
expect(community.infobase_gr_id).to eq('ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
498
|
-
end
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
end
|
503
|
-
end
|