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,297 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'singleton workflow' do
4
-
5
- class Entities::SingletonIntegration < Maestrano::Connector::Rails::Entity
6
- def self.external_entity_name
7
- 'Company'
8
- end
9
-
10
- def self.connec_entity_name
11
- 'Company'
12
- end
13
-
14
- def self.mapper_class
15
- CompanyMapper
16
- end
17
-
18
- def self.object_name_from_connec_entity_hash(entity)
19
- entity['name']
20
- end
21
-
22
- def self.object_name_from_external_entity_hash(entity)
23
- entity['name']
24
- end
25
-
26
- def self.id_from_external_entity_hash(entity)
27
- entity['id']
28
- end
29
-
30
- def self.last_update_date_from_external_entity_hash(entity)
31
- entity['updated_at']
32
- end
33
-
34
- def self.singleton?
35
- true
36
- end
37
-
38
- class CompanyMapper
39
- extend HashMapper
40
- map from('id'), to('id')
41
- map from('name'), to('name')
42
- end
43
- end
44
-
45
- let(:provider) { 'provider' }
46
- let(:oauth_uid) { 'oauth uid' }
47
- let!(:organization) { create(:organization, oauth_provider: provider, oauth_uid: oauth_uid) }
48
- let(:connec_client) { Maestrano::Connec::Client[organization.tenant].new(organization.uid) }
49
- let(:external_client) { Object.new }
50
- let(:ext_comp_id) { 'ext comp id' }
51
- let(:connec_updated) { 1.hour.ago }
52
- let(:ext_updated) { 1.hour.ago }
53
- let(:company_base) {
54
- {
55
- "name" => "My awesome company",
56
- "updated_at" => connec_updated.iso8601
57
- }
58
- }
59
-
60
- let(:ext_company_base) {
61
- {
62
- 'id' => ext_comp_id,
63
- 'name' => 'My not so awesome store',
64
- 'updated_at' => ext_updated.iso8601
65
- }
66
- }
67
-
68
- let(:mapped_connec_entity) {
69
- {
70
- id: ext_comp_id,
71
- name: "My awesome company"
72
- }
73
- }
74
-
75
- let(:mapped_external_entity) {
76
- {
77
- id: [
78
- {
79
- :id=>ext_comp_id,
80
- :provider=>provider,
81
- :realm=>oauth_uid
82
- }
83
- ],
84
- name: 'My not so awesome store'
85
- }
86
- }
87
-
88
- let(:synchronized_entity) { "singleton_integration" }
89
-
90
-
91
- before {
92
- allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {company: company}.to_json, {}))
93
- allow_any_instance_of(Entities::SingletonIntegration).to receive(:get_external_entities).and_return(ext_company)
94
- allow_any_instance_of(Entities::SingletonIntegration).to receive(:update_external_entity).and_return(nil)
95
- allow(connec_client).to receive(:batch).and_return(ActionDispatch::Response.new(200, {}, {results: [{status: 200, body: {company: {id: [{provider: 'connec', id: 'some connec id'}]}}}]}.to_json, {}))
96
- allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_return([synchronized_entity])
97
- organization.reset_synchronized_entities(true)
98
- }
99
-
100
- subject { Maestrano::Connector::Rails::SynchronizationJob.new.sync_entity(synchronized_entity, organization, connec_client, external_client, nil, {}) }
101
-
102
-
103
- describe 'when no idmap' do
104
-
105
- describe 'when received both' do
106
- let(:company) { company_base.merge('id' => [{'id' => 'some connec id', 'provider' => 'connec', 'realm' => organization.uid}]) }
107
- let(:ext_company) { [ext_company_base] }
108
-
109
- context 'when connec most recent' do
110
- let(:connec_updated) { 1.second.ago }
111
- let(:batch_params) {
112
- {
113
- :sequential => true,
114
- :ops => [
115
- {
116
- :method => "put",
117
- :url => "/api/v2/#{organization.uid}/company/some connec id",
118
- :params => {
119
- :company => {
120
- id: [
121
- {
122
- :id => "ext comp id",
123
- :provider => "provider",
124
- :realm => "oauth uid"
125
- }
126
- ]
127
- }
128
- }
129
- }
130
- ]
131
- }
132
- }
133
-
134
- it 'handles the get correctly' do
135
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:consolidate_and_map_data).with([company], ext_company).and_return({connec_entities: [], external_entities: []})
136
- subject
137
- end
138
-
139
- it 'handles the idmap correctly' do
140
- expect{
141
- subject
142
- }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
143
- idmap = Maestrano::Connector::Rails::IdMap.last
144
- expect(idmap.name).to eql('My awesome company')
145
- expect(idmap.connec_entity).to eql('company')
146
- expect(idmap.external_entity).to eql('company')
147
- expect(idmap.message).to be_nil
148
- expect(idmap.external_id).to eql(ext_comp_id)
149
- expect(idmap.connec_id).to eql('some connec id')
150
- end
151
-
152
- it 'does the mapping correctly' do
153
- idmap = Entities::SingletonIntegration.create_idmap(organization_id: organization.id, external_id: ext_comp_id, connec_id: 'some connec id')
154
- allow(Entities::SingletonIntegration).to receive(:create_idmap).and_return(idmap)
155
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_external).with([{entity: {name: 'My awesome company'}, idmap: idmap, id_refs_only_connec_entity: {}}])
156
- subject
157
- end
158
-
159
- it 'send the external id to connec' do
160
- expect(connec_client).to receive(:batch).with(batch_params)
161
- subject
162
- end
163
- end
164
-
165
- context 'when external most recent' do
166
- let(:external_updated) { 1.second.ago }
167
-
168
- it 'handles the idmap correctly' do
169
- expect{
170
- subject
171
- }.to change{ Maestrano::Connector::Rails::IdMap.count }.by(1)
172
- idmap = Maestrano::Connector::Rails::IdMap.last
173
- expect(idmap.name).to eql('My not so awesome store')
174
- expect(idmap.connec_entity).to eql('company')
175
- expect(idmap.external_entity).to eql('company')
176
- expect(idmap.message).to be_nil
177
- expect(idmap.external_id).to eql(ext_comp_id)
178
- end
179
-
180
- it 'does the mapping correctly' do
181
- idmap = Entities::SingletonIntegration.create_idmap(organization_id: organization.id, external_id: ext_comp_id)
182
- allow(Entities::SingletonIntegration).to receive(:create_idmap).and_return(idmap)
183
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_connec).with([{entity: mapped_external_entity, idmap: idmap}])
184
- subject
185
- end
186
- end
187
- end
188
- end
189
-
190
-
191
-
192
- describe 'when idmap exists' do
193
- describe 'when received both' do
194
- let(:company) { company_base.merge('id' => [{'id' => ext_comp_id, 'provider' => provider, 'realm' => oauth_uid}, {'id' => 'connec-id', 'provider' => 'connec', 'realm' => 'some-realm'}]) }
195
- let(:ext_company) { [ext_company_base] }
196
- let!(:idmap) { Entities::SingletonIntegration.create_idmap(organization_id: organization.id, external_id: ext_comp_id) }
197
-
198
- context 'when connec most recent' do
199
- let(:connec_updated) { 1.second.ago }
200
-
201
- it 'handles the idmap correctly' do
202
- expect{
203
- subject
204
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
205
- idmap = Maestrano::Connector::Rails::IdMap.last
206
- expect(idmap.name).to eql('My awesome company')
207
- expect(idmap.connec_entity).to eql('company')
208
- expect(idmap.external_entity).to eql('company')
209
- expect(idmap.message).to be_nil
210
- expect(idmap.external_id).to eql(ext_comp_id)
211
- end
212
-
213
- it 'does the mapping correctly' do
214
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_external).with([{entity: mapped_connec_entity, idmap: idmap, id_refs_only_connec_entity: {}}])
215
- subject
216
- end
217
-
218
- it 'does not map the external one' do
219
- expect_any_instance_of(Entities::SingletonIntegration).to_not receive(:map_to_connec)
220
- subject
221
- end
222
- end
223
-
224
- context 'when external most recent' do
225
- let(:external_updated) { 1.second.ago }
226
-
227
- it 'handles the idmap correctly' do
228
- expect{
229
- subject
230
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
231
- idmap = Maestrano::Connector::Rails::IdMap.last
232
- expect(idmap.name).to eql('My not so awesome store')
233
- expect(idmap.connec_entity).to eql('company')
234
- expect(idmap.external_entity).to eql('company')
235
- expect(idmap.message).to be_nil
236
- expect(idmap.external_id).to eql(ext_comp_id)
237
- end
238
-
239
- it 'does the mapping correctly' do
240
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_connec).with([{entity: mapped_external_entity, idmap: idmap}])
241
- subject
242
- end
243
-
244
- it 'does not map the external one' do
245
- expect_any_instance_of(Entities::SingletonIntegration).to_not receive(:map_to_external)
246
- subject
247
- end
248
- end
249
- end
250
- end
251
-
252
- describe 'when received only connec one' do
253
- let(:company) { company_base.merge('id' => [{'id' => ext_comp_id, 'provider' => provider, 'realm' => oauth_uid}, {'id' => 'connec-id', 'provider' => 'connec', 'realm' => 'some-realm'}]) }
254
- let(:ext_company) { [] }
255
- let!(:idmap) { Entities::SingletonIntegration.create_idmap(organization_id: organization.id, external_id: ext_comp_id) }
256
-
257
- it 'handles the idmap correctly' do
258
- expect{
259
- subject
260
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
261
- idmap = Maestrano::Connector::Rails::IdMap.last
262
- expect(idmap.name).to eql('My awesome company')
263
- expect(idmap.connec_entity).to eql('company')
264
- expect(idmap.external_entity).to eql('company')
265
- expect(idmap.message).to be_nil
266
- expect(idmap.external_id).to eql(ext_comp_id)
267
- end
268
-
269
- it 'does the mapping correctly' do
270
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_external).with([{entity: mapped_connec_entity, idmap: idmap, id_refs_only_connec_entity: {}}])
271
- subject
272
- end
273
- end
274
-
275
- describe 'when receive only external one' do
276
- let(:company) { [] }
277
- let(:ext_company) { [ext_company_base] }
278
- let!(:idmap) { Entities::SingletonIntegration.create_idmap(organization_id: organization.id, external_id: ext_comp_id) }
279
-
280
- it 'handles the idmap correctly' do
281
- expect{
282
- subject
283
- }.to_not change{ Maestrano::Connector::Rails::IdMap.count }
284
- idmap = Maestrano::Connector::Rails::IdMap.last
285
- expect(idmap.name).to eql('My not so awesome store')
286
- expect(idmap.connec_entity).to eql('company')
287
- expect(idmap.external_entity).to eql('company')
288
- expect(idmap.message).to be_nil
289
- expect(idmap.external_id).to eql(ext_comp_id)
290
- end
291
-
292
- it 'does the mapping correctly' do
293
- expect_any_instance_of(Entities::SingletonIntegration).to receive(:push_entities_to_connec).with([{entity: mapped_external_entity, idmap: idmap}])
294
- subject
295
- end
296
- end
297
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::AllSynchronizationsJob do
4
- let(:organization_not_linked) { create(:organization, oauth_provider: 'salesforce', oauth_token: nil, sync_enabled: true) }
5
- let(:organization_not_active) { create(:organization, oauth_provider: 'salesforce', oauth_token: '123', sync_enabled: 0) }
6
- let(:organization_to_process) { create(:organization, oauth_provider: 'salesforce', oauth_token: '123', sync_enabled: true) }
7
-
8
- subject { Maestrano::Connector::Rails::AllSynchronizationsJob.perform_now() }
9
-
10
- # before{
11
- # organization_not_active.update(encrypted_oauth_token: Maestrano::Connector::Rails::Organization.encrypt_oauth_token('123', key: 'This is a key that is 256 bits!!', iv: 'This iv is 12 bytes or longer'))
12
- # organization_to_process.update(encrypted_oauth_token: Maestrano::Connector::Rails::Organization.encrypt_oauth_token('123', key: 'This is a key that is 256 bits!!', iv: 'This iv is 12 bytes or longer'))
13
- # }
14
-
15
- describe 'perform' do
16
- it 'does not calls sync entity' do
17
- expect(Maestrano::Connector::Rails::SynchronizationJob).to_not receive(:perform_later).with(organization_not_linked.id, anything)
18
- expect(Maestrano::Connector::Rails::SynchronizationJob).to_not receive(:perform_later).with(organization_not_active.id, anything)
19
- expect(Maestrano::Connector::Rails::SynchronizationJob).to receive(:perform_later).with(organization_to_process.id, anything)
20
-
21
- subject
22
- end
23
- end
24
- end
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::PushToConnecJob do
4
- let(:organization) { create(:organization) }
5
- let(:entity_name1) { 'entity1' }
6
- let(:entity_name2) { 'entity2' }
7
- before {
8
- class Entities::Entity1 < Maestrano::Connector::Rails::Entity
9
- end
10
- allow_any_instance_of(Entities::Entity1).to receive(:push_entities_to_connec)
11
- allow(Entities::Entity1).to receive(:external_entity_name).and_return('ext_entity1')
12
- class Entities::Entity2 < Maestrano::Connector::Rails::ComplexEntity
13
- end
14
- allow_any_instance_of(Entities::Entity2).to receive(:consolidate_and_map_data).and_return({})
15
- allow_any_instance_of(Entities::Entity2).to receive(:push_entities_to_connec)
16
- allow(Entities::Entity2).to receive(:connec_entities_names).and_return(['Connec name'])
17
- allow(Entities::Entity2).to receive(:external_entities_names).and_return(%w(Subs ll))
18
- module Entities::SubEntities end;
19
- class Entities::SubEntities::Sub < Maestrano::Connector::Rails::SubEntityBase
20
- end
21
- allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return([entity_name1, entity_name2])
22
- allow(Maestrano::Connector::Rails::Entity).to receive(:id_from_external_entity_hash).and_return('11')
23
- }
24
- let(:entity11) { {first_name: 'John'} }
25
- let(:entity12) { {first_name: 'Jane'} }
26
- let(:entity21) { {job: 'Pizza guy'} }
27
- let(:hash) { {'ext_entity1' => [entity11, entity12], 'Subs' => [entity21]} }
28
- subject { Maestrano::Connector::Rails::PushToConnecJob.perform_now(organization, hash) }
29
-
30
- describe 'with organization sync enabled set to false' do
31
- before { organization.update(sync_enabled: false, oauth_uid: 'lala') }
32
-
33
- it 'does nothing' do
34
- expect(Maestrano::Connec::Client).to_not receive(:new)
35
- subject
36
- end
37
- end
38
-
39
- describe 'with no oauth uid' do
40
- before { organization.update(sync_enabled: true, oauth_uid: nil) }
41
-
42
- it 'does nothing' do
43
- expect(Maestrano::Connec::Client).to_not receive(:new)
44
- subject
45
- end
46
- end
47
-
48
- describe 'with sync enabled and an oauth uid' do
49
- before { organization.update(sync_enabled: true, oauth_uid: 'lala') }
50
-
51
- describe 'with a non existing entity' do
52
- let(:hash) { {'lala' => []} }
53
-
54
- it 'logs a warning' do
55
- expect(Rails.logger).to receive(:warn)
56
- subject
57
- end
58
- end
59
-
60
- describe 'with entities in synchronized entities' do
61
-
62
- describe 'complex entity' do
63
- let(:hash1) { {can_push_to_connec: false, can_push_to_external: false} }
64
- let(:hash2) { {can_push_to_connec: true, can_push_to_external: true} }
65
- before { organization.update(synchronized_entities: {:"#{entity_name1}" => hash1, :"#{entity_name2}" => hash2})}
66
-
67
- it 'calls consolidate and map data on the complex entity with the right arguments' do
68
- expect_any_instance_of(Entities::Entity2).to receive(:consolidate_and_map_data).with({"Connec name" => []}, {"Subs"=>[entity21], "ll"=>[]})
69
- expect_any_instance_of(Entities::Entity2).to receive(:push_entities_to_connec)
70
- subject
71
- end
72
-
73
- it 'does not calls methods on the non complex entity' do
74
- expect_any_instance_of(Entities::Entity1).to_not receive(:consolidate_and_map_data)
75
- subject
76
- end
77
-
78
- it 'calls before and after sync' do
79
- expect_any_instance_of(Entities::Entity2).to receive(:before_sync)
80
- expect_any_instance_of(Entities::Entity2).to receive(:after_sync)
81
- subject
82
- end
83
- end
84
-
85
- describe 'non complex entity' do
86
- let(:hash1) { {can_push_to_connec: true, can_push_to_external: true} }
87
- let(:hash2) { {can_push_to_connec: false, can_push_to_external: false} }
88
- before { organization.update(synchronized_entities: {:"#{entity_name1}" => hash1, :"#{entity_name2}" => hash2})}
89
-
90
- it 'calls consolidate_and_map_data on the non complex entity with the right arguments' do
91
- expect_any_instance_of(Entities::Entity1).to receive(:consolidate_and_map_data).with([], [entity11, entity12]).and_return({})
92
- expect_any_instance_of(Entities::Entity1).to receive(:push_entities_to_connec)
93
- subject
94
- end
95
-
96
- it 'does not calls methods on the complex entity' do
97
- allow_any_instance_of(Entities::Entity1).to receive(:consolidate_and_map_data).and_return({})
98
- expect_any_instance_of(Entities::Entity2).to_not receive(:consolidate_and_map_data)
99
- subject
100
- end
101
-
102
- it 'calls before and after sync' do
103
- allow_any_instance_of(Entities::Entity1).to receive(:consolidate_and_map_data).and_return({})
104
- expect_any_instance_of(Entities::Entity1).to receive(:before_sync)
105
- expect_any_instance_of(Entities::Entity1).to receive(:after_sync)
106
- subject
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'sidekiq/testing'
3
-
4
- describe Maestrano::Connector::Rails::PushToConnecWorker do
5
- describe 'class methods' do
6
- let(:organization) { create(:organization) }
7
- subject { Maestrano::Connector::Rails::PushToConnecWorker }
8
-
9
- Sidekiq::Testing.fake!
10
- it 'perform_async add a new job' do
11
- expect_any_instance_of(Maestrano::Connector::Rails::PushToConnecJob).to receive(:perform)
12
- expect {
13
- subject.perform_async(organization.id, 2, 3)
14
- }.to change(subject.jobs, :size).by(1)
15
-
16
- expect {
17
- subject.drain
18
- }.to change(subject.jobs, :size).by(-1)
19
- end
20
-
21
- it 'raise an error if the organization can t be found' do
22
- subject.perform_async(-1, 2, 3)
23
- expect {
24
- subject.drain
25
- }.to raise_error(ActiveRecord::RecordNotFound)
26
- end
27
-
28
-
29
- describe 'unique_args' do
30
- it do
31
- entities_hash = {entity_2: [{'id': 'id2'}, {'id': 'id1'}], entity_1: [{'id': 'id4'}, {'id': nil}, {'id': 'id3'}, {'id': 'id3'}]}
32
- expect(subject.unique_args([organization.id, entities_hash])).to eq([organization.id, [:entity_1, :entity_2]])
33
- end
34
- end
35
- end
36
- end
37
-