maestrano-connector-rails 2.0.2.pre.RC6 → 2.0.2.pre.RC7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/DEVELOPER.md +1 -4
  4. data/Gemfile +2 -32
  5. data/Rakefile +6 -30
  6. data/app/models/maestrano/connector/rails/concerns/entity.rb +12 -0
  7. data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +3 -2
  8. data/app/models/maestrano/connector/rails/id_map.rb +1 -0
  9. data/app/models/maestrano/connector/rails/services/data_consolidator.rb +4 -4
  10. data/db/migrate/20170315032224_add_metadata_to_id_map.rb +5 -0
  11. data/lib/maestrano/connector/rails/version.rb +7 -0
  12. data/lib/maestrano_connector_rails/factories.rb +1 -0
  13. data/maestrano-connector-rails.gemspec +44 -308
  14. metadata +13 -151
  15. data/VERSION +0 -1
  16. data/spec/controllers/connec_controller_spec.rb +0 -179
  17. data/spec/controllers/dependancies_controller_spec.rb +0 -31
  18. data/spec/controllers/group_users_controller_spec.rb +0 -39
  19. data/spec/controllers/groups_controller_spec.rb +0 -36
  20. data/spec/controllers/synchronizations_controller_spec.rb +0 -211
  21. data/spec/controllers/version_controller_spec.rb +0 -17
  22. data/spec/dummy/README.md +0 -1
  23. data/spec/dummy/Rakefile +0 -6
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  26. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -8
  28. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  30. data/spec/dummy/app/mailers/.keep +0 -0
  31. data/spec/dummy/app/models/.keep +0 -0
  32. data/spec/dummy/app/models/concerns/.keep +0 -0
  33. data/spec/dummy/app/models/entities/.keep +0 -0
  34. data/spec/dummy/app/views/home/index.html.erb +0 -1
  35. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  36. data/spec/dummy/bin/bundle +0 -3
  37. data/spec/dummy/bin/rails +0 -4
  38. data/spec/dummy/bin/rake +0 -4
  39. data/spec/dummy/bin/setup +0 -29
  40. data/spec/dummy/config.ru +0 -4
  41. data/spec/dummy/config/application.rb +0 -26
  42. data/spec/dummy/config/boot.rb +0 -5
  43. data/spec/dummy/config/database.yml +0 -25
  44. data/spec/dummy/config/environment.rb +0 -5
  45. data/spec/dummy/config/environments/development.rb +0 -41
  46. data/spec/dummy/config/environments/production.rb +0 -79
  47. data/spec/dummy/config/environments/test.rb +0 -39
  48. data/spec/dummy/config/initializers/assets.rb +0 -11
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  50. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  51. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  52. data/spec/dummy/config/initializers/inflections.rb +0 -16
  53. data/spec/dummy/config/initializers/maestrano.rb +0 -2
  54. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  55. data/spec/dummy/config/initializers/session_store.rb +0 -3
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  57. data/spec/dummy/config/locales/en.yml +0 -23
  58. data/spec/dummy/config/routes.rb +0 -9
  59. data/spec/dummy/config/secrets.yml +0 -22
  60. data/spec/dummy/config/settings.yml +0 -2
  61. data/spec/dummy/config/settings/development.yml +0 -12
  62. data/spec/dummy/config/settings/production.yml +0 -1
  63. data/spec/dummy/config/settings/test.yml +0 -12
  64. data/spec/dummy/config/settings/uat.yml +0 -1
  65. data/spec/dummy/db/schema.rb +0 -102
  66. data/spec/dummy/lib/assets/.keep +0 -0
  67. data/spec/dummy/log/.keep +0 -0
  68. data/spec/dummy/public/404.html +0 -67
  69. data/spec/dummy/public/422.html +0 -67
  70. data/spec/dummy/public/500.html +0 -66
  71. data/spec/dummy/public/favicon.ico +0 -0
  72. data/spec/dummy/tmp/cache/.gitkeep +0 -0
  73. data/spec/integration/complex_id_references_spec.rb +0 -249
  74. data/spec/integration/complex_naming_spec.rb +0 -192
  75. data/spec/integration/complex_spec.rb +0 -578
  76. data/spec/integration/connec_to_external_spec.rb +0 -327
  77. data/spec/integration/external_to_connec_spec.rb +0 -159
  78. data/spec/integration/id_references_spec.rb +0 -584
  79. data/spec/integration/singleton_spec.rb +0 -297
  80. data/spec/jobs/all_synchronizations_job_spec.rb +0 -24
  81. data/spec/jobs/push_to_connec_job_spec.rb +0 -111
  82. data/spec/jobs/push_to_connec_worker_spec.rb +0 -37
  83. data/spec/jobs/synchronization_job_spec.rb +0 -216
  84. data/spec/models/complex_entity_spec.rb +0 -407
  85. data/spec/models/connec_helper_spec.rb +0 -588
  86. data/spec/models/connector_logger_spec.rb +0 -26
  87. data/spec/models/entity_base_spec.rb +0 -20
  88. data/spec/models/entity_spec.rb +0 -1078
  89. data/spec/models/external_spec.rb +0 -27
  90. data/spec/models/id_map_spec.rb +0 -12
  91. data/spec/models/organization_spec.rb +0 -243
  92. data/spec/models/sub_entity_base_spec.rb +0 -155
  93. data/spec/models/synchronization_spec.rb +0 -106
  94. data/spec/models/user_organization_rel_spec.rb +0 -14
  95. data/spec/models/user_spec.rb +0 -15
  96. data/spec/routing/connec_routing_spec.rb +0 -12
  97. data/spec/spec_helper.rb +0 -34
  98. data/template/Procfile +0 -2
  99. data/template/application-sample.yml +0 -13
  100. data/template/database.yml +0 -31
  101. data/template/gitignore +0 -23
  102. data/template/maestrano.rb +0 -2
  103. data/template/maestrano_connector_template.rb +0 -135
  104. data/template/routes.rb +0 -25
  105. data/template/rubocop.yml +0 -55
  106. data/template/settings/development.yml +0 -0
  107. data/template/settings/production.yml +0 -0
  108. data/template/settings/settings.yml +0 -2
  109. data/template/settings/test.yml +0 -0
  110. data/template/settings/uat.yml +0 -0
  111. data/template/sidekiq.rb +0 -9
  112. data/template/sidekiq.yml +0 -4
  113. data/template/spec_helper.rb +0 -24
