maestrano-connector-rails 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ede31586bf582ced3d9a9024968edc3ac1d1732
4
- data.tar.gz: da7c491c555373c153650012442613b9edb8f6fb
3
+ metadata.gz: d892d2db085d00a255178b5c4f7ed07ef4c1c354
4
+ data.tar.gz: 80b21802042d7b4549e4c580bf6ad3ba990ae297
5
5
  SHA512:
6
- metadata.gz: 00e346e7cc00061e7c3c5377f51afb23f78fc59904cdad730016e9b3b11d8c72eb9d40e0e7929fc4a5d81103d09a98b253894a1e714ed8467213b5ca1798aa63
7
- data.tar.gz: 9078bb564275af62c3646b496e771c78777824f8d60b23c35b9ffc990a18ff9be881e7057fea0a1220890623352432ee61aea1cf4bfba70dfa166e14231cce7c
6
+ metadata.gz: 7e733367307412202e3a6f539fa8a03e62977b63d2e586d78bde6ac40c15d4db337aae60c6128759bc576518bb7276738df749ba9e50fd6d7d960514c63e46ce
7
+ data.tar.gz: c12a9abe28df122927cb134d01d9f3f0e9ade056b79b8b9a97e59bfe5041f118cba7e67c23faba951e59647471fa78dc142028863fb2f4eebac36b1fda3d52b1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.12
1
+ 0.2.13
@@ -16,14 +16,12 @@ class Maestrano::ConnecController < Maestrano::Rails::WebHookController
16
16
 
17
17
  # Build expected input for consolidate_and_map_data
18
18
  if entity_instance_hash[:is_complex]
19
- entity = Hash[ *entity_instance.connec_entities_names.collect{|name| name == entity_name.singularize ? [name, [entity]] : [ name, []]}.flatten(1) ]
20
- entity_instance.consolidate_and_map_data(entity, Hash[ *entity_instance.external_entities_names.collect{|name| [ name, []]}.flatten(1) ], organization, {})
19
+ mapped_entity = entity_instance.consolidate_and_map_data(Hash[ *entity_instance.connec_entities_names.collect{|name| name == entity_name.singularize ? [name, [entity]] : [ name, []]}.flatten(1) ], Hash[ *entity_instance.external_entities_names.collect{|name| [ name, []]}.flatten(1) ], organization, {})
21
20
  else
22
- entity = [entity]
23
- entity_instance.consolidate_and_map_data(entity, [], organization, {})
21
+ mapped_entity = entity_instance.consolidate_and_map_data([entity], [], organization, {})
24
22
  end
25
23
 
26
- entity_instance.push_entities_to_external(external_client, entity, organization)
24
+ entity_instance.push_entities_to_external(external_client, mapped_entity[:connec_entities], organization)
27
25
  end
28
26
 
29
27
  else
@@ -48,9 +46,9 @@ class Maestrano::ConnecController < Maestrano::Rails::WebHookController
48
46
  Maestrano::Connector::Rails::Entity.entities_list.each do |entity_name_from_list|
49
47
  instance = "Entities::#{entity_name_from_list.singularize.titleize.split.join}".constantize.new
50
48
  if instance.methods.include?('connec_entities_names'.to_sym)
51
- return {instance: instance, is_complex: true, name: entity_name_from_list} if instance.connec_entities_names.include?(entity_name.singularize)
49
+ return {instance: instance, is_complex: true, name: entity_name_from_list} if instance.connec_entities_names.include?(entity_name.singularize.downcase)
52
50
  elsif instance.methods.include?('connec_entity_name'.to_sym)
53
- return {instance: instance, is_complex: false, name: entity_name_from_list} if instance.connec_entity_name == entity_name.singularize
51
+ return {instance: instance, is_complex: false, name: entity_name_from_list} if instance.connec_entity_name == entity_name.singularize.downcase
54
52
  end
55
53
  end
56
54
  nil
@@ -14,13 +14,12 @@ module Maestrano::Connector::Rails
14
14
  next unless organization.synchronized_entities[entity_instance_hash[:name].to_sym]
15
15
 
16
16
  if entity_instance_hash[:is_complex]
