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.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/DEVELOPER.md +1 -4
- data/Gemfile +2 -32
- data/Rakefile +6 -30
- data/app/models/maestrano/connector/rails/concerns/entity.rb +12 -0
- data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +3 -2
- data/app/models/maestrano/connector/rails/id_map.rb +1 -0
- data/app/models/maestrano/connector/rails/services/data_consolidator.rb +4 -4
- data/db/migrate/20170315032224_add_metadata_to_id_map.rb +5 -0
- data/lib/maestrano/connector/rails/version.rb +7 -0
- data/lib/maestrano_connector_rails/factories.rb +1 -0
- data/maestrano-connector-rails.gemspec +44 -308
- metadata +13 -151
- data/VERSION +0 -1
- data/spec/controllers/connec_controller_spec.rb +0 -179
- data/spec/controllers/dependancies_controller_spec.rb +0 -31
- data/spec/controllers/group_users_controller_spec.rb +0 -39
- data/spec/controllers/groups_controller_spec.rb +0 -36
- data/spec/controllers/synchronizations_controller_spec.rb +0 -211
- data/spec/controllers/version_controller_spec.rb +0 -17
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -8
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/entities/.keep +0 -0
- data/spec/dummy/app/views/home/index.html.erb +0 -1
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -39
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/maestrano.rb +0 -2
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -9
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config/settings.yml +0 -2
- data/spec/dummy/config/settings/development.yml +0 -12
- data/spec/dummy/config/settings/production.yml +0 -1
- data/spec/dummy/config/settings/test.yml +0 -12
- data/spec/dummy/config/settings/uat.yml +0 -1
- data/spec/dummy/db/schema.rb +0 -102
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/.gitkeep +0 -0
- data/spec/integration/complex_id_references_spec.rb +0 -249
- data/spec/integration/complex_naming_spec.rb +0 -192
- data/spec/integration/complex_spec.rb +0 -578
- data/spec/integration/connec_to_external_spec.rb +0 -327
- data/spec/integration/external_to_connec_spec.rb +0 -159
- data/spec/integration/id_references_spec.rb +0 -584
- data/spec/integration/singleton_spec.rb +0 -297
- data/spec/jobs/all_synchronizations_job_spec.rb +0 -24
- data/spec/jobs/push_to_connec_job_spec.rb +0 -111
- data/spec/jobs/push_to_connec_worker_spec.rb +0 -37
- data/spec/jobs/synchronization_job_spec.rb +0 -216
- data/spec/models/complex_entity_spec.rb +0 -407
- data/spec/models/connec_helper_spec.rb +0 -588
- data/spec/models/connector_logger_spec.rb +0 -26
- data/spec/models/entity_base_spec.rb +0 -20
- data/spec/models/entity_spec.rb +0 -1078
- data/spec/models/external_spec.rb +0 -27
- data/spec/models/id_map_spec.rb +0 -12
- data/spec/models/organization_spec.rb +0 -243
- data/spec/models/sub_entity_base_spec.rb +0 -155
- data/spec/models/synchronization_spec.rb +0 -106
- data/spec/models/user_organization_rel_spec.rb +0 -14
- data/spec/models/user_spec.rb +0 -15
- data/spec/routing/connec_routing_spec.rb +0 -12
- data/spec/spec_helper.rb +0 -34
- data/template/Procfile +0 -2
- data/template/application-sample.yml +0 -13
- data/template/database.yml +0 -31
- data/template/gitignore +0 -23
- data/template/maestrano.rb +0 -2
- data/template/maestrano_connector_template.rb +0 -135
- data/template/routes.rb +0 -25
- data/template/rubocop.yml +0 -55
- data/template/settings/development.yml +0 -0
- data/template/settings/production.yml +0 -0
- data/template/settings/settings.yml +0 -2
- data/template/settings/test.yml +0 -0
- data/template/settings/uat.yml +0 -0
- data/template/sidekiq.rb +0 -9
- data/template/sidekiq.yml +0 -4
- data/template/spec_helper.rb +0 -24
@@ -1,584 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'id references' do
|
4
|
-
|
5
|
-
class Entities::IdReference < Maestrano::Connector::Rails::Entity
|
6
|
-
def self.external_entity_name
|
7
|
-
'Payment'
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.connec_entity_name
|
11
|
-
'Payment'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.mapper_class
|
15
|
-
PaymentMapper
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.references
|
19
|
-
{
|
20
|
-
record_references: %w(organization_id),
|
21
|
-
id_references: %w(lines/id)
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.object_name_from_connec_entity_hash(entity)
|
26
|
-
entity['title']
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.id_from_external_entity_hash(entity)
|
30
|
-
entity['ID']
|
31
|
-
end
|
32
|
-
|
33
|
-
class LineMapper
|
34
|
-
extend HashMapper
|
35
|
-
map from('id'), to('ID')
|
36
|
-
map from('amount'), to('Price')
|
37
|
-
end
|
38
|
-
|
39
|
-
class PaymentMapper
|
40
|
-
extend HashMapper
|
41
|
-
map from('title'), to('Title')
|
42
|
-
map from('organization_id'), to('AccountId')
|
43
|
-
map from('lines'), to('Line'), using: LineMapper
|
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::Connector::Rails::ConnecHelper.get_client(organization) }
|
51
|
-
let(:external_client) { Object.new }
|
52
|
-
let(:connec_payment_id) { '1205c5e0-e18e-0133-890f-07d4de9f9781' }
|
53
|
-
let(:connec_line_id1) { '3405c5e0-e18e-0133-890f-07d4de9f9781' }
|
54
|
-
let(:connec_line_id2) { '4505c5e0-e18e-0133-890f-07d4de9f9781' }
|
55
|
-
let(:ext_payment_id) { 'ext payment id' }
|
56
|
-
let(:ext_org_id) { 'ext org id' }
|
57
|
-
let(:ext_line_id1) { 'ext line id1' }
|
58
|
-
let(:ext_line_id2) { 'ext line id2' }
|
59
|
-
|
60
|
-
let(:payment_title) { 'This is a payment' }
|
61
|
-
let(:entity_name) { 'id_reference' }
|
62
|
-
|
63
|
-
|
64
|
-
before {
|
65
|
-
allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {payments: [connec_payment]}.to_json, {}))
|
66
|
-
allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [{status: 200, body: {payments: {}}}]}.to_json, {}))
|
67
|
-
|
68
|
-
allow_any_instance_of(Entities::IdReference).to receive(:get_external_entities).and_return([])
|
69
|
-
allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_return([entity_name])
|
70
|
-
organization.reset_synchronized_entities(true)
|
71
|
-
}
|
72
|
-
|
73
|
-
subject { Maestrano::Connector::Rails::SynchronizationJob.new.sync_entity(entity_name, organization, connec_client, external_client, organization.last_synchronization_date, {}) }
|
74
|
-
|
75
|
-
describe 'a creation from connec' do
|
76
|
-
before {
|
77
|
-
allow_any_instance_of(Entities::IdReference).to receive(:create_external_entity).and_return(entity_received_after_creation)
|
78
|
-
}
|
79
|
-
|
80
|
-
let(:connec_payment) {
|
81
|
-
{
|
82
|
-
'id' => [
|
83
|
-
{
|
84
|
-
'realm' => 'org-fg4a',
|
85
|
-
'provider' => 'connec',
|
86
|
-
'id' => connec_payment_id
|
87
|
-
}
|
88
|
-
],
|
89
|
-
'title' => payment_title,
|
90
|
-
'organization_id' => [
|
91
|
-
{
|
92
|
-
'realm' => 'org-fg4a',
|
93
|
-
'provider' => 'connec',
|
94
|
-
'id' => '2305c5e0-e18e-0133-890f-07d4de9f9781'
|
95
|
-
},
|
96
|
-
{
|
97
|
-
'realm' => oauth_uid,
|
98
|
-
'provider' => provider,
|
99
|
-
'id' => ext_org_id
|
100
|
-
}
|
101
|
-
],
|
102
|
-
'lines' => lines
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
let(:lines) {
|
107
|
-
[
|
108
|
-
{
|
109
|
-
'id' => [
|
110
|
-
{
|
111
|
-
'realm' => 'org-fg4a',
|
112
|
-
'provider' => 'connec',
|
113
|
-
'id' => connec_line_id1
|
114
|
-
}
|
115
|
-
],
|
116
|
-
'amount' => 123
|
117
|
-
},
|
118
|
-
{
|
119
|
-
'id' => [
|
120
|
-
{
|
121
|
-
'realm' => 'org-fg4a',
|
122
|
-
'provider' => 'connec',
|
123
|
-
'id' => connec_line_id2
|
124
|
-
}
|
125
|
-
],
|
126
|
-
'amount' => 456
|
127
|
-
}
|
128
|
-
]
|
129
|
-
}
|
130
|
-
|
131
|
-
let(:mapped_entity) {
|
132
|
-
{
|
133
|
-
Title: payment_title,
|
134
|
-
AccountId: ext_org_id,
|
135
|
-
Line: [
|
136
|
-
{
|
137
|
-
Price: 123
|
138
|
-
},
|
139
|
-
{
|
140
|
-
Price: 456
|
141
|
-
}
|
142
|
-
]
|
143
|
-
}.with_indifferent_access
|
144
|
-
}
|
145
|
-
|
146
|
-
let(:entity_received_after_creation) {
|
147
|
-
{
|
148
|
-
'ID' => ext_payment_id,
|
149
|
-
'Title' => payment_title,
|
150
|
-
'AccountId' => ext_org_id,
|
151
|
-
'Line' => [
|
152
|
-
{
|
153
|
-
'ID' => ext_line_id1,
|
154
|
-
'Price' => 123
|
155
|
-
},
|
156
|
-
{
|
157
|
-
'ID' => ext_line_id2,
|
158
|
-
'Price' => 456
|
159
|
-
}
|
160
|
-
]
|
161
|
-
}
|
162
|
-
}
|
163
|
-
|
164
|
-
let(:batch_params) {
|
165
|
-
{
|
166
|
-
:sequential=>true,
|
167
|
-
:ops=> [
|
168
|
-
{
|
169
|
-
:method=>"put",
|
170
|
-
:url=>"/api/v2/#{organization.uid}/payments/#{connec_payment_id}",
|
171
|
-
:params=>
|
172
|
-
{
|
173
|
-
:payments=>{
|
174
|
-
'id' => [
|
175
|
-
{
|
176
|
-
'id' => ext_payment_id,
|
177
|
-
'provider' =>provider,
|
178
|
-
'realm' =>oauth_uid
|
179
|
-
}
|
180
|
-
],
|
181
|
-
'lines' => [
|
182
|
-
{
|
183
|
-
'id' => [
|
184
|
-
{
|
185
|
-
'realm' => 'org-fg4a',
|
186
|
-
'provider' => 'connec',
|
187
|
-
'id' => connec_line_id1
|
188
|
-
},
|
189
|
-
{
|
190
|
-
'realm' => oauth_uid,
|
191
|
-
'provider' => provider,
|
192
|
-
'id' => ext_line_id1
|
193
|
-
}
|
194
|
-
]
|
195
|
-
},
|
196
|
-
{
|
197
|
-
'id' => [
|
198
|
-
{
|
199
|
-
'realm' => 'org-fg4a',
|
200
|
-
'provider' => 'connec',
|
201
|
-
'id' => connec_line_id2
|
202
|
-
},
|
203
|
-
{
|
204
|
-
'realm' => oauth_uid,
|
205
|
-
'provider' => provider,
|
206
|
-
'id' => ext_line_id2
|
207
|
-
}
|
208
|
-
]
|
209
|
-
}
|
210
|
-
]
|
211
|
-
}
|
212
|
-
}
|
213
|
-
}
|
214
|
-
]
|
215
|
-
}
|
216
|
-
}
|
217
|
-
|
218
|
-
it 'handles the idmap correctly' do
|
219
|
-
expect{
|
220
|
-
subject
|
221
|
-
}.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
|
222
|
-
idmap = Maestrano::Connector::Rails::IdMap.last
|
223
|
-
expect(idmap.name).to eql(payment_title)
|
224
|
-
expect(idmap.connec_entity).to eql('payment')
|
225
|
-
expect(idmap.external_entity).to eql('payment')
|
226
|
-
expect(idmap.message).to be_nil
|
227
|
-
expect(idmap.external_id).to eql(ext_payment_id)
|
228
|
-
expect(idmap.connec_id).to eql(connec_payment_id)
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'does the mapping correctly' do
|
232
|
-
idmap = Entities::IdReference.create_idmap(organization_id: organization.id, external_id: ext_payment_id, connec_id: connec_payment_id)
|
233
|
-
allow(Entities::IdReference).to receive(:find_or_create_idmap).and_return(idmap)
|
234
|
-
expect_any_instance_of(Entities::IdReference).to receive(:push_entities_to_external).with([{entity: mapped_entity, idmap: idmap, id_refs_only_connec_entity: {'lines' => lines.map { |line| line.delete('amount'); line }}}])
|
235
|
-
subject
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'send the external ids to connec' do
|
239
|
-
expect(connec_client).to receive(:batch).with(batch_params)
|
240
|
-
subject
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe 'an update from connec with no new lines' do
|
245
|
-
before {
|
246
|
-
allow_any_instance_of(Entities::IdReference).to receive(:update_external_entity).and_return(entity_received_after_update)
|
247
|
-
}
|
248
|
-
|
249
|
-
let!(:idmap) { Entities::IdReference.create_idmap(organization_id: organization.id, external_id: ext_payment_id, connec_id: connec_payment_id) }
|
250
|
-
|
251
|
-
let(:connec_payment) {
|
252
|
-
{
|
253
|
-
'id' => [
|
254
|
-
{
|
255
|
-
'realm' => 'org-fg4a',
|
256
|
-
'provider' => 'connec',
|
257
|
-
'id' => connec_payment_id
|
258
|
-
},
|
259
|
-
{
|
260
|
-
'realm' => oauth_uid,
|
261
|
-
'provider' => provider,
|
262
|
-
'id' => ext_payment_id
|
263
|
-
}
|
264
|
-
],
|
265
|
-
'title' => payment_title,
|
266
|
-
'organization_id' => [
|
267
|
-
{
|
268
|
-
'realm' => 'org-fg4a',
|
269
|
-
'provider' => 'connec',
|
270
|
-
'id' => '2305c5e0-e18e-0133-890f-07d4de9f9781'
|
271
|
-
},
|
272
|
-
{
|
273
|
-
'realm' => oauth_uid,
|
274
|
-
'provider' => provider,
|
275
|
-
'id' => ext_org_id
|
276
|
-
}
|
277
|
-
],
|
278
|
-
'lines' => lines
|
279
|
-
}
|
280
|
-
}
|
281
|
-
|
282
|
-
let(:lines) {
|
283
|
-
[
|
284
|
-
{
|
285
|
-
'id' => [
|
286
|
-
{
|
287
|
-
'realm' => 'org-fg4a',
|
288
|
-
'provider' => 'connec',
|
289
|
-
'id' => connec_line_id1
|
290
|
-
},
|
291
|
-
{
|
292
|
-
'realm' => oauth_uid,
|
293
|
-
'provider' => provider,
|
294
|
-
'id' => ext_line_id1
|
295
|
-
}
|
296
|
-
],
|
297
|
-
'amount' => 345,
|
298
|
-
},
|
299
|
-
{
|
300
|
-
'id' => [
|
301
|
-
{
|
302
|
-
'realm' => 'org-fg4a',
|
303
|
-
'provider' => 'connec',
|
304
|
-
'id' => connec_line_id2
|
305
|
-
},
|
306
|
-
{
|
307
|
-
'realm' => oauth_uid,
|
308
|
-
'provider' => provider,
|
309
|
-
'id' => ext_line_id2
|
310
|
-
}
|
311
|
-
],
|
312
|
-
'amount' => 678
|
313
|
-
}
|
314
|
-
]
|
315
|
-
}
|
316
|
-
|
317
|
-
let(:mapped_entity) {
|
318
|
-
{
|
319
|
-
Title: payment_title,
|
320
|
-
AccountId: ext_org_id,
|
321
|
-
Line: [
|
322
|
-
{
|
323
|
-
ID: ext_line_id1,
|
324
|
-
Price: 345
|
325
|
-
},
|
326
|
-
{
|
327
|
-
ID: ext_line_id2,
|
328
|
-
Price: 678
|
329
|
-
}
|
330
|
-
]
|
331
|
-
}.with_indifferent_access
|
332
|
-
}
|
333
|
-
|
334
|
-
let(:entity_received_after_update) {
|
335
|
-
{
|
336
|
-
'ID' => ext_payment_id,
|
337
|
-
'Title' => payment_title,
|
338
|
-
'AccountId' => ext_org_id,
|
339
|
-
'Line' => [
|
340
|
-
{
|
341
|
-
'ID' => ext_line_id1,
|
342
|
-
'Price' => 123
|
343
|
-
},
|
344
|
-
{
|
345
|
-
'ID' => ext_line_id2,
|
346
|
-
'Price' => 456
|
347
|
-
}
|
348
|
-
]
|
349
|
-
}
|
350
|
-
}
|
351
|
-
|
352
|
-
it 'update the idmap' do
|
353
|
-
subject
|
354
|
-
expect(idmap.reload.message).to be_nil
|
355
|
-
expect(idmap.reload.name).to eql(payment_title)
|
356
|
-
expect(idmap.reload.last_push_to_external > 1.minute.ago).to be true
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'does the mapping correctly' do
|
360
|
-
expect_any_instance_of(Entities::IdReference).to receive(:push_entities_to_external).with([{entity: mapped_entity, idmap: idmap, id_refs_only_connec_entity: {'lines' => lines.map { |line| line.delete('amount'); line }}}])
|
361
|
-
subject
|
362
|
-
end
|
363
|
-
|
364
|
-
it 'does not send anything back to connec' do
|
365
|
-
expect(connec_client).to receive(:batch)
|
366
|
-
# TODO change when performance improvment in connec helper is done
|
367
|
-
# expect(connec_client).to_not receive(:batch)
|
368
|
-
subject
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
describe 'an update from connec with a new lines' do
|
373
|
-
before {
|
374
|
-
allow_any_instance_of(Entities::IdReference).to receive(:update_external_entity).and_return(entity_received_after_update)
|
375
|
-
}
|
376
|
-
|
377
|
-
let!(:idmap) { Entities::IdReference.create_idmap(organization_id: organization.id, external_id: ext_payment_id, connec_id: connec_payment_id) }
|
378
|
-
let(:connec_line_id3) { '8905c5e0-e18e-0133-890f-07d4de9f9781' }
|
379
|
-
let(:ext_line_id3) { 'ext line id3' }
|
380
|
-
|
381
|
-
let(:connec_payment) {
|
382
|
-
{
|
383
|
-
'id' => [
|
384
|
-
{
|
385
|
-
'realm' => 'org-fg4a',
|
386
|
-
'provider' => 'connec',
|
387
|
-
'id' => connec_payment_id
|
388
|
-
},
|
389
|
-
{
|
390
|
-
'realm' => oauth_uid,
|
391
|
-
'provider' => provider,
|
392
|
-
'id' => ext_payment_id
|
393
|
-
}
|
394
|
-
],
|
395
|
-
'title' => payment_title,
|
396
|
-
'organization_id' => [
|
397
|
-
{
|
398
|
-
'realm' => 'org-fg4a',
|
399
|
-
'provider' => 'connec',
|
400
|
-
'id' => '2305c5e0-e18e-0133-890f-07d4de9f9781'
|
401
|
-
},
|
402
|
-
{
|
403
|
-
'realm' => oauth_uid,
|
404
|
-
'provider' => provider,
|
405
|
-
'id' => ext_org_id
|
406
|
-
}
|
407
|
-
],
|
408
|
-
'lines' => lines
|
409
|
-
}
|
410
|
-
}
|
411
|
-
|
412
|
-
let(:lines) {
|
413
|
-
[
|
414
|
-
{
|
415
|
-
'id' => [
|
416
|
-
{
|
417
|
-
'realm' => 'org-fg4a',
|
418
|
-
'provider' => 'connec',
|
419
|
-
'id' => connec_line_id1
|
420
|
-
},
|
421
|
-
{
|
422
|
-
'realm' => oauth_uid,
|
423
|
-
'provider' => provider,
|
424
|
-
'id' => ext_line_id1
|
425
|
-
}
|
426
|
-
],
|
427
|
-
'amount' => 345,
|
428
|
-
},
|
429
|
-
{
|
430
|
-
'id' => [
|
431
|
-
{
|
432
|
-
'realm' => 'org-fg4a',
|
433
|
-
'provider' => 'connec',
|
434
|
-
'id' => connec_line_id2
|
435
|
-
},
|
436
|
-
{
|
437
|
-
'realm' => oauth_uid,
|
438
|
-
'provider' => provider,
|
439
|
-
'id' => ext_line_id2
|
440
|
-
}
|
441
|
-
],
|
442
|
-
'amount' => 678
|
443
|
-
},
|
444
|
-
{
|
445
|
-
'id' => [
|
446
|
-
{
|
447
|
-
'realm' => 'org-fg4a',
|
448
|
-
'provider' => 'connec',
|
449
|
-
'id' => connec_line_id3
|
450
|
-
}
|
451
|
-
],
|
452
|
-
'amount' => 999
|
453
|
-
}
|
454
|
-
]
|
455
|
-
}
|
456
|
-
|
457
|
-
let(:mapped_entity) {
|
458
|
-
{
|
459
|
-
Title: payment_title,
|
460
|
-
AccountId: ext_org_id,
|
461
|
-
Line: [
|
462
|
-
{
|
463
|
-
ID: ext_line_id1,
|
464
|
-
Price: 345
|
465
|
-
},
|
466
|
-
{
|
467
|
-
ID: ext_line_id2,
|
468
|
-
Price: 678
|
469
|
-
},
|
470
|
-
{
|
471
|
-
Price: 999
|
472
|
-
}
|
473
|
-
]
|
474
|
-
}.with_indifferent_access
|
475
|
-
}
|
476
|
-
|
477
|
-
let(:entity_received_after_update) {
|
478
|
-
{
|
479
|
-
'ID' => ext_payment_id,
|
480
|
-
'Title' => payment_title,
|
481
|
-
'AccountId' => ext_org_id,
|
482
|
-
'Line' => [
|
483
|
-
{
|
484
|
-
'ID' => ext_line_id1,
|
485
|
-
'Price' => 123
|
486
|
-
},
|
487
|
-
{
|
488
|
-
'ID' => ext_line_id2,
|
489
|
-
'Price' => 456
|
490
|
-
},
|
491
|
-
{
|
492
|
-
'ID' => ext_line_id3,
|
493
|
-
'Price' => 999
|
494
|
-
}
|
495
|
-
]
|
496
|
-
}
|
497
|
-
}
|
498
|
-
|
499
|
-
let(:batch_params) {
|
500
|
-
{
|
501
|
-
:sequential=>true,
|
502
|
-
:ops=> [
|
503
|
-
{
|
504
|
-
:method=>"put",
|
505
|
-
:url=>"/api/v2/#{organization.uid}/payments/#{connec_payment_id}",
|
506
|
-
:params=>
|
507
|
-
{
|
508
|
-
:payments=>{
|
509
|
-
'id' => [
|
510
|
-
{
|
511
|
-
'id' => ext_payment_id,
|
512
|
-
'provider' =>provider,
|
513
|
-
'realm' =>oauth_uid
|
514
|
-
}
|
515
|
-
],
|
516
|
-
'lines' => [
|
517
|
-
{
|
518
|
-
'id' => [
|
519
|
-
{
|
520
|
-
'realm' => 'org-fg4a',
|
521
|
-
'provider' => 'connec',
|
522
|
-
'id' => connec_line_id1
|
523
|
-
},
|
524
|
-
{
|
525
|
-
'realm' => oauth_uid,
|
526
|
-
'provider' => provider,
|
527
|
-
'id' => ext_line_id1
|
528
|
-
}
|
529
|
-
]
|
530
|
-
},
|
531
|
-
{
|
532
|
-
'id' => [
|
533
|
-
{
|
534
|
-
'realm' => 'org-fg4a',
|
535
|
-
'provider' => 'connec',
|
536
|
-
'id' => connec_line_id2
|
537
|
-
},
|
538
|
-
{
|
539
|
-
'realm' => oauth_uid,
|
540
|
-
'provider' => provider,
|
541
|
-
'id' => ext_line_id2
|
542
|
-
}
|
543
|
-
]
|
544
|
-
},
|
545
|
-
{
|
546
|
-
'id' => [
|
547
|
-
{
|
548
|
-
'realm' => 'org-fg4a',
|
549
|
-
'provider' => 'connec',
|
550
|
-
'id' => connec_line_id3
|
551
|
-
},
|
552
|
-
{
|
553
|
-
'realm' => oauth_uid,
|
554
|
-
'provider' => provider,
|
555
|
-
'id' => ext_line_id3
|
556
|
-
}
|
557
|
-
]
|
558
|
-
}
|
559
|
-
]
|
560
|
-
}
|
561
|
-
}
|
562
|
-
}
|
563
|
-
]
|
564
|
-
}
|
565
|
-
}
|
566
|
-
|
567
|
-
it 'update the idmap' do
|
568
|
-
subject
|
569
|
-
expect(idmap.reload.message).to be_nil
|
570
|
-
expect(idmap.reload.name).to eql(payment_title)
|
571
|
-
expect(idmap.reload.last_push_to_external > 1.minute.ago).to be true
|
572
|
-
end
|
573
|
-
|
574
|
-
it 'does the mapping correctly' do
|
575
|
-
expect_any_instance_of(Entities::IdReference).to receive(:push_entities_to_external).with([{entity: mapped_entity, idmap: idmap, id_refs_only_connec_entity: {'lines' => lines.map { |line| line.delete('amount'); line }}}])
|
576
|
-
subject
|
577
|
-
end
|
578
|
-
|
579
|
-
it 'send the external ids to connec' do
|
580
|
-
expect(connec_client).to receive(:batch).with(batch_params)
|
581
|
-
subject
|
582
|
-
end
|
583
|
-
end
|
584
|
-
end
|