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,588 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Maestrano::Connector::Rails::ConnecHelper do
|
4
|
-
subject { Maestrano::Connector::Rails::ConnecHelper }
|
5
|
-
|
6
|
-
let!(:organization) { create(:organization) }
|
7
|
-
|
8
|
-
describe 'dependancies' do
|
9
|
-
it 'returns a default hash' do
|
10
|
-
expect(subject.dependancies).to eql({
|
11
|
-
connec: '1.0',
|
12
|
-
impac: '1.0',
|
13
|
-
maestrano_hub: '1.0'
|
14
|
-
})
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'connec_version' do
|
19
|
-
let!(:organization) { create(:organization, tenant: 'production') }
|
20
|
-
let!(:organization2) { create(:organization, tenant: 'uat') }
|
21
|
-
before {
|
22
|
-
allow(Maestrano::Connec::Client['production']).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {ci_build_number: '111', ci_branch: 'v1.1', ci_commit: '111'}.to_json, {}), ActionDispatch::Response.new(200, {}, {ci_build_number: '112', ci_branch: 'v1.2', ci_commit: '112'}.to_json, {}))
|
23
|
-
}
|
24
|
-
|
25
|
-
it 'returns the connec_version' do
|
26
|
-
expect(Maestrano::Connec::Client['production']).to receive(:get).twice
|
27
|
-
expect(subject.connec_version(organization)).to eql('1.1')
|
28
|
-
expect(subject.connec_version(organization2)).to eql('1.2')
|
29
|
-
expect(subject.connec_version(organization)).to eql('1.1')
|
30
|
-
expect(subject.connec_version(organization2)).to eql('1.2')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'connec_version_lt?' do
|
35
|
-
before {
|
36
|
-
allow(subject).to receive(:connec_version).and_return('1.1.0')
|
37
|
-
}
|
38
|
-
|
39
|
-
it 'returns false if the current version is gt the parameter' do
|
40
|
-
expect(subject.connec_version_lt?('1.0.1', nil)).to be false
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns true if the current version is lt the parameter' do
|
44
|
-
expect(subject.connec_version_lt?('1.2.1', nil)).to be true
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns false if the current version is eq the parameter' do
|
48
|
-
expect(subject.connec_version_lt?('1.1.0', nil)).to be false
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns true if something fails' do
|
52
|
-
expect(subject.connec_version_lt?('lala', nil)).to be true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'unfold_references' do
|
57
|
-
let(:connec_hash) {
|
58
|
-
{
|
59
|
-
id: id,
|
60
|
-
organization_id: org_id,
|
61
|
-
lines: [
|
62
|
-
{
|
63
|
-
linked_transaction: {
|
64
|
-
id: lt1_id
|
65
|
-
}
|
66
|
-
},
|
67
|
-
{
|
68
|
-
linked_transaction: {
|
69
|
-
id: lt2_id
|
70
|
-
}
|
71
|
-
}
|
72
|
-
]
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
let(:output_hash) {
|
77
|
-
{
|
78
|
-
connec_id: connec_id,
|
79
|
-
entity: {
|
80
|
-
id: id_id,
|
81
|
-
organization_id: org_id_id,
|
82
|
-
lines: [
|
83
|
-
{
|
84
|
-
linked_transaction: {
|
85
|
-
id: lt1_id_id
|
86
|
-
}
|
87
|
-
},
|
88
|
-
{
|
89
|
-
linked_transaction: {
|
90
|
-
id: lt2_id_id
|
91
|
-
}
|
92
|
-
}
|
93
|
-
]
|
94
|
-
}.with_indifferent_access,
|
95
|
-
id_refs_only_connec_entity: {}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
let(:lt1_id_id) { 'lt1_id' }
|
99
|
-
let(:lt2_id_id) { 'lt2_id' }
|
100
|
-
let(:lt1_id) { [subject.id_hash(lt1_id_id, organization)] }
|
101
|
-
let(:lt2_id) { [subject.id_hash(lt2_id_id, organization)] }
|
102
|
-
let(:connec_id) { 'cid1' }
|
103
|
-
let(:connec_org_id) { 'cid2' }
|
104
|
-
let(:org_id_id) { 'org_id' }
|
105
|
-
|
106
|
-
context 'when all ids are here' do
|
107
|
-
let(:id_id) { 'id' }
|
108
|
-
let(:id) { [subject.id_hash(id_id, organization), {'provider' => 'connec', 'id' => connec_id}] }
|
109
|
-
let(:org_id) { [subject.id_hash(org_id_id, organization), {'provider' => 'connec', 'id' => connec_org_id}] }
|
110
|
-
|
111
|
-
it 'unfolds everything' do
|
112
|
-
expect(subject.unfold_references(connec_hash, ['organization_id', 'lines/linked_transaction/id'], organization)).to eql(output_hash)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when only id is missing' do
|
117
|
-
let(:id_id) { nil }
|
118
|
-
let(:id) { [{'provider' => 'connec', 'realm' => 'some realm', 'id' => connec_id}] }
|
119
|
-
let(:org_id) { [subject.id_hash(org_id_id, organization)] }
|
120
|
-
|
121
|
-
it 'unfolds the other refs and keep the connec_id' do
|
122
|
-
expect(subject.unfold_references(connec_hash, ['organization_id', 'lines/linked_transaction/id'], organization)).to eql(output_hash.merge(connec_id: connec_id))
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when at least one ref is missing and there is a connec id' do
|
127
|
-
let(:id_id) { nil }
|
128
|
-
let(:id) { [{'provider' => 'connec', 'realm' => 'some realm', 'id' => connec_id}] }
|
129
|
-
let(:org_id) { [{'provider' => 'connec', 'realm' => 'some realm', 'id' => connec_org_id}] }
|
130
|
-
|
131
|
-
it 'returns nil' do
|
132
|
-
expect(subject.unfold_references(connec_hash, ['organization_id', 'lines/linked_transaction/id'], organization)).to eql(output_hash.merge(entity: nil))
|
133
|
-
end
|
134
|
-
end
|
135
|
-
context 'when at least one ref is missing but there is no connec id' do
|
136
|
-
let(:id_id) { 'id' }
|
137
|
-
let(:id) { [subject.id_hash(id_id, organization), {'provider' => 'connec', 'id' => connec_id}] }
|
138
|
-
let(:org_id_id) { nil }
|
139
|
-
let(:org_id) { nil }
|
140
|
-
|
141
|
-
it 'unfold the others refs' do
|
142
|
-
expect(subject.unfold_references(connec_hash, ['organization_id', 'lines/linked_transaction/id'], organization)).to eql(output_hash)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe 'when reference field is a string instead of an array' do
|
147
|
-
let(:connec_hash) {
|
148
|
-
{
|
149
|
-
id: [subject.id_hash('123', organization), {'provider' => 'connec', 'id' => 'abcd'}],
|
150
|
-
organization_id: 'an unexpected string id',
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
let(:output_hash) {
|
155
|
-
{
|
156
|
-
connec_id: 'abcd',
|
157
|
-
entity: {
|
158
|
-
id: '123'
|
159
|
-
}.with_indifferent_access,
|
160
|
-
id_refs_only_connec_entity: {}
|
161
|
-
}
|
162
|
-
}
|
163
|
-
|
164
|
-
it 'ignores the string' do
|
165
|
-
expect(subject.unfold_references(connec_hash, ['organization_id'], organization)).to eql(output_hash)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'fold_references' do
|
171
|
-
let(:id) { 'id1' }
|
172
|
-
let(:mapped_hash) {
|
173
|
-
{
|
174
|
-
id: id,
|
175
|
-
organization_id: nil,
|
176
|
-
contact: {
|
177
|
-
id: ''
|
178
|
-
},
|
179
|
-
lines: [
|
180
|
-
{
|
181
|
-
id: 'id2'
|
182
|
-
},
|
183
|
-
{
|
184
|
-
id: 'id3'
|
185
|
-
}
|
186
|
-
]
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
let(:output_hash) {
|
191
|
-
{
|
192
|
-
"id" => [
|
193
|
-
subject.id_hash(id, organization)
|
194
|
-
],
|
195
|
-
"organization_id" => nil,
|
196
|
-
"contact" => {
|
197
|
-
"id" => ""
|
198
|
-
},
|
199
|
-
"lines" => [
|
200
|
-
{
|
201
|
-
"id" => [
|
202
|
-
subject.id_hash('id2', organization)
|
203
|
-
]
|
204
|
-
},
|
205
|
-
{
|
206
|
-
"id" => [
|
207
|
-
subject.id_hash('id3', organization)
|
208
|
-
]
|
209
|
-
}
|
210
|
-
]
|
211
|
-
}
|
212
|
-
}
|
213
|
-
|
214
|
-
it 'folds the existing refs' do
|
215
|
-
expect(subject.fold_references(mapped_hash, ['organization_id', 'contact/id', 'lines/id', 'not_here_ref'], organization)).to eql(output_hash.with_indifferent_access)
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'folds the existing refs (both id and record refs)' do
|
219
|
-
expect(subject.fold_references(mapped_hash, {record_references: %w(organization_id contact/id), id_references: %w(lines/id not_here_ref)}, organization)).to eql(output_hash.with_indifferent_access)
|
220
|
-
end
|
221
|
-
|
222
|
-
context 'when id is an integer' do
|
223
|
-
let(:id) { 1234 }
|
224
|
-
|
225
|
-
it 'folds the existing refs' do
|
226
|
-
expect(subject.fold_references(mapped_hash, ['organization_id', 'contact/id', 'lines/id', 'not_here_ref'], organization)).to eql(output_hash.with_indifferent_access)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe 'build_id_references_tree' do
|
232
|
-
let(:id_references) { %w(lines/id lines/linked/id lines/linked/id2 linked/id) }
|
233
|
-
let(:tree) {
|
234
|
-
{
|
235
|
-
"lines"=>{
|
236
|
-
"id"=>{},
|
237
|
-
"linked"=>{
|
238
|
-
"id"=>{},
|
239
|
-
"id2"=>{}
|
240
|
-
}
|
241
|
-
},
|
242
|
-
"linked"=>{
|
243
|
-
"id"=>{}
|
244
|
-
}
|
245
|
-
}
|
246
|
-
}
|
247
|
-
|
248
|
-
it 'returns the tree' do
|
249
|
-
expect(subject.build_id_references_tree(id_references)).to eql(tree)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
describe 'format_references' do
|
254
|
-
context 'when array' do
|
255
|
-
it 'transforms it to an hash' do
|
256
|
-
expect(subject.format_references([1])).to eql({record_references: [1], id_references: []})
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context 'when hash with both keys' do
|
261
|
-
let(:hash) { {id_references: [1], record_references: [2]} }
|
262
|
-
it 'returns it' do
|
263
|
-
expect(subject.format_references(hash)).to eql(hash)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
context 'when hash with only one key' do
|
268
|
-
context 'when missing id_references' do
|
269
|
-
it 'returns the completed hash' do
|
270
|
-
expect(subject.format_references(record_references: [1])).to eql({record_references: [1], id_references: []})
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context 'when missing record_references' do
|
275
|
-
it 'returns the completed hash' do
|
276
|
-
expect(subject.format_references(id_references: [1])).to eql({id_references: [1], record_references: []})
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe 'filter_connec_entity_for_id_refs' do
|
283
|
-
let(:connec_entity) {
|
284
|
-
{
|
285
|
-
id: [{"id"=>"001", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
286
|
-
name: "Brewer Supplies Ltd",
|
287
|
-
description: "We supply all things brewed\n",
|
288
|
-
lines: [
|
289
|
-
{
|
290
|
-
id: [{"id"=>"002", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
291
|
-
amount: 12,
|
292
|
-
linked: {
|
293
|
-
linked_transactions: [
|
294
|
-
{
|
295
|
-
class: 'Invoice',
|
296
|
-
id: [{"id"=>"003", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
297
|
-
id2: [{"id"=>"013", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
298
|
-
},
|
299
|
-
{
|
300
|
-
class: 'Sales order',
|
301
|
-
id: [{"id"=>"004", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
302
|
-
id2: [{"id"=>"014", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
303
|
-
}
|
304
|
-
]
|
305
|
-
}
|
306
|
-
}
|
307
|
-
],
|
308
|
-
linked_transactions: [
|
309
|
-
{
|
310
|
-
class: 'Test',
|
311
|
-
id: [{"id"=>"005", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
312
|
-
}
|
313
|
-
]
|
314
|
-
}
|
315
|
-
}
|
316
|
-
|
317
|
-
context 'with id_references' do
|
318
|
-
let(:id_references) { %w(lines/id lines/linked/linked_transactions/id lines/linked/linked_transactions/id2 linked_transactions/id) }
|
319
|
-
let(:filtered_connec_entity) {
|
320
|
-
{
|
321
|
-
lines: [
|
322
|
-
{
|
323
|
-
id: [{"id"=>"002", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
324
|
-
linked: {
|
325
|
-
linked_transactions: [
|
326
|
-
{
|
327
|
-
id: [{"id"=>"003", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
328
|
-
id2: [{"id"=>"013", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
329
|
-
},
|
330
|
-
{
|
331
|
-
id: [{"id"=>"004", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
332
|
-
id2: [{"id"=>"014", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
333
|
-
}
|
334
|
-
]
|
335
|
-
}
|
336
|
-
}
|
337
|
-
],
|
338
|
-
linked_transactions: [
|
339
|
-
{
|
340
|
-
id: [{"id"=>"005", "provider"=>"this_app", "realm"=>"sfuiy765"}],
|
341
|
-
}
|
342
|
-
]
|
343
|
-
}.with_indifferent_access
|
344
|
-
}
|
345
|
-
|
346
|
-
it 'returns the connec_entity with only the relevant keys' do
|
347
|
-
expect(subject.filter_connec_entity_for_id_refs(connec_entity, id_references)).to eql(filtered_connec_entity)
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
context 'without id_references' do
|
352
|
-
it 'returns an empty hash' do
|
353
|
-
expect(subject.filter_connec_entity_for_id_refs(connec_entity, [])).to eql({})
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe 'value from hash' do
|
359
|
-
let(:hash) {
|
360
|
-
{
|
361
|
-
lines: [
|
362
|
-
{
|
363
|
-
linked: [
|
364
|
-
{
|
365
|
-
a: {
|
366
|
-
b: [1]
|
367
|
-
}
|
368
|
-
}
|
369
|
-
]
|
370
|
-
},
|
371
|
-
{
|
372
|
-
linked: [
|
373
|
-
{
|
374
|
-
a: {
|
375
|
-
b: [2]
|
376
|
-
}
|
377
|
-
},
|
378
|
-
{
|
379
|
-
a: {
|
380
|
-
b: [3]
|
381
|
-
}
|
382
|
-
}
|
383
|
-
]
|
384
|
-
},
|
385
|
-
]
|
386
|
-
}
|
387
|
-
}
|
388
|
-
|
389
|
-
let(:path) { [:lines, 1,:linked, 0, :a, :b] }
|
390
|
-
|
391
|
-
it 'returns the value from the path' do
|
392
|
-
expect(subject.value_from_hash(hash, path)).to eql([2])
|
393
|
-
end
|
394
|
-
|
395
|
-
context 'when the path leads to nowhere' do
|
396
|
-
context 'with a wrong array' do
|
397
|
-
let(:hash) {
|
398
|
-
{
|
399
|
-
lines: [
|
400
|
-
{
|
401
|
-
linked: [
|
402
|
-
{
|
403
|
-
a: {
|
404
|
-
b: [1]
|
405
|
-
}
|
406
|
-
}
|
407
|
-
]
|
408
|
-
},
|
409
|
-
]
|
410
|
-
}
|
411
|
-
}
|
412
|
-
|
413
|
-
it 'returns nil' do
|
414
|
-
expect(subject.value_from_hash(hash, path)).to eql(nil)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
context 'with a wrong hash' do
|
419
|
-
let(:hash) {
|
420
|
-
{
|
421
|
-
lines: [
|
422
|
-
{
|
423
|
-
},
|
424
|
-
{
|
425
|
-
linked: [
|
426
|
-
{
|
427
|
-
},
|
428
|
-
{
|
429
|
-
}
|
430
|
-
]
|
431
|
-
},
|
432
|
-
]
|
433
|
-
}
|
434
|
-
}
|
435
|
-
|
436
|
-
it 'returns nil' do
|
437
|
-
expect(subject.value_from_hash(hash, path)).to eql(nil)
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
describe 'merge_id_hashes' do
|
444
|
-
let(:dist) {
|
445
|
-
{
|
446
|
-
lines: [
|
447
|
-
{
|
448
|
-
id: [{"id"=>"002", "provider"=>"connec", "realm"=>"org-123"}],
|
449
|
-
linked: {
|
450
|
-
linked_transactions: [
|
451
|
-
{
|
452
|
-
id: [{"id"=>"003", "provider"=>"connec", "realm"=>"org-123"}],
|
453
|
-
id2: [{"id"=>"013", "provider"=>"connec", "realm"=>"org-123"}],
|
454
|
-
},
|
455
|
-
{
|
456
|
-
id: [{"id"=>"004", "provider"=>"connec", "realm"=>"org-123"}],
|
457
|
-
id2: [{"id"=>"014", "provider"=>"connec", "realm"=>"org-123"}],
|
458
|
-
}
|
459
|
-
]
|
460
|
-
}
|
461
|
-
}
|
462
|
-
],
|
463
|
-
linked_transactions: [
|
464
|
-
{
|
465
|
-
id: [{"id"=>"005", "provider"=>"connec", "realm"=>"org-123"}],
|
466
|
-
}
|
467
|
-
]
|
468
|
-
}
|
469
|
-
}
|
470
|
-
|
471
|
-
let(:src) {
|
472
|
-
{
|
473
|
-
title: 'Title',
|
474
|
-
lines: [
|
475
|
-
{
|
476
|
-
amount: 123,
|
477
|
-
id: [{"id"=>"002", "provider"=>"this-app", "realm"=>"6543"}],
|
478
|
-
linked: {
|
479
|
-
linked_transactions: [
|
480
|
-
{
|
481
|
-
class: 'Invoice',
|
482
|
-
id: [{"id"=>"003", "provider"=>"this-app", "realm"=>"6543"}],
|
483
|
-
id2: [{"id"=>"013", "provider"=>"this-app", "realm"=>"6543"}],
|
484
|
-
},
|
485
|
-
{
|
486
|
-
class: 'Sales Order',
|
487
|
-
id: [{"id"=>"004", "provider"=>"this-app", "realm"=>"6543"}],
|
488
|
-
id2: [{"id"=>"014", "provider"=>"this-app", "realm"=>"6543"}],
|
489
|
-
}
|
490
|
-
]
|
491
|
-
}
|
492
|
-
}
|
493
|
-
],
|
494
|
-
linked_transactions: [
|
495
|
-
{
|
496
|
-
class: 'Payment',
|
497
|
-
id: [{"id"=>"005", "provider"=>"this-app", "realm"=>"6543"}],
|
498
|
-
}
|
499
|
-
]
|
500
|
-
}
|
501
|
-
}
|
502
|
-
|
503
|
-
let(:id_references) {
|
504
|
-
%w(lines/id lines/linked/linked_transactions/id lines/linked/linked_transactions/id2 linked_transactions/id)
|
505
|
-
}
|
506
|
-
|
507
|
-
let(:output_hash) {
|
508
|
-
{
|
509
|
-
lines: [
|
510
|
-
{
|
511
|
-
id: [{"id"=>"002", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"002", "provider"=>"this-app", "realm"=>"6543"}],
|
512
|
-
linked: {
|
513
|
-
linked_transactions: [
|
514
|
-
{
|
515
|
-
id: [{"id"=>"003", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"003", "provider"=>"this-app", "realm"=>"6543"}],
|
516
|
-
id2: [{"id"=>"013", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"013", "provider"=>"this-app", "realm"=>"6543"}],
|
517
|
-
},
|
518
|
-
{
|
519
|
-
id: [{"id"=>"004", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"004", "provider"=>"this-app", "realm"=>"6543"}],
|
520
|
-
id2: [{"id"=>"014", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"014", "provider"=>"this-app", "realm"=>"6543"}],
|
521
|
-
}
|
522
|
-
]
|
523
|
-
}
|
524
|
-
}
|
525
|
-
],
|
526
|
-
linked_transactions: [
|
527
|
-
{
|
528
|
-
id: [{"id"=>"005", "provider"=>"connec", "realm"=>"org-123"}, {"id"=>"005", "provider"=>"this-app", "realm"=>"6543"}],
|
529
|
-
}
|
530
|
-
]
|
531
|
-
}.with_indifferent_access
|
532
|
-
}
|
533
|
-
|
534
|
-
it 'merge the id from the src to the dist' do
|
535
|
-
expect(subject.merge_id_hashes(dist, src, id_references)).to eql(output_hash)
|
536
|
-
end
|
537
|
-
|
538
|
-
describe 'edge cases' do
|
539
|
-
context 'uncomplete src' do
|
540
|
-
describe 'when an id is missing in an array' do
|
541
|
-
before {
|
542
|
-
src[:linked_transactions] = []
|
543
|
-
output_hash[:linked_transactions].first.delete(:id)
|
544
|
-
}
|
545
|
-
|
546
|
-
it 'does not merge this id' do
|
547
|
-
expect(subject.merge_id_hashes(dist, src, id_references)).to eql(output_hash)
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
describe 'when an id is missing in a hash' do
|
552
|
-
before {
|
553
|
-
src[:lines].first.delete(:id)
|
554
|
-
output_hash[:lines].first.delete(:id)
|
555
|
-
}
|
556
|
-
|
557
|
-
it 'does not merge this id' do
|
558
|
-
expect(subject.merge_id_hashes(dist, src, id_references)).to eql(output_hash)
|
559
|
-
end
|
560
|
-
end
|
561
|
-
end
|
562
|
-
|
563
|
-
context 'uncomplete dist' do
|
564
|
-
describe 'when an id is missing in an array' do
|
565
|
-
before {
|
566
|
-
dist[:linked_transactions] = []
|
567
|
-
output_hash[:linked_transactions] = []
|
568
|
-
}
|
569
|
-
|
570
|
-
it 'does not merge this id' do
|
571
|
-
expect(subject.merge_id_hashes(dist, src, id_references)).to eql(output_hash)
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
describe 'when an id is missing in a hash' do
|
576
|
-
before {
|
577
|
-
dist[:lines].first.delete(:id)
|
578
|
-
output_hash[:lines].first.delete(:id)
|
579
|
-
}
|
580
|
-
|
581
|
-
it 'does not merge this id' do
|
582
|
-
expect(subject.merge_id_hashes(dist, src, id_references)).to eql(output_hash)
|
583
|
-
end
|
584
|
-
end
|
585
|
-
end
|
586
|
-
end
|
587
|
-
end
|
588
|
-
end
|