17
- entities = Hash[ *entity_instance.external_entities_names.collect{|name| name == external_entity_name.singularize ? [name, entities] : [ name, []]}.flatten(1) ]
18
- entity_instance.consolidate_and_map_data(Hash[ *entity_instance.connec_entities_names.collect{|name| [ name, []]}.flatten(1) ], entities, organization, {})
17
+ mapped_entities = entity_instance.consolidate_and_map_data(Hash[ *entity_instance.connec_entities_names.collect{|name| [ name, []]}.flatten(1) ], Hash[ *entity_instance.external_entities_names.collect{|name| name == external_entity_name.singularize ? [name, entities] : [ name, []]}.flatten(1) ], organization, {})
19
18
  else
20
- entity_instance.consolidate_and_map_data([], entities, organization, {})
19
+ mapped_entities = entity_instance.consolidate_and_map_data([], entities, organization, {})
21
20
  end
22
21
 
23
- entity_instance.push_entities_to_connec(connec_client, entities, organization)
22
+ entity_instance.push_entities_to_connec(connec_client, mapped_entities[:external_entities], organization)
24
23
  else
25
24
  Rails.logger.warn "Called push to connec job with unknow entity: #{external_entity_name}"
26
25
  end
@@ -32,9 +31,9 @@ module Maestrano::Connector::Rails
32
31
  Maestrano::Connector::Rails::Entity.entities_list.each do |entity_name_from_list|
33
32
  instance = "Entities::#{entity_name_from_list.singularize.titleize.split.join}".constantize.new
34
33
  if instance.methods.include?('external_entities_names'.to_sym)
35
- return {instance: instance, is_complex: true, name: entity_name_from_list} if instance.external_entities_names.include?(entity_name.singularize)
34
+ return {instance: instance, is_complex: true, name: entity_name_from_list} if instance.external_entities_names.include?(entity_name.singularize.downcase)
36
35
  elsif instance.methods.include?('external_entity_name'.to_sym)
37
- return {instance: instance, is_complex: false, name: entity_name_from_list} if instance.external_entity_name == entity_name.singularize
36
+ return {instance: instance, is_complex: false, name: entity_name_from_list} if instance.external_entity_name == entity_name.singularize.downcase
38
37
  end
39
38
  end
40
39
  nil
@@ -46,14 +46,14 @@ module Maestrano::Connector::Rails
46
46
  end
47
47
  end
48
48
 
49
- def sync_entity(entity, organization, connec_client, external_client, last_synchronization, opts)
50
- entity_instance = "Entities::#{entity.titleize.split.join}".constantize.new
49
+ def sync_entity(entity_name, organization, connec_client, external_client, last_synchronization, opts)
50
+ entity_instance = "Entities::#{entity_name.titleize.split.join}".constantize.new
51
51
 
52
52
  external_entities = entity_instance.get_external_entities(external_client, last_synchronization, organization, opts)
53
53
  connec_entities = entity_instance.get_connec_entities(connec_client, last_synchronization, organization, opts)
54
- entity_instance.consolidate_and_map_data(connec_entities, external_entities, organization, opts)
55
- entity_instance.push_entities_to_external(external_client, connec_entities, organization)
56
- entity_instance.push_entities_to_connec(connec_client, external_entities, organization)
54
+ mapped_entities = entity_instance.consolidate_and_map_data(connec_entities, external_entities, organization, opts)
55
+ entity_instance.push_entities_to_external(external_client, mapped_entities[:connec_entities], organization)
56
+ entity_instance.push_entities_to_connec(connec_client, mapped_entities[:external_entities], organization)
57
57
  end
58
58
  end
59
59
  end
@@ -28,7 +28,7 @@ module Maestrano::Connector::Rails
28
28
  # external_entities_names[1]: [unmapped_connec_entitiy4]
29
29
  # }
30
30
  # }
31
- def connec_model_to_external_model!(connec_hash_of_entities)
31
+ def connec_model_to_external_model(connec_hash_of_entities)
32
32
  raise "Not implemented"
33
33
  end
34
34
 
@@ -45,7 +45,7 @@ module Maestrano::Connector::Rails
45
45
  # connec_entities_names[0]: [unmapped_external_entity3, unmapped_external_entity4]
