cangaroo 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/interactors/cangaroo/handle_request.rb +2 -4
- data/app/interactors/cangaroo/perform_flow.rb +9 -0
- data/app/interactors/cangaroo/validate_json_schema.rb +9 -0
- data/app/jobs/cangaroo/job.rb +15 -3
- data/lib/cangaroo/version.rb +1 -1
- data/lib/cangaroo/webhook/client.rb +5 -1
- data/spec/dummy/log/development.log +558 -0
- data/spec/dummy/log/test.log +27324 -0
- data/spec/fixtures/json_payload_connection_response.json +10 -0
- data/spec/interactors/cangaroo/handle_request_spec.rb +1 -3
- data/spec/interactors/cangaroo/perform_flow_spec.rb +17 -0
- data/spec/interactors/cangaroo/validate_json_schema_spec.rb +11 -5
- data/spec/jobs/cangaroo/job_spec.rb +18 -7
- data/spec/rails_helper.rb +8 -18
- data/spec/support/spec_helpers.rb +4 -0
- metadata +27 -8
@@ -8,9 +8,7 @@ describe Cangaroo::HandleRequest do
|
|
8
8
|
|
9
9
|
let(:interactors) do
|
10
10
|
[Cangaroo::AuthenticateConnection,
|
11
|
-
Cangaroo::
|
12
|
-
Cangaroo::CountJsonObject,
|
13
|
-
Cangaroo::PerformJobs]
|
11
|
+
Cangaroo::PerformFlow]
|
14
12
|
end
|
15
13
|
|
16
14
|
it { is_expected.to eql interactors }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe Cangaroo::PerformFlow do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
context 'organizes interactors' do
|
7
|
+
subject { described_class.organized }
|
8
|
+
|
9
|
+
let(:interactors) do
|
10
|
+
[Cangaroo::ValidateJsonSchema,
|
11
|
+
Cangaroo::CountJsonObject,
|
12
|
+
Cangaroo::PerformJobs]
|
13
|
+
end
|
14
|
+
|
15
|
+
it { is_expected.to eql interactors }
|
16
|
+
end
|
17
|
+
end
|
@@ -5,7 +5,15 @@ describe Cangaroo::ValidateJsonSchema do
|
|
5
5
|
|
6
6
|
describe '.call' do
|
7
7
|
context 'when json is well formatted' do
|
8
|
-
let(:json_body) {
|
8
|
+
let(:json_body) { parse_fixture('json_payload_ok.json') }
|
9
|
+
|
10
|
+
it 'succeeds' do
|
11
|
+
expect(context).to be_a_success
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when json is well formatted and come from a connection' do
|
16
|
+
let(:json_body) { parse_fixture('json_payload_connection_response.json') }
|
9
17
|
|
10
18
|
it 'succeeds' do
|
11
19
|
expect(context).to be_a_success
|
@@ -14,9 +22,7 @@ describe Cangaroo::ValidateJsonSchema do
|
|
14
22
|
|
15
23
|
context 'when json is not well formatted' do
|
16
24
|
describe 'with wrong main key' do
|
17
|
-
let(:json_body)
|
18
|
-
JSON.parse(load_fixture('json_payload_wrong_key.json'))
|
19
|
-
end
|
25
|
+
let(:json_body) { parse_fixture('json_payload_wrong_key.json') }
|
20
26
|
|
21
27
|
it 'fails' do
|
22
28
|
expect(context).to be_a_failure
|
@@ -32,7 +38,7 @@ describe Cangaroo::ValidateJsonSchema do
|
|
32
38
|
end
|
33
39
|
|
34
40
|
describe 'without an object id' do
|
35
|
-
let(:json_body) {
|
41
|
+
let(:json_body) { parse_fixture('json_payload_no_id.json') }
|
36
42
|
|
37
43
|
it 'fails' do
|
38
44
|
expect(context).to be_a_failure
|
@@ -9,39 +9,50 @@ module Cangaroo
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:job_class) { FakeJob }
|
12
|
-
let(:
|
12
|
+
let(:destination_connection) { create(:cangaroo_connection) }
|
13
13
|
let(:type) { 'orders' }
|
14
14
|
let(:payload) { { id: 'O123' } }
|
15
|
+
let(:connection_response) { parse_fixture('json_payload_connection_response.json') }
|
15
16
|
|
16
17
|
let(:options) do
|
17
|
-
{ connection:
|
18
|
+
{ connection: destination_connection,
|
18
19
|
type: type,
|
19
20
|
payload: payload }
|
20
21
|
end
|
21
22
|
|
22
23
|
let(:client) do
|
23
|
-
Cangaroo::Webhook::Client.new(
|
24
|
+
Cangaroo::Webhook::Client.new(destination_connection, '/webhook_path')
|
24
25
|
end
|
25
26
|
|
26
27
|
before do
|
27
|
-
client.stub(:post)
|
28
|
+
client.stub(:post).and_return(connection_response)
|
28
29
|
allow(Cangaroo::Webhook::Client).to receive(:new).and_return(client)
|
30
|
+
allow(Cangaroo::PerformFlow).to receive(:call)
|
29
31
|
end
|
30
32
|
|
31
33
|
describe '#perform' do
|
34
|
+
let(:job) { job_class.new(options) }
|
35
|
+
|
32
36
|
it 'instantiates a Cangaroo::Webhook::Client' do
|
33
37
|
expect(Cangaroo::Webhook::Client).to receive(:new)
|
34
|
-
.with(
|
38
|
+
.with(destination_connection, '/webhook_path')
|
35
39
|
.and_return(client)
|
36
|
-
|
40
|
+
job_class.perform_now(options)
|
37
41
|
end
|
38
42
|
|
39
43
|
it 'calls post on client' do
|
40
|
-
job = job_class.new(options)
|
41
44
|
job.perform
|
42
45
|
expect(client).to have_received(:post)
|
43
46
|
.with(job.transform, job.job_id, email: 'info@nebulab.it')
|
44
47
|
end
|
48
|
+
|
49
|
+
it 'restart the flow' do
|
50
|
+
job.perform
|
51
|
+
expect(Cangaroo::PerformFlow).to have_received(:call)
|
52
|
+
.with(source_connection: destination_connection,
|
53
|
+
json_body: connection_response.to_json,
|
54
|
+
jobs: Rails.configuration.cangaroo.jobs)
|
55
|
+
end
|
45
56
|
end
|
46
57
|
|
47
58
|
describe '#perform?' do
|
data/spec/rails_helper.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'simplecov'
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
|
2
4
|
SimpleCov.start 'rails' do
|
3
5
|
add_group 'Commands', 'app/commands'
|
4
6
|
end
|
7
|
+
CodeClimate::TestReporter.start
|
5
8
|
|
6
9
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
7
10
|
ENV['RAILS_ENV'] ||= 'test'
|
@@ -50,6 +53,11 @@ end
|
|
50
53
|
RSpec.configure do |config|
|
51
54
|
config.include FactoryGirl::Syntax::Methods
|
52
55
|
|
56
|
+
# whitelist codeclimate.com so test coverage can be reported
|
57
|
+
config.after(:suite) do
|
58
|
+
WebMock.disable_net_connect!(allow: 'codeclimate.com')
|
59
|
+
end
|
60
|
+
|
53
61
|
config.before(:suite) do
|
54
62
|
DatabaseCleaner.strategy = :transaction
|
55
63
|
DatabaseCleaner.clean_with(:truncation)
|
@@ -60,25 +68,7 @@ RSpec.configure do |config|
|
|
60
68
|
example.run
|
61
69
|
end
|
62
70
|
end
|
63
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
64
|
-
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
65
|
-
|
66
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
67
|
-
# examples within a transaction, remove the following line or assign false
|
68
|
-
# instead of true.
|
69
|
-
# config.use_transactional_fixtures = true
|
70
71
|
|
71
|
-
# RSpec Rails can automatically mix in different behaviours to your tests
|
72
|
-
# based on their file location, for example enabling you to call `get` and
|
73
|
-
# `post` in specs under `spec/controllers`.
|
74
|
-
#
|
75
|
-
# You can disable this behaviour by removing the line below, and instead
|
76
|
-
# explicitly tag your specs with their type, e.g.:
|
77
|
-
#
|
78
|
-
# RSpec.describe UsersController, :type => :controller do
|
79
|
-
# # ...
|
80
|
-
# end
|
81
|
-
#
|
82
72
|
# The different available types are documented in the features, such as in
|
83
73
|
# https://relishapp.com/rspec/rspec-rails/docs
|
84
74
|
config.infer_spec_type_from_file_location!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cangaroo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessio Rocco
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 0.13.7
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: codeclimate-test-reporter
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: database_cleaner
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - ">="
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: pg
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: rspec-rails
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ">="
|
@@ -138,7 +138,21 @@ dependencies:
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: rubocop
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: shoulda-matchers
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|
143
157
|
requirements:
|
144
158
|
- - ">="
|
@@ -166,7 +180,7 @@ dependencies:
|
|
166
180
|
- !ruby/object:Gem::Version
|
167
181
|
version: '0'
|
168
182
|
- !ruby/object:Gem::Dependency
|
169
|
-
name:
|
183
|
+
name: webmock
|
170
184
|
requirement: !ruby/object:Gem::Requirement
|
171
185
|
requirements:
|
172
186
|
- - ">="
|
@@ -193,6 +207,7 @@ files:
|
|
193
207
|
- app/interactors/cangaroo/authenticate_connection.rb
|
194
208
|
- app/interactors/cangaroo/count_json_object.rb
|
195
209
|
- app/interactors/cangaroo/handle_request.rb
|
210
|
+
- app/interactors/cangaroo/perform_flow.rb
|
196
211
|
- app/interactors/cangaroo/perform_jobs.rb
|
197
212
|
- app/interactors/cangaroo/validate_json_schema.rb
|
198
213
|
- app/jobs/cangaroo/job.rb
|
@@ -248,12 +263,14 @@ files:
|
|
248
263
|
- spec/dummy/public/500.html
|
249
264
|
- spec/dummy/public/favicon.ico
|
250
265
|
- spec/factories/cangaroo_connections.rb
|
266
|
+
- spec/fixtures/json_payload_connection_response.json
|
251
267
|
- spec/fixtures/json_payload_no_id.json
|
252
268
|
- spec/fixtures/json_payload_ok.json
|
253
269
|
- spec/fixtures/json_payload_wrong_key.json
|
254
270
|
- spec/interactors/cangaroo/authenticate_connection_spec.rb
|
255
271
|
- spec/interactors/cangaroo/count_json_object_spec.rb
|
256
272
|
- spec/interactors/cangaroo/handle_request_spec.rb
|
273
|
+
- spec/interactors/cangaroo/perform_flow_spec.rb
|
257
274
|
- spec/interactors/cangaroo/perform_jobs_spec.rb
|
258
275
|
- spec/interactors/cangaroo/validate_json_schema_spec.rb
|
259
276
|
- spec/jobs/cangaroo/job_spec.rb
|
@@ -329,12 +346,14 @@ test_files:
|
|
329
346
|
- spec/dummy/Rakefile
|
330
347
|
- spec/dummy/README.rdoc
|
331
348
|
- spec/factories/cangaroo_connections.rb
|
349
|
+
- spec/fixtures/json_payload_connection_response.json
|
332
350
|
- spec/fixtures/json_payload_no_id.json
|
333
351
|
- spec/fixtures/json_payload_ok.json
|
334
352
|
- spec/fixtures/json_payload_wrong_key.json
|
335
353
|
- spec/interactors/cangaroo/authenticate_connection_spec.rb
|
336
354
|
- spec/interactors/cangaroo/count_json_object_spec.rb
|
337
355
|
- spec/interactors/cangaroo/handle_request_spec.rb
|
356
|
+
- spec/interactors/cangaroo/perform_flow_spec.rb
|
338
357
|
- spec/interactors/cangaroo/perform_jobs_spec.rb
|
339
358
|
- spec/interactors/cangaroo/validate_json_schema_spec.rb
|
340
359
|
- spec/jobs/cangaroo/job_spec.rb
|