@@ -1,327 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'connec to the external application' do
4
-
5
- class Entities::ConnecToExternal < Maestrano::Connector::Rails::Entity
6
- def self.external_entity_name
7
- 'Contact'
8
- end
9
-
10
- def self.connec_entity_name
11
- 'Person'
12
- end
13
-
14
- def self.mapper_class
15
- PersonMapper
16
- end
17
-
18
- def self.references
19
- ['organization_id']
20
- end
21
-
22
- def self.object_name_from_connec_entity_hash(entity)
23
- entity['first_name']
24
- end
25
-
26
- def self.id_from_external_entity_hash(entity)
27
- entity['ID']
28
- end
29
-
30
- def before_sync(last_synchronization_date)
31
- @elephant_count = 8
32
- end
33
-
34
- class PersonMapper
35
- extend HashMapper
36
-
37
- after_normalize do |input, output, opts|
38
- output[:Count] = opts[:elephant_count]
39
- output
40
- end
41
-
42
- map from('organization_id'), to('AccountId')
43
- map from('first_name'), to('FirstName')
44
- end
45
- end
46
-
47
- let(:provider) { 'provider' }
48
- let(:oauth_uid) { 'oauth uid' }
49
- let!(:organization) { create(:organization, oauth_provider: provider, oauth_uid: oauth_uid) }
50
- let(:connec_client) { Maestrano::Connec::Client[organization.tenant].new(organization.uid) }
51
- let(:external_client) { Object.new }
52
- let(:ext_org_id) { 'ext org id' }
53
- let(:ext_contact_id) { 'ext contact id' }
54
- let(:ext_contact_id2) { 'ext contact id 2' }
55
- let(:connec_id1) { "23daf041-e18e-0133-7b6a-15461b913fab"}
56
- let(:connec_id2) { "11daf041-e18e-0133-7b6a-15461b913yyy"}
57
-
58
- let(:person1) {
59
- {
60
- "id" => [
61
- {
62
- "realm" => "org-fg4a",
63
- "provider" => "connec",
64
- "id" => connec_id1
65
- }
66
- ],
67
- "code" => "PE3",
68
- "status" => "ACTIVE",
69
- "first_name" => "John",
70
- "last_name" => "Doe",
71
- "organization_id" => [
72
- {
73
- "realm" => "org-fg4a",
74
- "provider" => "connec",
75
- "id" => "2305c5e0-e18e-0133-890f-07d4de9f9781"
76
- },
77
- {
78
- "realm" => oauth_uid,
79
- "provider" => provider,
80
- "id" => ext_org_id
81
- }
82
- ],
83
- "is_customer" => false,
84
- "is_supplier" => true,
85
- "is_lead" => false,
86
- "updated_at" => 2.day.ago,
87
- "created_at" => 2.day.ago
88
- }
89
- }
90
- let(:person) { person1 }
91
- let(:entity_name) { 'connec_to_external' }
92
-
93
- before do
94
- allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [person]}.to_json, {}))
95
- allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [{status: 200, body: {people: {}}}]}.to_json, {}))
96
-
97
- allow_any_instance_of(Entities::ConnecToExternal).to receive(:get_external_entities).and_return([])
98
- allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_return([entity_name])
99
- organization.reset_synchronized_entities(true)
100
- end
101
-
102
- subject { Maestrano::Connector::Rails::SynchronizationJob.new.sync_entity(entity_name, organization, connec_client, external_client, organization.last_synchronization_date, {}) }
103
-
104
- describe 'a new record created in connec with all references known' do
105
- before {
106
- allow_any_instance_of(Entities::ConnecToExternal).to receive(:create_external_entity).and_return({'ID' => ext_contact_id})
107
- }
108
-
109
- let(:mapped_entity) {
110
- {
111
- AccountId: ext_org_id,
112
- FirstName: 'John',
113
- Count: 8
114
- }
115
- }
116
-
117
- let(:batch_params) {
118
- {
119
- :sequential=>true,
120
- :ops=> [
121
- {
122
- :method=>"put",
123
- :url=>"/api/v2/#{organization.uid}/people/23daf041-e18e-0133-7b6a-15461b913fab",
124
- :params=>
125
- {
126
- :people=>{
127
- id: [
128
- {
129
- :id=>"ext contact id",
130
- :provider=>"provider",
131
- :realm=>"oauth uid"
132
- }
133
- ]
134
- }
135
- }
136
- }
137
- ]
138
- }
139
- }
140
-
141
- it 'handles the idmap correctly' do
142
- expect{
143
- subject
144
- }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
145
- idmap = Maestrano::Connector::Rails::IdMap.last
146
- expect(idmap.name).to eql('John')
147
- expect(idmap.connec_entity).to eql('person')
148
- expect(idmap.external_entity).to eql('contact')
149
- expect(idmap.message).to be_nil
150
- expect(idmap.external_id).to eql(ext_contact_id)
151
- expect(idmap.connec_id).to eql("23daf041-e18e-0133-7b6a-15461b913fab")
152
- end
153
-
154
- it 'does the mapping correctly' do
155
- idmap = Entities::ConnecToExternal.create_idmap(organization_id: organization.id, external_id: ext_contact_id, connec_id: "23daf041-e18e-0133-7b6a-15461b913fab")
156
- allow(Entities::ConnecToExternal).to receive(:find_or_create_idmap).and_return(idmap)
157
- expect_any_instance_of(Entities::ConnecToExternal).to receive(:push_entities_to_external).with([{entity: mapped_entity.with_indifferent_access, idmap: idmap, id_refs_only_connec_entity: {}}])
158
- subject
159
- end
160
-
161
- it 'send the external id to connec' do
162
- expect(connec_client).to receive(:batch).with(batch_params)
163
- subject
164
- end
165
- end
166
-
167
- describe 'an update from connec with all references known' do
168
- before {
169
- allow_any_instance_of(Entities::ConnecToExternal).to receive(:update_external_entity).and_return(nil)
170
- }
171
- let(:person) { person1.merge('first_name' => 'Jane', 'id' => person1['id'] << {'id' => ext_contact_id, 'provider' => provider, 'realm' => oauth_uid}) }
172
- let!(:idmap) { Entities::ConnecToExternal.create_idmap(organization_id: organization.id, external_id: ext_contact_id, connec_id: "23daf041-e18e-0133-7b6a-15461b913fab") }
173
-
174
- let(:mapped_entity) {
175
- {
176
- AccountId: ext_org_id,
177
- FirstName: 'Jane',
178
- Count: 8
179
- }
180
- }
181
-
182
- it 'update the idmap' do
183
- subject
184
- expect(idmap.reload.message).to be_nil
185
- expect(idmap.reload.name).to eql('Jane')
186
- expect(idmap.reload.last_push_to_external > 1.minute.ago).to be true
187
- end
188
-
189
- it 'does the mapping correctly' do
190
- expect_any_instance_of(Entities::ConnecToExternal).to receive(:push_entities_to_external).with([{entity: mapped_entity.with_indifferent_access, idmap: idmap, id_refs_only_connec_entity: {}}])
191
- subject
192
- end
193
-
194
- it 'does not send the external id to connec' do
195
- expect(connec_client).to_not receive(:batch)
196
- subject
197
- end
198
- end
199
-
200
- describe 'a creation from connec with references missing' do
201
- let(:person) { person1.merge("organization_id" => [{"realm"=>"org-fg4a", "provider"=>"connec", "id"=>"2305c5e0-e18e-0133-890f-07d4de9f9781"}]) }
202
-
203
- it 'pushes nothing and creates no idmap' do
204
- expect_any_instance_of(Entities::ConnecToExternal).to_not receive(:create_external_entity)
205
- expect_any_instance_of(Entities::ConnecToExternal).to_not receive(:update_external_entity)
206
- expect{
207
- subject
208
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
209
- end
210
- end
211
-
212
- describe 'an entity from before the date filtering limit' do
213
- let(:date_filtering_limit) { 2.minute.ago }
214
- before {
215
- organization.update(date_filtering_limit: date_filtering_limit)
216
- }
217
-
218
- it 'calls get_connec_entities with a date even if there is no last sync' do
219
- expect_any_instance_of(Entities::ConnecToExternal).to receive(:get_connec_entities).with(date_filtering_limit).and_return([])
220
- subject
221
- end
222
-
223
- it 'pushes nothing and creates no idmap' do
224
- expect_any_instance_of(Entities::ConnecToExternal).to_not receive(:create_external_entity)
225
- expect_any_instance_of(Entities::ConnecToExternal).to_not receive(:update_external_entity)
226
- expect{
227
- subject
228
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
229
- end
230
- end
231
-
232
- describe 'a creation from connec where the creation_only_mapper has to be used' do
233
- #idmap.last_push_to_external is nil
234
- let(:entity_name) { 'connec_to_external_missing_field' }
235
- before do
236
- allow_any_instance_of(Entities::ConnecToExternalMissingField).to receive(:get_external_entities).and_return([])
237
- allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_return([entity_name])
238
- organization.reset_synchronized_entities(true)
239
- end
240
-
241
- subject { Maestrano::Connector::Rails::SynchronizationJob.new.sync_entity(entity_name, organization, connec_client, external_client, organization.last_synchronization_date, {}) }
242
-
243
- class Entities::ConnecToExternalMissingField < Entities::ConnecToExternal
244
-
245
- def self.creation_mapper_class
246
- CreationPersonMapper
247
- end
248
-
249
- class CreationPersonMapper < PersonMapper
250
- after_normalize do |input, output|
251
- output[:missing_connec_field] = "Default"
252
- output
253
- end
254
- end
255
- end
256
-
257
- describe 'a new record created in connec with all references known' do
258
- before {
259
- allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [person2]}.to_json, {}))
260
- allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [{status: 200, body: {people: {}}}]}.to_json, {}))
261
-
262
- allow_any_instance_of(Entities::ConnecToExternalMissingField).to receive(:create_external_entity).and_return({'ID' => ext_contact_id2})
263
- }
264
-
265
- let(:person2) { person1.merge('first_name' => 'Jack', 'id' => [{"realm" => "org-fg4a", "provider" => "connec", "id" => connec_id2 }]) }
266
-
267
- let(:mapped_entity_missing_field) {
268
- {
269
- AccountId: ext_org_id,
270
- FirstName: 'Jack',
271
- missing_connec_field: "Default",
272
- Count: 8
273
- }
274
- }
275
-
276
- let(:batch_params) {
277
- {
278
- :sequential=>true,
279
- :ops=> [
280
- {
281
- :method=>"put",
282
- :url=>"/api/v2/#{organization.uid}/people/11daf041-e18e-0133-7b6a-15461b913yyy",
283
- :params=>
284
- {
285
- :people=>{
286
- id: [
287
- {
288
- :id=>"ext contact id 2",
289
- :provider=>"provider",
290
- :realm=>"oauth uid"
291
- }
292
- ]
293
- }
294
- }
295
- }
296
- ]
297
- }
298
- }
299
-
300
- it 'handles the idmap correctly' do
301
- expect{
302
- subject
303
- }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
304
- idmap = Maestrano::Connector::Rails::IdMap.last
305
- expect(idmap.name).to eql('Jack')
306
- expect(idmap.connec_entity).to eql('person')
307
- expect(idmap.external_entity).to eql('contact')
308
- expect(idmap.message).to be_nil
309
- expect(idmap.external_id).to eql(ext_contact_id2)
310
- expect(idmap.connec_id).to eql("11daf041-e18e-0133-7b6a-15461b913yyy")
311
- end
312
-
313
- it 'does the mapping correctly' do
314
- idmap = Entities::ConnecToExternalMissingField.create_idmap(organization_id: organization.id, external_id: ext_contact_id, connec_id: "23daf041-e18e-0133-7b6a-15461b913yyy")
315
- allow(Entities::ConnecToExternalMissingField).to receive(:find_or_create_idmap).and_return(idmap)
316
- expect_any_instance_of(Entities::ConnecToExternalMissingField).to receive(:push_entities_to_external).with([{entity: mapped_entity_missing_field.with_indifferent_access, idmap: idmap, id_refs_only_connec_entity: {}}])
317
- subject
318
- end
319
-
320
- it 'send the external id to connec' do
321
- expect(connec_client).to receive(:batch).with(batch_params)
322
- subject
323
- end
324
- end
325
-
326
- end
327
- end
@@ -1,159 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'external application to connec' do
4
-
5
- class Entities::ExternalToConnec < Maestrano::Connector::Rails::Entity
6
- def self.external_entity_name
7
- 'Contact'
8
- end
9
-
10
- def self.connec_entity_name
11
- 'Person'
12
- end
13
-
14
- def self.mapper_class
15
- PersonMapper
16
- end
17
-
18
- def self.references
19
- ['organization_id']
20
- end
21
-
22
- def self.object_name_from_external_entity_hash(entity)
23
- entity['FirstName']
24
- end
25
-
26
- def self.id_from_external_entity_hash(entity)
27
- entity['Id']
28
- end
29
-
30
- class PersonMapper
31
- extend HashMapper
32
- map from('organization_id'), to('AccountId')
33
- map from('first_name'), to('FirstName')
34
- end
35
- end
36
-
37
- let(:provider) { 'provider' }
38
- let(:oauth_uid) { 'oauth uid' }
39
- let!(:organization) { create(:organization, oauth_provider: provider, oauth_uid: oauth_uid) }
40
- let(:connec_client) { Maestrano::Connec::Client[organization.tenant].new(organization.uid) }
41
- let(:external_client) { Object.new }
42
-
43
- let(:ext_org_id) { 'ext org id' }
44
- let(:ext_contact_id) { 'ext contact id' }
45
-
46
- let(:contact1) {
47
- {
48
- 'Id' => ext_contact_id,
49
- 'FirstName' => 'Jack',
50
- 'AccountId' => ext_org_id
51
- }
52
- }
53
- let(:contact) { contact1 }
54
-
55
- let(:mapped_entity1) {
56
- {
57
- id: [
58
- {
59
- provider: provider,
60
- realm: oauth_uid,
61
- id: ext_contact_id
62
- }
63
- ],
64
- first_name: 'Jack',
65
- organization_id: [
66
- {
67
- provider: provider,
68
- realm: oauth_uid,
69
- id: ext_org_id
70
- }
71
- ]
72
- }
73
- }
74
- let(:mapped_entity) { mapped_entity1 }
75
-
76
- let(:batch_call) {
77
- {
78
- :sequential => true,
79
- :ops => [
80
- {
81
- :method => "post",
82
- :url => "/api/v2/#{organization.uid}/people/",
83
- :params => {
84
- :people => mapped_entity
85
- }
86
- }
87
- ]
88
- }
89
- }
90
-
91
- let(:entity_name) { 'external_to_connec' }
92
-
93
- before {
94
- allow_any_instance_of(Entities::ExternalToConnec).to receive(:get_connec_entities).and_return([])
95
- allow_any_instance_of(Entities::ExternalToConnec).to receive(:get_external_entities).and_return([contact])
96
- allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_return([entity_name])
97
- organization.reset_synchronized_entities(true)
98
- }
99
-
100
- subject { Maestrano::Connector::Rails::SynchronizationJob.new.sync_entity(entity_name, organization, connec_client, external_client, nil, {}) }
101
-
102
- describe 'creating an record in connec' do
103
- before {
104
- allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(201, {}, {results: [{status: 201, body: {people: {id: [{provider: 'connec', id: 'connec-id'}]}}}]}.to_json, {}))
105
- }
106
-
107
- it 'handles the idmap correctly' do
108
- expect{
109
- subject
110
- }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
111
- idmap = Maestrano::Connector::Rails::IdMap.last
112
- expect(idmap.name).to eql('Jack')
113
- expect(idmap.connec_entity).to eql('person')
114
- expect(idmap.external_entity).to eql('contact')
115
- expect(idmap.message).to be_nil
116
- expect(idmap.external_id).to eql(ext_contact_id)
117
- end
118
-
119
- it 'does the mapping correctly' do
120
- idmap = Entities::ExternalToConnec.create_idmap(organization_id: organization.id, external_id: ext_contact_id)
121
- allow(Entities::ExternalToConnec).to receive(:create_idmap).and_return(idmap)
122
- expect_any_instance_of(Entities::ExternalToConnec).to receive(:push_entities_to_connec).with([{entity: mapped_entity, idmap: idmap}])
123
- subject
124
- end
125
-
126
- it 'does the right call to connec' do
127
- expect(connec_client).to receive(:batch).with(batch_call)
128
- subject
129
- expect(Maestrano::Connector::Rails::IdMap.last.connec_id).to eql('connec-id')
130
- end
131
- end
132
-
133
- describe 'updating an record in connec' do
134
- before {
135
- allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(201, {}, {results: [{status: 201, body: {people: {id: [{provider: 'connec', id: 'connec-id'}]}}}]}.to_json, {}))
136
- }
137
- let(:contact) { contact1.merge('FirstName' => 'Jacky') }
138
- let(:mapped_entity) { mapped_entity1.merge(first_name: 'Jacky') }
139
- let!(:idmap) { Entities::ExternalToConnec.create_idmap(organization_id: organization.id, external_id: ext_contact_id, connec_id: 'connec-id') }
140
-
141
- it 'handles the idmap correctly' do
142
- expect{
143
- subject
144
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
145
- expect(idmap.reload.name).to eql('Jacky')
146
- expect(idmap.reload.message).to be_nil
147
- end
148
-
149
- it 'does the mapping correctly' do
150
- expect_any_instance_of(Entities::ExternalToConnec).to receive(:push_entities_to_connec).with([{entity: mapped_entity, idmap: idmap}])
151
- subject
152
- end
153
-
154
- it 'does the right call to connec' do
155
- expect(connec_client).to receive(:batch).with(batch_call)
156
- subject
157
- end
158
- end
159
- end