46
46
  # }
47
47
  # }
48
- def external_model_to_connec_model!(external_hash_of_entities)
48
+ def external_model_to_connec_model(external_hash_of_entities)
49
49
  raise "Not implemented"
50
50
  end
51
51
 
@@ -87,10 +87,10 @@ module Maestrano::Connector::Rails
87
87
  end
88
88
 
89
89
  def consolidate_and_map_data(connec_entities, external_entities, organization, opts)
90
- external_model_to_connec_model!(external_entities)
91
- connec_model_to_external_model!(connec_entities)
90
+ modeled_external_entities = external_model_to_connec_model(external_entities)
91
+ modeled_connec_entities = connec_model_to_external_model(connec_entities)
92
92
 
93
- external_entities.each do |external_entity_name, entities_in_connec_model|
93
+ modeled_external_entities.each do |external_entity_name, entities_in_connec_model|
94
94
  entities_in_connec_model.each do |connec_entity_name, entities|
95
95
  sub_entity_instance = "Entities::SubEntities::#{external_entity_name.titleize.split.join}".constantize.new
96
96
 
@@ -134,7 +134,7 @@ module Maestrano::Connector::Rails
134
134
  end
135
135
  end
136
136
 
137
- connec_entities.each do |connec_entity_name, entities_in_external_model|
137
+ modeled_connec_entities.each do |connec_entity_name, entities_in_external_model|
138
138
  entities_in_external_model.each do |external_entity_name, entities|
139
139
  sub_entity_instance = "Entities::SubEntities::#{connec_entity_name.titleize.split.join}".constantize.new
140
140
  entities.map!{|entity|
@@ -142,6 +142,8 @@ module Maestrano::Connector::Rails
142
142
  }.compact!
143
143
  end
144
144
  end
145
+
146
+ return {connec_entities: modeled_connec_entities, external_entities: modeled_external_entities}
145
147
  end
146
148
 
147
149
  # input : {
@@ -183,10 +183,10 @@ module Maestrano::Connector::Rails::Concerns::Entity
183
183
  # * Discards entities that do not need to be pushed because they have not been updated since their last push
184
184
  # * Discards entities from one of the two source in case of conflict
185
185
  # * Maps not discarded entities and associates them with their idmap, or create one if there isn't any
186
+ # * Return a hash {connec_entities: [], external_entities: []}
186
187
  def consolidate_and_map_data(connec_entities, external_entities, organization, opts={})
187
- external_entities.map!{|entity|
188
+ mapped_external_entities = external_entities.map{|entity|
188
189
  idmap = Maestrano::Connector::Rails::IdMap.find_by(external_id: self.get_id_from_external_entity_hash(entity), external_entity: self.external_entity_name.downcase, organization_id: organization.id)
189
-
190
190
  # No idmap: creating one, nothing else to do
191
191
  unless idmap
192
192
  next {entity: self.map_to_connec(entity, organization), idmap: Maestrano::Connector::Rails::IdMap.create(external_id: self.get_id_from_external_entity_hash(entity), external_entity: self.external_entity_name.downcase, organization_id: organization.id, name: self.object_name_from_external_entity_hash(entity))}
@@ -222,11 +222,15 @@ module Maestrano::Connector::Rails::Concerns::Entity
222
222
  else
223
223
  {entity: self.map_to_connec(entity, organization), idmap: idmap}
224
224
  end
225
- }.compact!
225
+ }
226
+ mapped_external_entities.compact!
226
227
 
227
- connec_entities.map!{|entity|
228
+ mapped_connec_entities = connec_entities.map{|entity|
228
229
  self.map_to_external_with_idmap(entity, organization)
229
- }.compact!
230
+ }
231
+ mapped_connec_entities.compact!
232
+
233
+ return {connec_entities: mapped_connec_entities, external_entities: mapped_external_entities}
230
234
  end
231
235
 
232
236
 
@@ -23,17 +23,18 @@
23
23
  # # external_entities_names[1]: [unmapped_connec_entitiy4]
24
24
  # # }
25
25
  # # }
26
- # def connec_model_to_external_model!(connec_hash_of_entities)
26
+ # def connec_model_to_external_model(connec_hash_of_entities)
27
27
  # people = connec_hash_of_entities['person']
