maestrano-connector-rails 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/app/models/maestrano/connector/rails/concerns/entity.rb +94 -19
- data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +12 -14
- data/lib/generators/connector/templates/example_entity.rb +15 -0
- data/maestrano-connector-rails.gemspec +8 -8
- data/release_notes.md +9 -0
- data/spec/integration/complex_spec.rb +298 -4
- data/spec/integration/connec_to_external_spec.rb +117 -10
- data/spec/models/complex_entity_spec.rb +14 -10
- data/spec/models/entity_spec.rb +87 -72
- data/spec/models/sub_entity_base_spec.rb +33 -21
- metadata +7 -5
@@ -4,7 +4,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
4
4
|
|
5
5
|
describe 'class methods' do
|
6
6
|
subject { Maestrano::Connector::Rails::ComplexEntity }
|
7
|
-
|
7
|
+
|
8
8
|
describe 'connec_entities_names' do
|
9
9
|
it { expect{ subject.connec_entities_names }.to raise_error('Not implemented') }
|
10
10
|
end
|
@@ -233,17 +233,18 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
233
233
|
let(:connec_name) { 'sc_e1' }
|
234
234
|
let(:external_name) { 'ext1' }
|
235
235
|
let(:id_refs_only_connec_entity) { {a: 1} }
|
236
|
-
before
|
236
|
+
before do
|
237
237
|
allow(subject.class).to receive(:connec_entities_names).and_return(['sc_e1'])
|
238
238
|
allow(subject.class).to receive(:external_entities_names).and_return(['ext1'])
|
239
239
|
allow(Entities::SubEntities::ScE1).to receive(:external?).and_return(false)
|
240
240
|
allow(Entities::SubEntities::ScE1).to receive(:entity_name).and_return(connec_name)
|
241
|
-
allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:map_to).with(external_name, entity).and_return(mapped_entity)
|
241
|
+
allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:map_to).with(external_name, entity, first_time_synch).and_return(mapped_entity)
|
242
242
|
allow(Entities::SubEntities::ScE1).to receive(:object_name_from_connec_entity_hash).and_return(human_name)
|
243
243
|
allow(Maestrano::Connector::Rails::ConnecHelper).to receive(:unfold_references).and_return({entity: entity, connec_id: connec_id, id_refs_only_connec_entity: id_refs_only_connec_entity})
|
244
|
-
|
244
|
+
end
|
245
245
|
|
246
246
|
context 'when idmaps do not exist' do
|
247
|
+
let(:first_time_synch) { true }
|
247
248
|
it 'creates the idmaps with a name and returns the mapped entities with their idmaps' do
|
248
249
|
expect{
|
249
250
|
expect(subject.consolidate_and_map_connec_entities(modelled_connec_entities, {})).to eql({connec_name => {external_name => [{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}]}})
|
@@ -253,6 +254,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
253
254
|
end
|
254
255
|
|
255
256
|
context 'when idmap exists' do
|
257
|
+
let!(:first_time_synch) { false }
|
256
258
|
let!(:idmap1) { create(:idmap, organization: organization, connec_entity: connec_name.downcase, external_entity: external_name.downcase, external_id: id, connec_id: connec_id) }
|
257
259
|
|
258
260
|
it 'does not create an idmap' do
|
@@ -280,7 +282,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
280
282
|
end
|
281
283
|
|
282
284
|
context 'when last_push_to_external is recent' do
|
283
|
-
before
|
285
|
+
before do
|
286
|
+
idmap1.update(last_push_to_external: 2.second.ago)
|
287
|
+
end
|
284
288
|
it 'discards the entity' do
|
285
289
|
expect(subject.consolidate_and_map_connec_entities(modelled_connec_entities, {})).to eql({connec_name => {external_name => []}})
|
286
290
|
end
|
@@ -317,8 +321,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
317
321
|
}
|
318
322
|
|
319
323
|
context 'with connec one more recent' do
|
320
|
-
let(:external_date) { 1.year.ago }
|
321
|
-
let(:date) { 1.day.ago }
|
324
|
+
let(:external_date) { 1.year.ago }
|
325
|
+
let(:date) { 1.day.ago }
|
322
326
|
|
323
327
|
it 'keeps the entity and discards the external one' do
|
324
328
|
expect(subject.consolidate_and_map_connec_entities(modelled_connec_entities, modelled_external_entities)).to eql({connec_name => {external_name => [{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}]}})
|
@@ -327,8 +331,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
327
331
|
end
|
328
332
|
|
329
333
|
context 'with external one more recent' do
|
330
|
-
let(:external_date) { 1.month.ago }
|
331
|
-
let(:date) { 1.year.ago }
|
334
|
+
let(:external_date) { 1.month.ago }
|
335
|
+
let(:date) { 1.year.ago }
|
332
336
|
|
333
337
|
it 'discards the entity and keep the external one' do
|
334
338
|
expect(subject.consolidate_and_map_connec_entities(modelled_connec_entities, modelled_external_entities)).to eql({connec_name => {external_name => []}})
|
@@ -402,4 +406,4 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
402
406
|
end
|
403
407
|
end
|
404
408
|
end
|
405
|
-
end
|
409
|
+
end
|
data/spec/models/entity_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe Maestrano::Connector::Rails::Entity do
|
|
7
7
|
|
8
8
|
# IdMap methods
|
9
9
|
describe 'idmaps methods' do
|
10
|
-
before
|
10
|
+
before do
|
11
11
|
allow(subject).to receive(:connec_entity_name).and_return('Ab')
|
12
12
|
allow(subject).to receive(:external_entity_name).and_return('Ab')
|
13
|
-
|
13
|
+
end
|
14
14
|
let(:n_hash) { {connec_entity: 'ab', external_entity: 'ab'} }
|
15
15
|
|
16
16
|
it { expect(subject.names_hash).to eql(n_hash) }
|
@@ -32,13 +32,13 @@ describe Maestrano::Connector::Rails::Entity do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe 'normalized_connec_entity_name' do
|
35
|
-
before
|
35
|
+
before do
|
36
36
|
allow(subject).to receive(:connec_entity_name).and_return(connec_name)
|
37
|
-
|
37
|
+
end
|
38
38
|
context 'for a singleton resource' do
|
39
|
-
before
|
39
|
+
before do
|
40
40
|
allow(subject).to receive(:singleton?).and_return(true)
|
41
|
-
|
41
|
+
end
|
42
42
|
|
43
43
|
context 'for a simple name' do
|
44
44
|
let(:connec_name) { 'Person' }
|
@@ -52,9 +52,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'for a non singleton resource' do
|
55
|
-
before
|
55
|
+
before do
|
56
56
|
allow(subject).to receive(:singleton?).and_return(false)
|
57
|
-
|
57
|
+
end
|
58
58
|
|
59
59
|
context 'for a simple name' do
|
60
60
|
let(:connec_name) { 'Person' }
|
@@ -124,9 +124,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
context 'when singleton' do
|
127
|
-
before
|
127
|
+
before do
|
128
128
|
allow(subject).to receive(:singleton?).and_return(true)
|
129
|
-
|
129
|
+
end
|
130
130
|
|
131
131
|
it 'returns the connec_entity_name' do
|
132
132
|
allow(subject).to receive(:connec_entity_name).and_return('tree')
|
@@ -151,35 +151,50 @@ describe Maestrano::Connector::Rails::Entity do
|
|
151
151
|
subject { Maestrano::Connector::Rails::Entity.new(organization, connec_client, external_client, opts) }
|
152
152
|
let(:connec_name) { 'Person' }
|
153
153
|
let(:external_name) { 'external_name' }
|
154
|
-
before
|
154
|
+
before do
|
155
155
|
allow(subject.class).to receive(:connec_entity_name).and_return(connec_name)
|
156
156
|
allow(subject.class).to receive(:external_entity_name).and_return(external_name)
|
157
|
-
|
157
|
+
end
|
158
158
|
|
159
159
|
describe 'Mapper methods' do
|
160
|
-
before(:each)
|
160
|
+
before(:each) do
|
161
161
|
class AMapper
|
162
162
|
extend HashMapper
|
163
163
|
end
|
164
164
|
allow(subject.class).to receive(:mapper_class).and_return(AMapper)
|
165
|
-
|
165
|
+
allow(subject.class).to receive(:creation_mapper_class).and_call_original
|
166
|
+
end
|
166
167
|
|
167
168
|
describe 'map_to_external' do
|
168
169
|
it 'calls the mapper normalize' do
|
169
|
-
expect(AMapper).to receive(:normalize).with({}).and_return({})
|
170
|
+
expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
|
170
171
|
subject.map_to_external({})
|
171
172
|
end
|
173
|
+
|
174
|
+
it 'calls the creation_mapper normalize if passed true as second argument' do
|
175
|
+
expect(subject.class).to receive(:creation_mapper_class)
|
176
|
+
#if not overridden #creation_mapper_class calls #mapper_class
|
177
|
+
expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
|
178
|
+
subject.map_to_external({}, true)
|
179
|
+
end
|
172
180
|
end
|
173
181
|
|
174
182
|
describe 'map_to_connec' do
|
175
|
-
before
|
183
|
+
before do
|
176
184
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('this id')
|
177
|
-
|
185
|
+
end
|
178
186
|
it 'calls the mapper denormalize' do
|
179
|
-
expect(AMapper).to receive(:denormalize).with({}).and_return({})
|
187
|
+
expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
|
180
188
|
subject.map_to_connec({})
|
181
189
|
end
|
182
190
|
|
191
|
+
it 'calls the creation_mapper denormalize if passed true as second argument' do
|
192
|
+
expect(subject.class).to receive(:creation_mapper_class)
|
193
|
+
#if not overridden #creation_mapper_class calls #mapper_class
|
194
|
+
expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
|
195
|
+
subject.map_to_connec({}, true)
|
196
|
+
end
|
197
|
+
|
183
198
|
it 'calls for reference folding' do
|
184
199
|
refs = %w(organization_id person_id)
|
185
200
|
allow(subject.class).to receive(:references).and_return(refs)
|
@@ -207,10 +222,10 @@ describe Maestrano::Connector::Rails::Entity do
|
|
207
222
|
|
208
223
|
describe 'get_connec_entities' do
|
209
224
|
describe 'when write only' do
|
210
|
-
before
|
225
|
+
before do
|
211
226
|
allow(subject.class).to receive(:can_read_connec?).and_return(false)
|
212
227
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [{first_name: 'Lea'}]}.to_json, {}))
|
213
|
-
|
228
|
+
end
|
214
229
|
|
215
230
|
it { expect(subject.get_connec_entities(nil)).to eql([]) }
|
216
231
|
end
|
@@ -222,10 +237,10 @@ describe Maestrano::Connector::Rails::Entity do
|
|
222
237
|
|
223
238
|
describe 'with response' do
|
224
239
|
context 'for a singleton resource' do
|
225
|
-
before
|
240
|
+
before do
|
226
241
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {person: []}.to_json, {}))
|
227
242
|
allow(subject.class).to receive(:singleton?).and_return(true)
|
228
|
-
|
243
|
+
end
|
229
244
|
|
230
245
|
it 'calls get with a singularize url' do
|
231
246
|
expect(connec_client).to receive(:get).with("#{connec_name.downcase}?")
|
@@ -234,15 +249,15 @@ describe Maestrano::Connector::Rails::Entity do
|
|
234
249
|
end
|
235
250
|
|
236
251
|
context 'for a non singleton resource' do
|
237
|
-
before
|
252
|
+
before do
|
238
253
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: []}.to_json, {}))
|
239
|
-
|
254
|
+
end
|
240
255
|
|
241
256
|
context 'with limit and skip opts' do
|
242
257
|
let(:opts) { {__skip: 100, __limit: 50} }
|
243
|
-
before
|
258
|
+
before do
|
244
259
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [], pagination: {next: "https://api-connec.maestrano.com/api/v2/cld-dkg601/people?%24skip=10&%24top=10"}}.to_json, {}), ActionDispatch::Response.new(200, {}, {people: []}.to_json, {}))
|
245
|
-
|
260
|
+
end
|
246
261
|
|
247
262
|
it 'performs a size limited date and do not paginate' do
|
248
263
|
uri_param = {"$filter" => "updated_at gt '#{sync.updated_at.iso8601}'", "$skip" => 100, "$top" => 50}.to_query
|
@@ -298,9 +313,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
298
313
|
end
|
299
314
|
|
300
315
|
context 'with pagination' do
|
301
|
-
before
|
316
|
+
before do
|
302
317
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [], pagination: {next: "https://api-connec.maestrano.com/api/v2/cld-dkg601/people?%24skip=10&%24top=10"}}.to_json, {}), ActionDispatch::Response.new(200, {}, {people: []}.to_json, {}))
|
303
|
-
|
318
|
+
end
|
304
319
|
|
305
320
|
it 'calls get multiple times' do
|
306
321
|
expect(connec_client).to receive(:get).with('people?')
|
@@ -322,30 +337,30 @@ describe Maestrano::Connector::Rails::Entity do
|
|
322
337
|
|
323
338
|
describe 'failures' do
|
324
339
|
context 'when no response' do
|
325
|
-
before
|
340
|
+
before do
|
326
341
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, nil, {}))
|
327
|
-
|
342
|
+
end
|
328
343
|
it { expect{ subject.get_connec_entities(nil) }.to raise_error(RuntimeError) }
|
329
344
|
end
|
330
345
|
|
331
346
|
context 'when invalid response' do
|
332
|
-
before
|
347
|
+
before do
|
333
348
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {not_an_entity: []}.to_json, {}))
|
334
|
-
|
349
|
+
end
|
335
350
|
it { expect{ subject.get_connec_entities(nil) }.to raise_error(RuntimeError) }
|
336
351
|
end
|
337
352
|
|
338
353
|
context 'when no response in pagination' do
|
339
|
-
before
|
354
|
+
before do
|
340
355
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [], pagination: {next: "https://api-connec.maestrano.com/api/v2/cld-dkg601/people?%24skip=10&%24top=10"}}.to_json, {}), ActionDispatch::Response.new(200, {}, nil, {}))
|
341
|
-
|
356
|
+
end
|
342
357
|
it { expect{ subject.get_connec_entities(nil) }.to raise_error(RuntimeError) }
|
343
358
|
end
|
344
359
|
|
345
360
|
context 'when invalid response in pagination' do
|
346
|
-
before
|
361
|
+
before do
|
347
362
|
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [], pagination: {next: "https://api-connec.maestrano.com/api/v2/cld-dkg601/people?%24skip=10&%24top=10"}}.to_json, {}), ActionDispatch::Response.new(200, {}, {not_an_entity: []}.to_json, {}))
|
348
|
-
|
363
|
+
end
|
349
364
|
it { expect{ subject.get_connec_entities(nil) }.to raise_error(RuntimeError) }
|
350
365
|
end
|
351
366
|
end
|
@@ -368,9 +383,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
368
383
|
let(:entities_with_idmaps) { [entity_with_idmap1, entity_with_idmap2] }
|
369
384
|
|
370
385
|
context 'when read only' do
|
371
|
-
before
|
386
|
+
before do
|
372
387
|
allow(subject.class).to receive(:can_write_connec?).and_return(false)
|
373
|
-
|
388
|
+
end
|
374
389
|
|
375
390
|
it 'does nothing' do
|
376
391
|
expect(subject).to_not receive(:batch_op)
|
@@ -379,10 +394,10 @@ describe Maestrano::Connector::Rails::Entity do
|
|
379
394
|
end
|
380
395
|
|
381
396
|
context 'when no update' do
|
382
|
-
before
|
397
|
+
before do
|
383
398
|
allow(subject.class).to receive(:can_update_connec?).and_return(false)
|
384
399
|
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: []}.to_json, {}))
|
385
|
-
|
400
|
+
end
|
386
401
|
|
387
402
|
it 'filters out the one with a connec_id' do
|
388
403
|
expect(subject).to receive(:batch_op).once.with('post', entity2, nil, 'people')
|
@@ -393,9 +408,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
393
408
|
context 'without errors' do
|
394
409
|
let(:result200) { {status: 200, body: {connec_name.downcase.pluralize.to_sym => {id: [{provider: 'connec', id: 'id1'}]}}} }
|
395
410
|
let(:result201) { {status: 201, body: {connec_name.downcase.pluralize.to_sym => {id: [{provider: 'connec', id: 'id2'}]}}} }
|
396
|
-
before
|
411
|
+
before do
|
397
412
|
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [result200, result201]}.to_json, {}))
|
398
|
-
|
413
|
+
end
|
399
414
|
|
400
415
|
let(:batch_request) {
|
401
416
|
{
|
@@ -441,13 +456,13 @@ describe Maestrano::Connector::Rails::Entity do
|
|
441
456
|
let(:results) { [] }
|
442
457
|
|
443
458
|
context 'when 100 entities' do
|
444
|
-
before
|
459
|
+
before do
|
445
460
|
100.times do
|
446
461
|
entities << entity_with_idmap1
|
447
462
|
results << result200
|
448
463
|
end
|
449
464
|
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: results}.to_json, {}))
|
450
|
-
|
465
|
+
end
|
451
466
|
|
452
467
|
it 'does one call' do
|
453
468
|
expect(connec_client).to receive(:batch).once
|
@@ -456,14 +471,14 @@ describe Maestrano::Connector::Rails::Entity do
|
|
456
471
|
end
|
457
472
|
|
458
473
|
context 'when more than 100 entities' do
|
459
|
-
before
|
474
|
+
before do
|
460
475
|
100.times do
|
461
476
|
entities << entity_with_idmap1
|
462
477
|
results << result200
|
463
478
|
end
|
464
479
|
entities << entity_with_idmap2
|
465
480
|
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: results}.to_json, {}), ActionDispatch::Response.new(200, {}, {results: [result201]}.to_json, {}))
|
466
|
-
|
481
|
+
end
|
467
482
|
|
468
483
|
it 'does several call' do
|
469
484
|
expect(connec_client).to receive(:batch).twice
|
@@ -482,9 +497,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
482
497
|
context 'with errors' do
|
483
498
|
let(:err_msg) { 'Not Found' }
|
484
499
|
let(:result400) { {status: 400, body: err_msg} }
|
485
|
-
before
|
500
|
+
before do
|
486
501
|
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [result400, result400]}.to_json, {}))
|
487
|
-
|
502
|
+
end
|
488
503
|
|
489
504
|
it 'stores the errr in the idmap' do
|
490
505
|
subject.push_entities_to_connec_to(entities_with_idmaps, '')
|
@@ -506,9 +521,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
506
521
|
|
507
522
|
# External methods
|
508
523
|
describe 'external methods' do
|
509
|
-
before
|
524
|
+
before do
|
510
525
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('id')
|
511
|
-
|
526
|
+
end
|
512
527
|
let(:idmap1) { create(:idmap, organization: organization) }
|
513
528
|
let(:idmap2) { create(:idmap, organization: organization, external_id: nil, external_entity: nil, last_push_to_external: nil) }
|
514
529
|
let(:entity1) { {name: 'John'} }
|
@@ -571,11 +586,11 @@ describe Maestrano::Connector::Rails::Entity do
|
|
571
586
|
end
|
572
587
|
|
573
588
|
describe 'ids' do
|
574
|
-
before
|
589
|
+
before do
|
575
590
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('id')
|
576
591
|
allow(subject).to receive(:create_external_entity).and_return({'id' => 'id'})
|
577
592
|
allow(subject).to receive(:update_external_entity).and_return(nil)
|
578
|
-
|
593
|
+
end
|
579
594
|
|
580
595
|
context 'when ids to send to connec' do
|
581
596
|
let(:batch_param) {
|
@@ -589,9 +604,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
589
604
|
end
|
590
605
|
|
591
606
|
context 'when no id to send to connec' do
|
592
|
-
before
|
607
|
+
before do
|
593
608
|
idmap2.update(external_id: 'id')
|
594
|
-
|
609
|
+
end
|
595
610
|
|
596
611
|
it 'does not do a call on connec' do
|
597
612
|
expect(connec_client).to_not receive(:batch)
|
@@ -725,17 +740,17 @@ describe Maestrano::Connector::Rails::Entity do
|
|
725
740
|
describe 'consolidate_and_map methods' do
|
726
741
|
let(:id) { '56882' }
|
727
742
|
let(:date) { 2.hour.ago }
|
728
|
-
before
|
743
|
+
before do
|
729
744
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return(id)
|
730
745
|
allow(subject.class).to receive(:last_update_date_from_external_entity_hash).and_return(date)
|
731
746
|
allow(subject.class).to receive(:creation_date_from_external_entity_hash).and_return(date)
|
732
|
-
|
747
|
+
end
|
733
748
|
|
734
749
|
describe 'consolidate_and_map_data' do
|
735
750
|
context 'singleton' do
|
736
|
-
before
|
751
|
+
before do
|
737
752
|
allow(subject.class).to receive(:singleton?).and_return(true)
|
738
|
-
|
753
|
+
end
|
739
754
|
|
740
755
|
it 'returns the consolidate_and_map_singleton method result' do
|
741
756
|
expect(subject).to receive(:consolidate_and_map_singleton).with({}, {}).and_return({result: 1})
|
@@ -754,12 +769,12 @@ describe Maestrano::Connector::Rails::Entity do
|
|
754
769
|
|
755
770
|
describe 'consolidate_and_map_singleton' do
|
756
771
|
let(:connec_id) { [{'id' => 'lala', 'provider' => 'connec', 'realm' => 'realm'}] }
|
757
|
-
before
|
772
|
+
before do
|
758
773
|
allow(subject).to receive(:map_to_connec).and_return({map: 'connec'})
|
759
774
|
allow(subject).to receive(:map_to_external).and_return({map: 'external'})
|
760
775
|
allow(subject.class).to receive(:object_name_from_connec_entity_hash).and_return('connec human name')
|
761
776
|
allow(subject.class).to receive(:object_name_from_external_entity_hash).and_return('external human name')
|
762
|
-
|
777
|
+
end
|
763
778
|
|
764
779
|
it { expect(subject.consolidate_and_map_singleton([], [])).to eql({connec_entities: [], external_entities: []}) }
|
765
780
|
|
@@ -899,9 +914,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
899
914
|
end
|
900
915
|
|
901
916
|
context 'when before date_filtering_limit' do
|
902
|
-
before
|
917
|
+
before do
|
903
918
|
organization.update(date_filtering_limit: 5.minutes.ago)
|
904
|
-
|
919
|
+
end
|
905
920
|
|
906
921
|
it 'discards the entity' do
|
907
922
|
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([])
|
@@ -922,9 +937,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
922
937
|
let(:entities) { [entity1] }
|
923
938
|
let(:external_entity_1) { {'id' => id1} }
|
924
939
|
let(:external_entities) { [external_entity_1] }
|
925
|
-
before
|
940
|
+
before do
|
926
941
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return(id1)
|
927
|
-
|
942
|
+
end
|
928
943
|
|
929
944
|
context 'with opts' do
|
930
945
|
context 'with connec preemption false' do
|
@@ -945,9 +960,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
945
960
|
end
|
946
961
|
|
947
962
|
context 'without opts' do
|
948
|
-
before
|
963
|
+
before do
|
949
964
|
allow(subject.class).to receive(:last_update_date_from_external_entity_hash).and_return(external_date)
|
950
|
-
|
965
|
+
end
|
951
966
|
|
952
967
|
context 'with connec one more recent' do
|
953
968
|
let(:external_date) { 1.year.ago }
|
@@ -976,11 +991,11 @@ describe Maestrano::Connector::Rails::Entity do
|
|
976
991
|
let(:entity) { {'id' => id, 'name' => 'Jane'} }
|
977
992
|
let(:id) { 'id' }
|
978
993
|
let(:external_human_name) { 'external human name' }
|
979
|
-
before
|
994
|
+
before do
|
980
995
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return(id)
|
981
996
|
allow(subject.class).to receive(:object_name_from_external_entity_hash).and_return(external_human_name)
|
982
997
|
allow(subject).to receive(:map_to_connec).and_return({mapped: 'ext_entity'})
|
983
|
-
|
998
|
+
end
|
984
999
|
|
985
1000
|
context 'when idmap exists' do
|
986
1001
|
let!(:idmap) { create(:idmap, organization: organization, connec_entity: connec_name.downcase, external_entity: external_name.downcase, external_id: id) }
|
@@ -1004,9 +1019,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
1004
1019
|
end
|
1005
1020
|
|
1006
1021
|
context 'when entity is inactive' do
|
1007
|
-
before
|
1022
|
+
before do
|
1008
1023
|
allow(subject.class).to receive(:inactive_from_external_entity_hash?).and_return(true)
|
1009
|
-
|
1024
|
+
end
|
1010
1025
|
|
1011
1026
|
it 'discards the entity' do
|
1012
1027
|
expect(subject.consolidate_and_map_external_entities([entity], connec_name)).to eql([])
|
@@ -1035,9 +1050,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
1035
1050
|
end
|
1036
1051
|
|
1037
1052
|
context 'when before date_filtering_limit' do
|
1038
|
-
before
|
1053
|
+
before do
|
1039
1054
|
organization.update(date_filtering_limit: 5.minutes.ago)
|
1040
|
-
|
1055
|
+
end
|
1041
1056
|
|
1042
1057
|
it 'discards the entity' do
|
1043
1058
|
expect(subject.consolidate_and_map_external_entities([entity], connec_name)).to eql([])
|