maestrano-connector-rails 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +7 -20
- data/VERSION +1 -1
- data/app/controllers/maestrano/synchronizations_controller.rb +3 -3
- data/app/models/maestrano/connector/rails/concerns/complex_entity.rb +50 -22
- data/app/models/maestrano/connector/rails/concerns/connec_helper.rb +157 -19
- data/app/models/maestrano/connector/rails/concerns/entity.rb +63 -42
- data/app/models/maestrano/connector/rails/concerns/external.rb +4 -0
- data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +18 -5
- data/app/models/maestrano/connector/rails/organization.rb +1 -1
- data/lib/generators/connector/templates/complex_entity_example/contact_and_lead.rb +5 -5
- data/lib/generators/connector/templates/entity.rb +4 -5
- data/lib/generators/connector/templates/external.rb +6 -0
- data/lib/generators/connector/templates/home_index.haml +7 -4
- data/maestrano-connector-rails.gemspec +7 -4
- data/release_notes.md +5 -0
- data/spec/factories.rb +2 -2
- data/spec/integration/complex_id_references_spec.rb +248 -0
- data/spec/integration/complex_naming_spec.rb +191 -0
- data/spec/integration/{integration_complex_spec.rb → complex_spec.rb} +9 -9
- data/spec/integration/connec_to_external_spec.rb +7 -3
- data/spec/integration/id_references_spec.rb +581 -0
- data/spec/integration/singleton_spec.rb +3 -3
- data/spec/models/complex_entity_spec.rb +42 -27
- data/spec/models/connec_helper_spec.rb +399 -31
- data/spec/models/entity_spec.rb +76 -21
- data/spec/models/external_spec.rb +4 -0
- data/spec/models/sub_entity_base_spec.rb +11 -4
- metadata +6 -3
data/spec/models/entity_spec.rb
CHANGED
@@ -144,10 +144,6 @@ describe Maestrano::Connector::Rails::Entity do
|
|
144
144
|
expect(AMapper).to receive(:normalize).with({}).and_return({})
|
145
145
|
subject.map_to_external({})
|
146
146
|
end
|
147
|
-
|
148
|
-
it 'preserve the __connec_id' do
|
149
|
-
expect(subject.map_to_external({__connec_id: 'connec id'})).to eql({__connec_id: 'connec id'}.with_indifferent_access)
|
150
|
-
end
|
151
147
|
end
|
152
148
|
|
153
149
|
describe 'map_to_connec' do
|
@@ -339,7 +335,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
339
335
|
|
340
336
|
describe 'push_entities_to_connec_to' do
|
341
337
|
let(:idmap1) { create(:idmap, organization: organization) }
|
342
|
-
let(:idmap2) { create(:idmap, organization: organization,
|
338
|
+
let(:idmap2) { create(:idmap, organization: organization, connec_id: nil) }
|
343
339
|
let(:entity1) { {name: 'John'} }
|
344
340
|
let(:entity2) { {name: 'Jane'} }
|
345
341
|
let(:entity_with_idmap1) { {entity: entity1, idmap: idmap1} }
|
@@ -357,6 +353,18 @@ describe Maestrano::Connector::Rails::Entity do
|
|
357
353
|
end
|
358
354
|
end
|
359
355
|
|
356
|
+
context 'when no update' do
|
357
|
+
before {
|
358
|
+
allow(subject.class).to receive(:can_update_connec?).and_return(false)
|
359
|
+
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: []}.to_json, {}))
|
360
|
+
}
|
361
|
+
|
362
|
+
it 'filters out the one with a connec_id' do
|
363
|
+
expect(subject).to receive(:batch_op).once.with('post', entity2, nil, 'people')
|
364
|
+
subject.push_entities_to_connec_to(entities_with_idmaps, connec_name)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
360
368
|
context 'without errors' do
|
361
369
|
let(:result200) { {status: 200, body: {connec_name.downcase.pluralize.to_sym => {id: [{provider: 'connec', id: 'id1'}]}}} }
|
362
370
|
let(:result201) { {status: 201, body: {connec_name.downcase.pluralize.to_sym => {id: [{provider: 'connec', id: 'id2'}]}}} }
|
@@ -473,13 +481,18 @@ describe Maestrano::Connector::Rails::Entity do
|
|
473
481
|
|
474
482
|
# External methods
|
475
483
|
describe 'external methods' do
|
484
|
+
before {
|
485
|
+
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('id')
|
486
|
+
}
|
476
487
|
let(:idmap1) { create(:idmap, organization: organization) }
|
477
488
|
let(:idmap2) { create(:idmap, organization: organization, external_id: nil, external_entity: nil, last_push_to_external: nil) }
|
478
489
|
let(:entity1) { {name: 'John'} }
|
479
490
|
let(:entity2) { {name: 'Jane'} }
|
480
|
-
let(:
|
491
|
+
let(:id_refs_only_connec_entity1) { {} }
|
492
|
+
let(:id_refs_only_connec_entity2) { {} }
|
493
|
+
let(:entity_with_idmap1) { {entity: entity1, idmap: idmap1, id_refs_only_connec_entity: id_refs_only_connec_entity1} }
|
481
494
|
let(:connec_id2) { 'connec_id2' }
|
482
|
-
let(:entity_with_idmap2) { {entity: entity2, idmap: idmap2} }
|
495
|
+
let(:entity_with_idmap2) { {entity: entity2, idmap: idmap2, id_refs_only_connec_entity: id_refs_only_connec_entity2} }
|
483
496
|
let(:entities_with_idmaps) { [entity_with_idmap1, entity_with_idmap2] }
|
484
497
|
|
485
498
|
describe 'get_external_entities_wrapper' do
|
@@ -508,7 +521,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
508
521
|
end
|
509
522
|
|
510
523
|
describe 'get_external_entities' do
|
511
|
-
it { expect{ subject.get_external_entities(
|
524
|
+
it { expect{ subject.get_external_entities('') }.to raise_error('Not implemented') }
|
512
525
|
end
|
513
526
|
|
514
527
|
describe 'push_entities_to_external' do
|
@@ -534,7 +547,8 @@ describe Maestrano::Connector::Rails::Entity do
|
|
534
547
|
|
535
548
|
describe 'ids' do
|
536
549
|
before {
|
537
|
-
allow(subject).to receive(:
|
550
|
+
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('id')
|
551
|
+
allow(subject).to receive(:create_external_entity).and_return({'id' => 'id'})
|
538
552
|
allow(subject).to receive(:update_external_entity).and_return(nil)
|
539
553
|
}
|
540
554
|
|
@@ -560,6 +574,44 @@ describe Maestrano::Connector::Rails::Entity do
|
|
560
574
|
end
|
561
575
|
end
|
562
576
|
end
|
577
|
+
|
578
|
+
describe 'id_references' do
|
579
|
+
let(:connec_line_id1) { 'connec_line_id1' }
|
580
|
+
let(:connec_line_id2) { 'connec_line_id2' }
|
581
|
+
let(:ext_line_id1) { 'ext_line_id1' }
|
582
|
+
let(:ext_line_id2) { 'ext_line_id2' }
|
583
|
+
let(:id_refs_only_connec_entity1) { {lines: [{id: [{provider: 'connec', realm: 'org', id: connec_line_id1}]}]}.with_indifferent_access }
|
584
|
+
let(:id_refs_only_connec_entity2) { {lines: [{id: [{provider: 'connec', realm: 'org', id: connec_line_id2}]}]}.with_indifferent_access }
|
585
|
+
before {
|
586
|
+
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('id')
|
587
|
+
allow(subject.class).to receive(:references).and_return({record_references: [], id_references: ['lines/id']})
|
588
|
+
allow(subject).to receive(:create_external_entity).and_return({'id' => 'id', invoice_lines: [{ID: ext_line_id1}]})
|
589
|
+
allow(subject).to receive(:update_external_entity).and_return({'id' => 'id', invoice_lines: [{ID: ext_line_id2}]})
|
590
|
+
allow(subject).to receive(:map_to_connec).and_return({lines: [{id: [{id: ext_line_id1, provider: organization.oauth_provider, realm: organization.oauth_uid}]}]}, {lines: [{id: [{id: ext_line_id2, provider: organization.oauth_provider, realm: organization.oauth_uid}]}]})
|
591
|
+
}
|
592
|
+
let(:batch_param) {
|
593
|
+
{
|
594
|
+
:sequential=>true,
|
595
|
+
:ops=> [
|
596
|
+
{
|
597
|
+
:method=>"put",
|
598
|
+
:url=>"/api/v2/cld-123/people/#{idmap1.connec_id}",
|
599
|
+
:params=>{:people=>{id: [{:id=>idmap1.external_id, :provider=>organization.oauth_provider, :realm=>organization.oauth_uid}], lines: [{id: [{provider: 'connec', realm: 'org', id: connec_line_id1}, {id: ext_line_id1, provider: organization.oauth_provider, realm: organization.oauth_uid}]}]}.with_indifferent_access}
|
600
|
+
},
|
601
|
+
{
|
602
|
+
:method=>"put",
|
603
|
+
:url=>"/api/v2/cld-123/people/#{idmap2.connec_id}",
|
604
|
+
:params=>{:people=>{id: [{:id=>'id', :provider=>organization.oauth_provider, :realm=>organization.oauth_uid}], lines: [{id: [{provider: 'connec', realm: 'org', id: connec_line_id2}, {id: ext_line_id2, provider: organization.oauth_provider, realm: organization.oauth_uid}]}]}.with_indifferent_access}
|
605
|
+
}
|
606
|
+
]
|
607
|
+
}
|
608
|
+
}
|
609
|
+
|
610
|
+
it 'send both the id and the id references to connec' do
|
611
|
+
expect(connec_client).to receive(:batch).with(batch_param).and_return(ActionDispatch::Response.new(200, {}, {results: []}.to_json, {}))
|
612
|
+
subject.push_entities_to_external_to(entities_with_idmaps, external_name)
|
613
|
+
end
|
614
|
+
end
|
563
615
|
end
|
564
616
|
|
565
617
|
describe 'push_entity_to_external' do
|
@@ -591,7 +643,8 @@ describe Maestrano::Connector::Rails::Entity do
|
|
591
643
|
end
|
592
644
|
|
593
645
|
it 'updates the idmap external id, entity and last push' do
|
594
|
-
allow(subject).to receive(:create_external_entity).and_return('999111')
|
646
|
+
allow(subject).to receive(:create_external_entity).and_return({'id' => '999111'})
|
647
|
+
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('999111')
|
595
648
|
subject.push_entity_to_external(entity_with_idmap2, external_name)
|
596
649
|
idmap2.reload
|
597
650
|
expect(idmap2.external_id).to eql('999111')
|
@@ -599,8 +652,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
599
652
|
end
|
600
653
|
|
601
654
|
it 'returns the idmap' do
|
602
|
-
allow(subject).to receive(:create_external_entity).and_return('999111')
|
603
|
-
|
655
|
+
allow(subject).to receive(:create_external_entity).and_return({'id' => '999111'})
|
656
|
+
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('999111')
|
657
|
+
expect(subject.push_entity_to_external(entity_with_idmap2, external_name)).to eql({idmap: idmap2, completed_hash: nil})
|
604
658
|
end
|
605
659
|
end
|
606
660
|
|
@@ -722,7 +776,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
722
776
|
let(:opts) { {connec_preemption: true} }
|
723
777
|
|
724
778
|
it 'keep the connec one' do
|
725
|
-
expect(subject.consolidate_and_map_singleton([connec_entity], [{}])).to eql({connec_entities: [{entity: {map: 'external'}, idmap: idmap}], external_entities: []})
|
779
|
+
expect(subject.consolidate_and_map_singleton([connec_entity], [{}])).to eql({connec_entities: [{entity: {map: 'external'}, idmap: idmap, id_refs_only_connec_entity: {}}], external_entities: []})
|
726
780
|
end
|
727
781
|
|
728
782
|
it 'map with the unfolded references' do
|
@@ -738,7 +792,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
738
792
|
end
|
739
793
|
context 'with a more recent connec one' do
|
740
794
|
let(:updated) { 2.minute.ago }
|
741
|
-
it { expect(subject.consolidate_and_map_singleton([connec_entity], [{}])).to eql({connec_entities: [{entity: {map: 'external'}, idmap: idmap}], external_entities: []}) }
|
795
|
+
it { expect(subject.consolidate_and_map_singleton([connec_entity], [{}])).to eql({connec_entities: [{entity: {map: 'external'}, idmap: idmap, id_refs_only_connec_entity: {}}], external_entities: []}) }
|
742
796
|
end
|
743
797
|
end
|
744
798
|
end
|
@@ -754,16 +808,17 @@ describe Maestrano::Connector::Rails::Entity do
|
|
754
808
|
let(:entity2) { {'id' => id2, 'name' => 'Jane', 'updated_at' => date, 'created_at' => date} }
|
755
809
|
let(:entity_without_refs) { {} }
|
756
810
|
let(:entities) { [entity1, entity2] }
|
811
|
+
let(:id_refs_only_connec_entity) { {a:1} }
|
757
812
|
before {
|
758
813
|
allow(subject.class).to receive(:object_name_from_connec_entity_hash).and_return(connec_human_name)
|
759
814
|
allow(subject).to receive(:map_to_external).and_return({mapped: 'entity'})
|
760
|
-
allow(Maestrano::Connector::Rails::ConnecHelper).to receive(:unfold_references).and_return(entity1
|
815
|
+
allow(Maestrano::Connector::Rails::ConnecHelper).to receive(:unfold_references).and_return({entity: entity1, connec_id: connec_id1, id_refs_only_connec_entity: id_refs_only_connec_entity}, {entity: entity2, connec_id: connec_id2, id_refs_only_connec_entity: id_refs_only_connec_entity}, {entity: nil})
|
761
816
|
}
|
762
817
|
|
763
818
|
context 'when idmaps do not exist' do
|
764
819
|
it 'creates the idmaps with a name and returns the mapped entities with their idmaps' do
|
765
820
|
expect{
|
766
|
-
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first}, {entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.last}])
|
821
|
+
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}, {entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.last, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
767
822
|
}.to change{ Maestrano::Connector::Rails::IdMap.count }.by(2)
|
768
823
|
expect(Maestrano::Connector::Rails::IdMap.last.name).to eql(connec_human_name)
|
769
824
|
end
|
@@ -780,7 +835,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
780
835
|
end
|
781
836
|
|
782
837
|
it 'returns the entity with its idmap' do
|
783
|
-
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1}])
|
838
|
+
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
784
839
|
end
|
785
840
|
|
786
841
|
context 'when external inactive' do
|
@@ -807,7 +862,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
807
862
|
let(:opts) { {full_sync: true} }
|
808
863
|
|
809
864
|
it 'keeps the entity' do
|
810
|
-
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1}])
|
865
|
+
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
811
866
|
end
|
812
867
|
end
|
813
868
|
end
|
@@ -825,7 +880,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
825
880
|
let(:opts) { {full_sync: true} }
|
826
881
|
|
827
882
|
it 'keeps the entity' do
|
828
|
-
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1}])
|
883
|
+
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
829
884
|
end
|
830
885
|
end
|
831
886
|
end
|
@@ -852,7 +907,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
852
907
|
context 'with connec preemption true' do
|
853
908
|
it 'keeps the entity and discards the external one' do
|
854
909
|
subject.instance_variable_set(:@opts, {connec_preemption: true})
|
855
|
-
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first}])
|
910
|
+
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
856
911
|
expect(external_entities).to be_empty
|
857
912
|
end
|
858
913
|
end
|
@@ -868,7 +923,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
868
923
|
let(:date) { 1.day.ago }
|
869
924
|
|
870
925
|
it 'keeps the entity and discards the external one' do
|
871
|
-
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first}])
|
926
|
+
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
872
927
|
expect(external_entities).to be_empty
|
873
928
|
end
|
874
929
|
end
|
@@ -20,4 +20,8 @@ describe Maestrano::Connector::Rails::External do
|
|
20
20
|
describe 'entities_list' do
|
21
21
|
it { expect{ subject.entities_list }.to raise_error(RuntimeError) }
|
22
22
|
end
|
23
|
+
|
24
|
+
describe 'create_account_link' do
|
25
|
+
it { expect{ subject.create_account_link }.to raise_error(RuntimeError) }
|
26
|
+
end
|
23
27
|
end
|
@@ -115,6 +115,17 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
115
115
|
subject.map_to('Name', {})
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
context 'when connec_matching_fields' do
|
120
|
+
before {
|
121
|
+
expect(AMapper).to receive(:denormalize).and_return({opts: {a: 2}})
|
122
|
+
allow(subject.class).to receive(:connec_matching_fields).and_return('matching_fields')
|
123
|
+
}
|
124
|
+
|
125
|
+
it 'adds the matching_fields in the entity opts' do
|
126
|
+
expect(subject.map_to('Name', {})).to eql({id: [Maestrano::Connector::Rails::ConnecHelper.id_hash('this id', organization)], opts: {a: 2, matching_fields: 'matching_fields'}}.with_indifferent_access)
|
127
|
+
end
|
128
|
+
end
|
118
129
|
end
|
119
130
|
|
120
131
|
context 'when not external' do
|
@@ -126,10 +137,6 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
126
137
|
expect(AMapper).to receive(:normalize).and_return({})
|
127
138
|
subject.map_to('Name', {})
|
128
139
|
end
|
129
|
-
|
130
|
-
it 'preserve the __connec_id' do
|
131
|
-
expect(subject.map_to('Name', {__connec_id: 'connec id'})).to eql({__connec_id: 'connec id'}.with_indifferent_access)
|
132
|
-
end
|
133
140
|
end
|
134
141
|
end
|
135
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maestrano-connector-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Berard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -522,9 +522,12 @@ files:
|
|
522
522
|
- spec/dummy/public/favicon.ico
|
523
523
|
- spec/dummy/tmp/cache/.keep
|
524
524
|
- spec/factories.rb
|
525
|
+
- spec/integration/complex_id_references_spec.rb
|
526
|
+
- spec/integration/complex_naming_spec.rb
|
527
|
+
- spec/integration/complex_spec.rb
|
525
528
|
- spec/integration/connec_to_external_spec.rb
|
526
529
|
- spec/integration/external_to_connec_spec.rb
|
527
|
-
- spec/integration/
|
530
|
+
- spec/integration/id_references_spec.rb
|
528
531
|
- spec/integration/singleton_spec.rb
|
529
532
|
- spec/jobs/all_synchronizations_job_spec.rb
|
530
533
|
- spec/jobs/push_to_connec_job_spec.rb
|