28
- # connec_hash_of_entities['person'] = { 'lead' => [], 'contact' => [] }
28
+ # modeled_connec_entities = {'person' => { 'lead' => [], 'contact' => [] }}
29
29
 
30
30
  # people.each do |person|
31
31
  # if person['is_lead']
32
- # connec_hash_of_entities['person']['lead'] << person
32
+ # modeled_connec_entities['person']['lead'] << person
33
33
  # else
34
- # connec_hash_of_entities['person']['contact'] << person
34
+ # modeled_connec_entities['person']['contact'] << person
35
35
  # end
36
36
  # end
37
+ # return modeled_connec_entities
37
38
  # end
38
39
 
39
40
  # # input : {
@@ -49,8 +50,7 @@
49
50
  # # connec_entity_names[0]: [unmapped_external_entity3, unmapped_external_entity4]
50
51
  # # }
51
52
  # # }
52
- # def external_model_to_connec_model!(external_hash_of_entities)
53
- # external_hash_of_entities['lead'] = { 'person' => external_hash_of_entities['lead'] }
54
- # external_hash_of_entities['contact'] = { 'person' => external_hash_of_entities['contact'] }
53
+ # def external_model_to_connec_model(external_hash_of_entities)
54
+ # return {'lead' => {'person' => external_hash_of_entities['lead']}, 'contact' => {'person' => external_hash_of_entities['contact']}}
55
55
  # end
56
56
  # end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: maestrano-connector-rails 0.2.12 ruby lib
5
+ # stub: maestrano-connector-rails 0.2.13 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.2.12"
9
+ s.version = "0.2.13"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -70,7 +70,7 @@ describe Maestrano::ConnecController, type: :controller do
70
70
  let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {contact_and_lead: true}) }
71
71
 
72
72
  it 'process the data and push them' do
73
- expect_any_instance_of(Entities::ContactAndLead).to receive(:consolidate_and_map_data).with({"lead"=>[entity]}, {}, organization, {})
73
+ expect_any_instance_of(Entities::ContactAndLead).to receive(:consolidate_and_map_data).with({"lead"=>[entity]}, {}, organization, {}).and_return({})
74
74
  expect_any_instance_of(Entities::ContactAndLead).to receive(:push_entities_to_external)
75
75
  subject
76
76
  end
@@ -135,7 +135,7 @@ describe Maestrano::ConnecController, type: :controller do
135
135
  let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {person: true}) }
136
136
 
137
137
  it 'process the data and push them' do
138
- expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).with([entity], [], organization, {})
138
+ expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).with([entity], [], organization, {}).and_return({})
139
139
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
140
140
  subject
141
141
  end
@@ -14,7 +14,7 @@ describe Maestrano::Connector::Rails::PushToConnecJob do
14
14
  allow_any_instance_of(Entities::Entity1).to receive(:external_entity_name).and_return('ext_entity1')
15
15
  class Entities::Entity2 < Maestrano::Connector::Rails::ComplexEntity
16
16
  end
17
- allow_any_instance_of(Entities::Entity2).to receive(:consolidate_and_map_data)
17
+ allow_any_instance_of(Entities::Entity2).to receive(:consolidate_and_map_data).and_return({})
18
18
  allow_any_instance_of(Entities::Entity2).to receive(:push_entities_to_connec)
19
19
  allow_any_instance_of(Entities::Entity2).to receive(:connec_entities_names).and_return(%w())
20
20
  allow_any_instance_of(Entities::Entity2).to receive(:external_entities_names).and_return(%w(sub ll))
@@ -81,7 +81,7 @@ describe Maestrano::Connector::Rails::PushToConnecJob do
81
81
  before { organization.update(synchronized_entities: {:"#{entity_name1}" => true, :"#{entity_name2}" => false})}
82
82
 
83
83
  it 'calls consolidate_and_map_data on the non complex entity with the right arguments' do
84
- expect_any_instance_of(Entities::Entity1).to receive(:consolidate_and_map_data).with([], [entity11, entity12], organization, {})
84
+ expect_any_instance_of(Entities::Entity1).to receive(:consolidate_and_map_data).with([], [entity11, entity12], organization, {}).and_return({})
85
85
  expect_any_instance_of(Entities::Entity1).to receive(:push_entities_to_connec)
86
86
  subject
87
87
  end
@@ -49,7 +49,6 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
49
49
  end
50
50
  end
51
51
 
52
- # def sync_entity(entity, organization, connec_client, external_client, last_synchronization, opts)
53
52
  describe 'sync_entity' do
54
53
  before {
55
54
  class Entities::Person < Maestrano::Connector::Rails::Entity
@@ -61,7 +60,7 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
61
60
  it 'calls the five methods' do
62
61
  expect_any_instance_of(Entities::Person).to receive(:get_connec_entities)
63
62
  expect_any_instance_of(Entities::Person).to receive(:get_external_entities)
64
- expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data)
63
+ expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).and_return({})
65
64
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
66
65
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_connec)
67
66
  subject.sync_entity('person', organization, nil, nil, nil, {})
@@ -10,11 +10,11 @@ describe Maestrano::Connector::Rails::ComplexEntity do
10
10
  describe 'external_entities_names' do
11
11
  it { expect{ subject.external_entities_names }.to raise_error('Not implemented') }
12
12
  end
13
- describe 'connec_model_to_external_model!' do
14
- it { expect{ subject.connec_model_to_external_model!({}) }.to raise_error('Not implemented') }
13
+ describe 'connec_model_to_external_model' do
14
+ it { expect{ subject.connec_model_to_external_model({}) }.to raise_error('Not implemented') }
15
15
  end
16
- describe 'external_model_to_connec_model!' do
17
- it { expect{ subject.external_model_to_connec_model!({}) }.to raise_error('Not implemented') }
16
+ describe 'external_model_to_connec_model' do
17
+ it { expect{ subject.external_model_to_connec_model({}) }.to raise_error('Not implemented') }
18
18
  end
19
19
  end
20
20
 
@@ -128,20 +128,20 @@ describe Maestrano::Connector::Rails::ComplexEntity do
128
128
  let(:opt) { {opt: true} }
129
129
  let(:organization) { create(:organization) }
130
130
 
131
- it 'calls external_model_to_connec_model!' do
132
- allow(subject).to receive(:connec_model_to_external_model!)
133
- expect(subject).to receive(:external_model_to_connec_model!).with({a: {}})
131
+ it 'calls external_model_to_connec_model' do
132
+ allow(subject).to receive(:connec_model_to_external_model).and_return({})
133
+ expect(subject).to receive(:external_model_to_connec_model).with({a: {}}).and_return({})
134
134
  subject.consolidate_and_map_data({}, {a: {}}, organization, opt)
135
135
  end
136
136
 
137
137
  it 'calls connec_model_to_external_model' do
138
- allow(subject).to receive(:external_model_to_connec_model!)
139
- expect(subject).to receive(:connec_model_to_external_model!).with({a: {}})
138
+ allow(subject).to receive(:external_model_to_connec_model).and_return({})
139
+ expect(subject).to receive(:connec_model_to_external_model).with({a: {}}).and_return({})
140
140
  subject.consolidate_and_map_data({a: {}}, {}, organization, opt)
141
141
  end
142
142
 
143
143
  describe 'connec_entities treatment' do
144
- #hash as it should be after connec_model_to_external_model!
144
+ #hash as it should be after connec_model_to_external_model
145
145
  let(:connec_hash) {
146
146
  {
147
147
  'sc_e1' => {'ext1' => [{'name' => 'John'}, {'name' => 'Jane'}]},
@@ -149,18 +149,18 @@ describe Maestrano::Connector::Rails::ComplexEntity do
149
149
  }
150
150
  }
151
151
  before{
152
- allow(subject).to receive(:external_model_to_connec_model!)
153
- allow(subject).to receive(:connec_model_to_external_model!)
152
+ allow(subject).to receive(:external_model_to_connec_model).and_return({})
153
+ allow(subject).to receive(:connec_model_to_external_model).and_return(connec_hash)
154
154
  }
155
155
 
156
156
  it 'calls map_to_external_with_idmap on each entity' do
157
157
  expect(subject).to receive(:map_to_external_with_idmap).exactly(4).times
158
- subject.consolidate_and_map_data(connec_hash, {}, organization, opt)
158
+ subject.consolidate_and_map_data({}, {}, organization, opt)
159
159
  end
160
160
  end
161
161
 
162
162
  describe 'external_entities treatment' do
163
- #hash as it should be after external_model_to_connec_model!
163
+ #hash as it should be after external_model_to_connec_model
164
164
  let(:id1) { '5678ttd3' }
165
165
  let(:id2) { '5678taa3' }
166
166
  let(:entity1) { {'id' => id1, 'name' => 'Robert'} }
@@ -173,9 +173,10 @@ describe Maestrano::Connector::Rails::ComplexEntity do
173
173
  'ScE2' => {'connec1' => [entity1], 'connec2' => [entity2]}
174
174
  }
175
175
  }
176
+ let(:connec_hash) { {} }
176
177
  before{
177
- allow(subject).to receive(:external_model_to_connec_model!)
178
- allow(subject).to receive(:connec_model_to_external_model!)
178
+ allow(subject).to receive(:external_model_to_connec_model).and_return(external_hash)
179
+ allow(subject).to receive(:connec_model_to_external_model).and_return(connec_hash)
179
180
  allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:get_id_from_external_entity_hash).with(entity1).and_return(id1)
180
181
  allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:get_last_update_date_from_external_entity_hash).and_return(1.minute.ago)
181
182
  allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:map_to).with('connec1', entity1, organization).and_return(mapped_entity1)
@@ -195,19 +196,20 @@ describe Maestrano::Connector::Rails::ComplexEntity do
195
196
 
196
197
  it 'creates an idmap for each entity' do
197
198
  expect{
198
- subject.consolidate_and_map_data({}, external_hash, organization, opt)
199
+ subject.consolidate_and_map_data({}, {}, organization, opt)
199
200
  }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(3)
200
201
  end
201
202
 
202
203
  it 'returns the entity with their new idmaps' do
203
- subject.consolidate_and_map_data({}, external_hash, organization, opt)
204
- expect(external_hash).to eql( {
204
+ mapped_entities = subject.consolidate_and_map_data({}, external_hash, organization, opt)
205
+ expect(mapped_entities).to eql(external_entities: {
205
206
  'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.first}]},
206
207
  'ScE2' => {
207
208
  'connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.all[1]}],
208
209
  'connec2' => [{entity: mapped_entity2, idmap: Maestrano::Connector::Rails::IdMap.last}],
209
210
  }
210
- })
211
+ },
212
+ connec_entities: {})
211
213
  end
212
214
  end
213
215
 
@@ -217,14 +219,15 @@ describe Maestrano::Connector::Rails::ComplexEntity do
217
219
  let!(:idmap22) { create(:idmap, organization: organization, external_id: id2, external_entity: 'sce2', connec_entity: 'connec2', last_push_to_connec: 1.second.ago) }
218
220
 
219
221
  it 'discards the entities' do
220
- subject.consolidate_and_map_data({}, external_hash, organization, opt)
221
- expect(external_hash).to eql( {
222
+ mapped_entities = subject.consolidate_and_map_data({}, external_hash, organization, opt)
223
+ expect(mapped_entities).to eql(external_entities: {
222
224
  'sc_e1' => {'connec1' => []},
223
225
  'ScE2' => {
224
226
  'connec1' => [],
225
227
  'connec2' => [],
226
228
  }
227
- })
229
+ },
230
+ connec_entities: {})
228
231
  end
229
232
  end
230
233
 
@@ -261,9 +264,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
261
264
  let(:opt) { {connec_preemption: true} }
262
265
 
263
266
  it 'keeps the connec entities' do
264
- subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
265
- expect(connec_hash).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
266
- expect(external_hash).to eql({
267
+ mapped_entities = subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
268
+ expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
269
+ expect(mapped_entities[:external_entities]).to eql({
267
270
  'sc_e1' => {'connec1' => []},
268
271
  'ScE2' => {
269
272
  'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
@@ -272,13 +275,14 @@ describe Maestrano::Connector::Rails::ComplexEntity do
272
275
  })
273
276
  end
274
277
  end
278
+
275
279
  context 'set to false' do
276
280
  let(:opt) { {connec_preemption: false} }
277
281
 
278
282
  it 'keeps the external entities' do
279
- subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
280
- expect(connec_hash).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
281
- expect(external_hash).to eql({
283
+ mapped_entities = subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
284
+ expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
285
+ expect(mapped_entities[:external_entities]).to eql({
282
286
  'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
283
287
  'ScE2' => {
284
288
  'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
@@ -292,9 +296,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
292
296
  context 'without option' do
293
297
  context 'with a more recently updated external entity' do
294
298
  it 'keeps the external entity' do
295
- subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
296
- expect(connec_hash).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
297
- expect(external_hash).to eql({
299
+ mapped_entities = subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
300
+ expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
301
+ expect(mapped_entities[:external_entities]).to eql({
298
302
  'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
299
303
  'ScE2' => {
300
304
  'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
@@ -308,9 +312,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
308
312
  let(:connec_hash) { {'connec1' => {'sc_e1' => [{'id' => connec_id1, 'first_name' => 'Jacob', 'updated_at' => 1.second.ago}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}} }
309
313
 
310
314
  it 'keeps the connec entities' do
311
- subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
312
- expect(connec_hash).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
313
- expect(external_hash).to eql({
315
+ mapped_entities = subject.consolidate_and_map_data(connec_hash, external_hash, organization, opt)
316
+ expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
317
+ expect(mapped_entities[:external_entities]).to eql({
314
318
  'sc_e1' => {'connec1' => []},
315
319
  'ScE2' => {
316
320
  'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
@@ -374,8 +374,8 @@ describe Maestrano::Connector::Rails::Entity do
374
374
  }
375
375
 
376
376
  it 'creates an idmap and returns the mapped entity with its new idmap' do
377
- subject.consolidate_and_map_data([], entities, organization)
378
- expect(entities).to eql([{entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last}])
377
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
378
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last}]})
379
379
  end
380
380
 
381
381
  it 'save the name in the idmap' do
@@ -388,8 +388,8 @@ describe Maestrano::Connector::Rails::Entity do
388
388
  let!(:idmap) { create(:idmap, external_entity: external_name, external_id: id, organization: organization, last_push_to_connec: 2.minute.ago) }
389
389
 
390
390
  it 'discards the entity' do
391
- subject.consolidate_and_map_data([], entities, organization)
392
- expect(entities).to eql([])
391
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
392
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
393
393
  end
394
394
  end
395
395
 
@@ -399,8 +399,8 @@ describe Maestrano::Connector::Rails::Entity do
399
399
  let!(:idmap) { create(:idmap, external_entity: external_name, external_id: id, organization: organization, last_push_to_connec: 2.day.ago) }
400
400
 
401
401
  it 'returns the mapped entity with its idmap' do
402
- subject.consolidate_and_map_data([], entities, organization)
403
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
402
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
403
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
404
404
  end
405
405
  end
406
406
 
@@ -416,16 +416,16 @@ describe Maestrano::Connector::Rails::Entity do
416
416
  context 'set to true' do
417
417
  let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.day.ago} }
418
418
  it 'discards the entity' do
419
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
420
- expect(entities).to eql([])
419
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
420
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
421
421
  end
422
422
  end
423
423
 
424
424
  context 'set to false' do
425
425
  let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.second.ago} }
426
426
  it 'returns the mapped entity with its idmap' do
427
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
428
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
427
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
428
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
429
429
  end
430
430
  end
431
431
  end
@@ -435,8 +435,8 @@ describe Maestrano::Connector::Rails::Entity do
435
435
  let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.second.ago} }
436
436
 
437
437
  it 'discards the entity' do
438
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
439
- expect(entities).to eql([])
438
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
439
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
440
440
  end
441
441
  end
442
442
 
@@ -444,8 +444,8 @@ describe Maestrano::Connector::Rails::Entity do
444
444
  let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.year.ago} }
445
445
 
446
446
  it 'returns the mapped entity with its idmap' do
447
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
448
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
447
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
448
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
449
449
  end
450
450
  end
451
451
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano-connector-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Berard