solidus_bactracs 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gem_release.yml +2 -2
- data/.github/CODEOWNERS +54 -0
- data/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +3 -0
- data/.github/workflows/release.yml +50 -0
- data/.gitignore +0 -2
- data/.rubocop_todo.yml +3 -3
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +7 -1
- data/PULL_REQUEST_TEMPLATE.md +3 -0
- data/README.md +5 -5
- data/app/assets/javascripts/spree/backend/{solidus_backtracs.js → solidus_bactracs.js} +0 -0
- data/app/assets/javascripts/spree/frontend/{solidus_backtracs.js → solidus_bactracs.js} +0 -0
- data/app/assets/stylesheets/spree/backend/{solidus_backtracs.css → solidus_bactracs.css} +0 -0
- data/app/assets/stylesheets/spree/frontend/{solidus_backtracs.css → solidus_bactracs.css} +0 -0
- data/app/controllers/spree/{backtracs_controller.rb → bactracs_controller.rb} +9 -9
- data/app/decorators/models/{solidus_backtracs → solidus_bactracs}/spree/shipment_decorator.rb +5 -5
- data/app/helpers/{solidus_backtracs → solidus_bactracs}/export_helper.rb +2 -2
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/schedule_shipment_syncs_job.rb +7 -7
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipment_job.rb +1 -1
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipments_job.rb +3 -3
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/between_query.rb +1 -1
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/exportable_query.rb +3 -3
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/pending_api_sync_query.rb +6 -6
- data/app/views/spree/{backtracs → bactracs}/export.xml.builder +5 -5
- data/bin/console +1 -1
- data/bin/rails-engine +1 -1
- data/bin/sandbox +1 -1
- data/config/routes.rb +2 -2
- data/db/migrate/{20210220093010_add_backtracs_api_sync_fields.rb → 20210220093010_add_bactracs_api_sync_fields.rb} +2 -2
- data/lib/generators/{solidus_backtracs → solidus_bactracs}/install/install_generator.rb +3 -3
- data/lib/generators/{solidus_backtracs → solidus_bactracs}/install/templates/initializer.rb +42 -12
- data/lib/solidus_backtracs/version.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/api/batch_syncer.rb +5 -5
- data/lib/{solidus_backtracs → solidus_bactracs}/api/client.rb +4 -4
- data/lib/{solidus_backtracs → solidus_bactracs}/api/rate_limited_error.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/api/request_error.rb +1 -1
- data/lib/solidus_bactracs/api/request_runner.rb +135 -0
- data/lib/{solidus_backtracs → solidus_bactracs}/api/shipment_serializer.rb +28 -27
- data/lib/{solidus_backtracs → solidus_bactracs}/api/threshold_verifier.rb +6 -6
- data/lib/{solidus_backtracs → solidus_bactracs}/configuration.rb +4 -4
- data/lib/{solidus_backtracs → solidus_bactracs}/engine.rb +2 -2
- data/lib/{solidus_backtracs → solidus_bactracs}/errors.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/shipment_notice.rb +2 -2
- data/lib/{solidus_backtracs → solidus_bactracs}/testing_support/factories.rb +0 -0
- data/lib/solidus_bactracs/version.rb +5 -0
- data/lib/solidus_bactracs.rb +16 -0
- data/solidus_bactracs.gemspec +3 -2
- data/spec/controllers/spree/{backtracs_controller_spec.rb → bactracs_controller_spec.rb} +9 -9
- data/spec/fixtures/{backtracs_xml_schema.xsd → bactracs_xml_schema.xsd} +0 -0
- data/spec/jobs/{solidus_backtracs → solidus_bactracs}/api/schedule_shipment_syncs_job_spec.rb +5 -5
- data/spec/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipments_job_spec.rb +10 -10
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/batch_syncer_spec.rb +28 -28
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/client_spec.rb +10 -10
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/rate_limited_error_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/request_error_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/request_runner_spec.rb +3 -3
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/shipment_serializer_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/threshold_verifier_spec.rb +9 -9
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/shipment_notice_spec.rb +4 -4
- data/spec/lib/solidus_bactracs_spec.rb +9 -0
- data/spec/models/spree/shipment_spec.rb +2 -2
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/between_query_spec.rb +1 -1
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/exportable_query_spec.rb +1 -1
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/pending_api_sync_query_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -2
- data/spec/support/configuration_helper.rb +1 -1
- metadata +72 -64
- data/lib/solidus_backtracs/api/request_runner.rb +0 -109
- data/lib/solidus_backtracs.rb +0 -16
- data/spec/lib/solidus_backtracs_spec.rb +0 -9
data/spec/jobs/{solidus_backtracs → solidus_bactracs}/api/schedule_shipment_syncs_job_spec.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe
|
3
|
+
RSpec.describe SolidusBactracs::Api::ScheduleShipmentSyncsJob do
|
4
4
|
it 'schedules the shipment sync in batches' do
|
5
5
|
stub_configuration(api_batch_size: 2)
|
6
6
|
shipments = create_list(:shipment, 3)
|
@@ -10,20 +10,20 @@ RSpec.describe SolidusBacktracs::Api::ScheduleShipmentSyncsJob do
|
|
10
10
|
.and_yield(shipments[0..1])
|
11
11
|
.and_yield([shipments.last])
|
12
12
|
end
|
13
|
-
allow(
|
13
|
+
allow(SolidusBactracs::Shipment::PendingApiSyncQuery).to receive(:apply)
|
14
14
|
.and_return(relation)
|
15
15
|
|
16
16
|
described_class.perform_now
|
17
17
|
|
18
|
-
expect(
|
19
|
-
expect(
|
18
|
+
expect(SolidusBactracs::Api::SyncShipmentsJob).to have_been_enqueued.with(shipments[0..1])
|
19
|
+
expect(SolidusBactracs::Api::SyncShipmentsJob).to have_been_enqueued.with([shipments.last])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'reports any errors to the handler' do
|
23
23
|
error_handler = instance_spy('Proc')
|
24
24
|
stub_configuration(error_handler: error_handler)
|
25
25
|
error = RuntimeError.new('Something went wrong')
|
26
|
-
allow(
|
26
|
+
allow(SolidusBactracs::Shipment::PendingApiSyncQuery).to receive(:apply).and_raise(error)
|
27
27
|
|
28
28
|
described_class.perform_now
|
29
29
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe
|
3
|
+
RSpec.describe SolidusBactracs::Api::SyncShipmentsJob do
|
4
4
|
include ActiveSupport::Testing::TimeHelpers
|
5
5
|
|
6
6
|
context 'when a shipment is syncable' do
|
@@ -20,7 +20,7 @@ RSpec.describe SolidusBacktracs::Api::SyncShipmentsJob do
|
|
20
20
|
it 'retries intelligently when hitting a rate limit' do
|
21
21
|
freeze_time do
|
22
22
|
shipment = build_stubbed(:shipment) { |s| stub_syncability(s, true) }
|
23
|
-
stub_failing_batch_syncer(
|
23
|
+
stub_failing_batch_syncer(SolidusBactracs::Api::RateLimitedError.new(
|
24
24
|
response_code: 429,
|
25
25
|
response_headers: { 'X-Rate-Limit-Reset' => 30 },
|
26
26
|
response_body: '{"message":"Too Many Requests"}',
|
@@ -39,7 +39,7 @@ RSpec.describe SolidusBacktracs::Api::SyncShipmentsJob do
|
|
39
39
|
error_handler = instance_spy('Proc')
|
40
40
|
stub_configuration(error_handler: error_handler)
|
41
41
|
shipment = build_stubbed(:shipment) { |s| stub_syncability(s, true) }
|
42
|
-
error =
|
42
|
+
error = SolidusBactracs::Api::RequestError.new(
|
43
43
|
response_code: 500,
|
44
44
|
response_headers: {},
|
45
45
|
response_body: '{"message":"Internal Server Error"}',
|
@@ -64,7 +64,7 @@ RSpec.describe SolidusBacktracs::Api::SyncShipmentsJob do
|
|
64
64
|
expect(batch_syncer).not_to have_received(:call)
|
65
65
|
end
|
66
66
|
|
67
|
-
it 'fires a
|
67
|
+
it 'fires a solidus_bactracs.api.sync_skipped event' do
|
68
68
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
69
69
|
shipment = build_stubbed(:shipment) { |s| stub_syncability(s, false) }
|
70
70
|
stub_successful_batch_syncer
|
@@ -72,7 +72,7 @@ RSpec.describe SolidusBacktracs::Api::SyncShipmentsJob do
|
|
72
72
|
described_class.perform_now([shipment])
|
73
73
|
|
74
74
|
expect(Spree::Event).to have_received(:fire).with(
|
75
|
-
'
|
75
|
+
'solidus_bactracs.api.sync_skipped',
|
76
76
|
shipment: shipment,
|
77
77
|
)
|
78
78
|
end
|
@@ -81,21 +81,21 @@ RSpec.describe SolidusBacktracs::Api::SyncShipmentsJob do
|
|
81
81
|
private
|
82
82
|
|
83
83
|
def stub_successful_batch_syncer
|
84
|
-
instance_spy(
|
85
|
-
allow(
|
84
|
+
instance_spy(SolidusBactracs::Api::BatchSyncer).tap do |batch_syncer|
|
85
|
+
allow(SolidusBactracs::Api::BatchSyncer).to receive(:from_config).and_return(batch_syncer)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def stub_failing_batch_syncer(error)
|
90
|
-
instance_double(
|
91
|
-
allow(
|
90
|
+
instance_double(SolidusBactracs::Api::BatchSyncer).tap do |batch_syncer|
|
91
|
+
allow(SolidusBactracs::Api::BatchSyncer).to receive(:from_config).and_return(batch_syncer)
|
92
92
|
|
93
93
|
allow(batch_syncer).to receive(:call).and_raise(error)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
def stub_syncability(shipment, result)
|
98
|
-
allow(
|
98
|
+
allow(SolidusBactracs::Api::ThresholdVerifier).to receive(:call)
|
99
99
|
.with(shipment)
|
100
100
|
.and_return(result)
|
101
101
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Api::BatchSyncer do
|
2
2
|
include ActiveSupport::Testing::TimeHelpers
|
3
3
|
|
4
4
|
describe '.from_config' do
|
5
5
|
it 'creates a syncer with the configured API client' do
|
6
|
-
client = instance_double(
|
7
|
-
allow(
|
6
|
+
client = instance_double(SolidusBactracs::Api::Client)
|
7
|
+
allow(SolidusBactracs::Api::Client).to receive(:from_config).and_return(client)
|
8
8
|
shipment_matcher = -> {}
|
9
9
|
stub_configuration(api_shipment_matcher: shipment_matcher)
|
10
10
|
|
@@ -20,10 +20,10 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
20
20
|
describe '#call' do
|
21
21
|
context 'when the API call is successful' do
|
22
22
|
context 'when the sync operation succeeded' do
|
23
|
-
it 'updates the
|
23
|
+
it 'updates the bactracs data on the shipment' do
|
24
24
|
freeze_time do
|
25
25
|
shipment = instance_spy('Spree::Shipment', number: 'H123456')
|
26
|
-
api_client = instance_double(
|
26
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
27
27
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_return(
|
28
28
|
{
|
29
29
|
'results' => [
|
@@ -40,15 +40,15 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
40
40
|
build_batch_syncer(client: api_client).call([shipment])
|
41
41
|
|
42
42
|
expect(shipment).to have_received(:update_columns).with(
|
43
|
-
|
43
|
+
bactracs_synced_at: Time.zone.now,
|
44
44
|
)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
it 'emits a
|
48
|
+
it 'emits a solidus_bactracs.api.sync_completed event' do
|
49
49
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
50
50
|
shipment = instance_spy('Spree::Shipment', number: 'H123456')
|
51
|
-
api_client = instance_double(
|
51
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
52
52
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_return(
|
53
53
|
{
|
54
54
|
'results' => [
|
@@ -65,7 +65,7 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
65
65
|
build_batch_syncer(client: api_client).call([shipment])
|
66
66
|
|
67
67
|
expect(Spree::Event).to have_received(:fire).with(
|
68
|
-
'
|
68
|
+
'solidus_bactracs.api.sync_completed',
|
69
69
|
shipment: shipment,
|
70
70
|
payload: {
|
71
71
|
'orderNumber' => shipment.number,
|
@@ -77,9 +77,9 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
context 'when the sync operation failed' do
|
80
|
-
it 'does not update the
|
80
|
+
it 'does not update the bactracs data on the shipment' do
|
81
81
|
shipment = instance_spy('Spree::Shipment', number: 'H123456')
|
82
|
-
api_client = instance_double(
|
82
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
83
83
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_return(
|
84
84
|
{
|
85
85
|
'results' => [
|
@@ -98,10 +98,10 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
98
98
|
expect(shipment).not_to have_received(:update_columns)
|
99
99
|
end
|
100
100
|
|
101
|
-
it 'emits a
|
101
|
+
it 'emits a solidus_bactracs.api.sync_failed event' do
|
102
102
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
103
103
|
shipment = instance_spy('Spree::Shipment', number: 'H123456')
|
104
|
-
api_client = instance_double(
|
104
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
105
105
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_return(
|
106
106
|
{
|
107
107
|
'results' => [
|
@@ -118,7 +118,7 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
118
118
|
build_batch_syncer(client: api_client).call([shipment])
|
119
119
|
|
120
120
|
expect(Spree::Event).to have_received(:fire).with(
|
121
|
-
'
|
121
|
+
'solidus_bactracs.api.sync_failed',
|
122
122
|
shipment: shipment,
|
123
123
|
payload: {
|
124
124
|
'orderNumber' => shipment.number,
|
@@ -131,27 +131,27 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
131
131
|
end
|
132
132
|
|
133
133
|
context 'when the API call hits a rate limit' do
|
134
|
-
it 'emits a
|
134
|
+
it 'emits a solidus_bactracs.api.rate_limited event' do
|
135
135
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
136
136
|
shipment = instance_double('Spree::Shipment')
|
137
|
-
error =
|
137
|
+
error = SolidusBactracs::Api::RateLimitedError.new(
|
138
138
|
response_headers: { 'X-Rate-Limit-Reset' => 20 },
|
139
139
|
response_body: '{"message":"Too Many Requests"}',
|
140
140
|
response_code: 429,
|
141
141
|
retry_in: 20.seconds,
|
142
142
|
)
|
143
|
-
api_client = instance_double(
|
143
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
144
144
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_raise(error)
|
145
145
|
end
|
146
146
|
|
147
147
|
begin
|
148
148
|
build_batch_syncer(client: api_client).call([shipment])
|
149
|
-
rescue
|
149
|
+
rescue SolidusBactracs::Api::RateLimitedError
|
150
150
|
# We want to ignore the error here, since we're testing for the event.
|
151
151
|
end
|
152
152
|
|
153
153
|
expect(Spree::Event).to have_received(:fire).with(
|
154
|
-
'
|
154
|
+
'solidus_bactracs.api.rate_limited',
|
155
155
|
shipments: [shipment],
|
156
156
|
error: error,
|
157
157
|
)
|
@@ -159,13 +159,13 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
159
159
|
|
160
160
|
it 're-raises the error' do
|
161
161
|
shipment = instance_double('Spree::Shipment')
|
162
|
-
error =
|
162
|
+
error = SolidusBactracs::Api::RateLimitedError.new(
|
163
163
|
response_headers: { 'X-Rate-Limit-Reset' => 20 },
|
164
164
|
response_body: '{"message":"Too Many Requests"}',
|
165
165
|
response_code: 429,
|
166
166
|
retry_in: 20.seconds,
|
167
167
|
)
|
168
|
-
api_client = instance_double(
|
168
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
169
169
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_raise(error)
|
170
170
|
end
|
171
171
|
|
@@ -176,26 +176,26 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
context 'when the API call results in a server error' do
|
179
|
-
it 'emits a
|
179
|
+
it 'emits a solidus_bactracs.api.sync_errored event' do
|
180
180
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
181
181
|
shipment = instance_double('Spree::Shipment')
|
182
|
-
error =
|
182
|
+
error = SolidusBactracs::Api::RequestError.new(
|
183
183
|
response_headers: {},
|
184
184
|
response_body: '{"message":"Internal Server Error"}',
|
185
185
|
response_code: 500,
|
186
186
|
)
|
187
|
-
api_client = instance_double(
|
187
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
188
188
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_raise(error)
|
189
189
|
end
|
190
190
|
|
191
191
|
begin
|
192
192
|
build_batch_syncer(client: api_client).call([shipment])
|
193
|
-
rescue
|
193
|
+
rescue SolidusBactracs::Api::RequestError
|
194
194
|
# We want to ignore the error here, since we're testing for the event.
|
195
195
|
end
|
196
196
|
|
197
197
|
expect(Spree::Event).to have_received(:fire).with(
|
198
|
-
'
|
198
|
+
'solidus_bactracs.api.sync_errored',
|
199
199
|
shipments: [shipment],
|
200
200
|
error: error,
|
201
201
|
)
|
@@ -204,12 +204,12 @@ RSpec.describe SolidusBacktracs::Api::BatchSyncer do
|
|
204
204
|
it 're-raises the error' do
|
205
205
|
stub_const('Spree::Event', class_spy(Spree::Event))
|
206
206
|
shipment = instance_double('Spree::Shipment')
|
207
|
-
error =
|
207
|
+
error = SolidusBactracs::Api::RequestError.new(
|
208
208
|
response_headers: {},
|
209
209
|
response_body: '{"message":"Internal Server Error"}',
|
210
210
|
response_code: 500,
|
211
211
|
)
|
212
|
-
api_client = instance_double(
|
212
|
+
api_client = instance_double(SolidusBactracs::Api::Client).tap do |client|
|
213
213
|
allow(client).to receive(:bulk_create_orders).with([shipment]).and_raise(error)
|
214
214
|
end
|
215
215
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Api::Client do
|
2
2
|
describe '.from_config' do
|
3
3
|
it 'generates a client from the configuration' do
|
4
|
-
request_runner = instance_double('
|
4
|
+
request_runner = instance_double('SolidusBactracs::Api::RequestRunner')
|
5
5
|
error_handler = instance_spy('Proc')
|
6
|
-
shipment_serializer = instance_spy('
|
7
|
-
allow(
|
8
|
-
allow(
|
6
|
+
shipment_serializer = instance_spy('SolidusBactracs::Api::Serializer')
|
7
|
+
allow(SolidusBactracs::Api::RequestRunner).to receive(:from_config).and_return(request_runner)
|
8
|
+
allow(SolidusBactracs.config).to receive_messages(
|
9
9
|
error_handler: error_handler,
|
10
10
|
api_shipment_serializer: shipment_serializer,
|
11
11
|
)
|
@@ -22,7 +22,7 @@ RSpec.describe SolidusBacktracs::Api::Client do
|
|
22
22
|
|
23
23
|
describe '#bulk_create_orders' do
|
24
24
|
it 'calls the bulk order creation endpoint' do
|
25
|
-
request_runner = instance_spy('
|
25
|
+
request_runner = instance_spy('SolidusBactracs::Api::RequestRunner')
|
26
26
|
shipment = build_stubbed(:shipment)
|
27
27
|
serialized_shipment = { 'key' => 'value' }
|
28
28
|
|
@@ -40,7 +40,7 @@ RSpec.describe SolidusBacktracs::Api::Client do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'does not fail for serialization errors' do
|
43
|
-
request_runner = instance_spy('
|
43
|
+
request_runner = instance_spy('SolidusBactracs::Api::RequestRunner')
|
44
44
|
successful_shipment = build_stubbed(:shipment)
|
45
45
|
serialized_shipment = { 'key' => 'value' }
|
46
46
|
failing_shipment = build_stubbed(:shipment)
|
@@ -77,7 +77,7 @@ RSpec.describe SolidusBacktracs::Api::Client do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'skips the API call if all shipments failed serialization' do
|
80
|
-
request_runner = instance_spy('
|
80
|
+
request_runner = instance_spy('SolidusBactracs::Api::RequestRunner')
|
81
81
|
failing_shipment = build_stubbed(:shipment)
|
82
82
|
|
83
83
|
client = build_client(
|
@@ -96,14 +96,14 @@ RSpec.describe SolidusBacktracs::Api::Client do
|
|
96
96
|
|
97
97
|
def build_client(options = {})
|
98
98
|
described_class.new(**{
|
99
|
-
request_runner: instance_spy('
|
99
|
+
request_runner: instance_spy('SolidusBactracs::Api::RequestRunner'),
|
100
100
|
error_handler: instance_spy('Proc'),
|
101
101
|
shipment_serializer: stub_shipment_serializer,
|
102
102
|
}.merge(options))
|
103
103
|
end
|
104
104
|
|
105
105
|
def stub_shipment_serializer(results_map = {})
|
106
|
-
serializer = class_spy('
|
106
|
+
serializer = class_spy('SolidusBactracs::Api::Serializer')
|
107
107
|
|
108
108
|
results_map.each_pair do |shipment, result_or_error|
|
109
109
|
stub = allow(serializer).to receive(:call).with(shipment)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Api::RequestRunner do
|
2
2
|
#TODO
|
3
3
|
describe '.from_config' do
|
4
4
|
it 'builds a runner using credentials from the configuration' do
|
@@ -43,7 +43,7 @@ RSpec.describe SolidusBacktracs::Api::RequestRunner do
|
|
43
43
|
|
44
44
|
expect {
|
45
45
|
request_runner.call(:post, '/test')
|
46
|
-
}.to raise_error(
|
46
|
+
}.to raise_error(SolidusBactracs::Api::RateLimitedError)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -58,7 +58,7 @@ RSpec.describe SolidusBacktracs::Api::RequestRunner do
|
|
58
58
|
|
59
59
|
expect {
|
60
60
|
request_runner.call(:post, '/test')
|
61
|
-
}.to raise_error(
|
61
|
+
}.to raise_error(SolidusBactracs::Api::RequestError)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Api::ThresholdVerifier do
|
2
2
|
context "when the shipment's order was completed" do
|
3
|
-
context 'when the shipment was never synced with
|
4
|
-
it 'returns true when the shipment was never synced with
|
3
|
+
context 'when the shipment was never synced with Bactracs yet' do
|
4
|
+
it 'returns true when the shipment was never synced with bactracs yet' do
|
5
5
|
stub_configuration(api_sync_threshold: 10.minutes)
|
6
6
|
shipment = create(:order_ready_to_ship).shipments.first
|
7
7
|
|
@@ -18,22 +18,22 @@ RSpec.describe SolidusBacktracs::Api::ThresholdVerifier do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'when the shipment was already synced with
|
22
|
-
it 'returns true when the shipment is pending a
|
21
|
+
context 'when the shipment was already synced with Bactracs' do
|
22
|
+
it 'returns true when the shipment is pending a Bactracs re-sync' do
|
23
23
|
stub_configuration(api_sync_threshold: 10.minutes)
|
24
24
|
shipment = create(:order_ready_to_ship).shipments.first.tap do |s|
|
25
25
|
s.order.update_columns(updated_at: 4.minutes.ago)
|
26
|
-
s.update_columns(
|
26
|
+
s.update_columns(bactracs_synced_at: 5.minutes.ago)
|
27
27
|
end
|
28
28
|
|
29
29
|
expect(described_class.call(shipment)).to eq(true)
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'returns false when the shipment is up-to-date in
|
32
|
+
it 'returns false when the shipment is up-to-date in Bactracs' do
|
33
33
|
stub_configuration(api_sync_threshold: 10.minutes)
|
34
34
|
shipment = create(:order_ready_to_ship).shipments.first.tap do |s|
|
35
35
|
s.order.update_columns(updated_at: 6.minutes.ago)
|
36
|
-
s.update_columns(
|
36
|
+
s.update_columns(bactracs_synced_at: 5.minutes.ago)
|
37
37
|
end
|
38
38
|
|
39
39
|
expect(described_class.call(shipment)).to eq(false)
|
@@ -43,7 +43,7 @@ RSpec.describe SolidusBacktracs::Api::ThresholdVerifier do
|
|
43
43
|
stub_configuration(api_sync_threshold: 10.minutes)
|
44
44
|
shipment = create(:order_ready_to_ship).shipments.first.tap do |s|
|
45
45
|
s.order.update_columns(updated_at: 11.minutes.ago)
|
46
|
-
s.update_columns(
|
46
|
+
s.update_columns(bactracs_synced_at: 12.minutes.ago)
|
47
47
|
end
|
48
48
|
|
49
49
|
expect(described_class.call(shipment)).to eq(false)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.describe
|
3
|
+
RSpec.describe SolidusBactracs::ShipmentNotice do
|
4
4
|
shared_examples 'ships or updates the shipment' do
|
5
5
|
context 'when the order was not shipped yet' do
|
6
6
|
# rubocop:disable RSpec/MultipleExpectations
|
@@ -60,7 +60,7 @@ RSpec.describe SolidusBacktracs::ShipmentNotice do
|
|
60
60
|
|
61
61
|
shipment_notice = build_shipment_notice(order.shipments.first)
|
62
62
|
|
63
|
-
expect { shipment_notice.apply }.to raise_error(
|
63
|
+
expect { shipment_notice.apply }.to raise_error(SolidusBactracs::PaymentError) do |e|
|
64
64
|
expect(e.cause).to be_instance_of(Spree::Core::GatewayError)
|
65
65
|
end
|
66
66
|
end
|
@@ -84,7 +84,7 @@ RSpec.describe SolidusBacktracs::ShipmentNotice do
|
|
84
84
|
|
85
85
|
shipment_notice = build_shipment_notice(order.shipments.first)
|
86
86
|
|
87
|
-
expect { shipment_notice.apply }.to raise_error(
|
87
|
+
expect { shipment_notice.apply }.to raise_error(SolidusBactracs::OrderNotPaidError)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -103,7 +103,7 @@ RSpec.describe SolidusBacktracs::ShipmentNotice do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def build_shipment_notice(shipment, shipment_tracking: '1Z1231234')
|
106
|
-
|
106
|
+
SolidusBactracs::ShipmentNotice.new(
|
107
107
|
shipment_number: shipment.number,
|
108
108
|
shipment_tracking: shipment_tracking,
|
109
109
|
)
|
@@ -4,7 +4,7 @@ RSpec.describe Spree::Shipment do
|
|
4
4
|
describe '.between' do
|
5
5
|
it 'delegates to BetweenQuery' do
|
6
6
|
shipment = build_stubbed(:shipment)
|
7
|
-
allow(
|
7
|
+
allow(SolidusBactracs::Shipment::BetweenQuery).to receive(:apply).with(
|
8
8
|
any_args,
|
9
9
|
from: Time.zone.yesterday,
|
10
10
|
to: Time.zone.today,
|
@@ -29,7 +29,7 @@ RSpec.describe Spree::Shipment do
|
|
29
29
|
describe '.exportable' do
|
30
30
|
it 'delegates to ExportableQuery' do
|
31
31
|
shipment = build_stubbed(:shipment)
|
32
|
-
allow(
|
32
|
+
allow(SolidusBactracs::Shipment::ExportableQuery).to receive(:apply).and_return([shipment])
|
33
33
|
|
34
34
|
result = Spree::Deprecation.silence do
|
35
35
|
described_class.exportable
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Shipment::BetweenQuery do
|
2
2
|
describe '.apply' do
|
3
3
|
it 'returns shipments whose updated_at falls within the given time range' do
|
4
4
|
shipment = create(:shipment) { |s| s.update_column(:updated_at, Time.zone.now) }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Shipment::ExportableQuery do
|
2
2
|
describe '.apply' do
|
3
3
|
context 'when capture_at_notification is false and export_canceled_shipments is false' do
|
4
4
|
it 'returns ready shipments from complete orders' do
|
data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/pending_api_sync_query_spec.rb
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe
|
1
|
+
RSpec.describe SolidusBactracs::Shipment::PendingApiSyncQuery do
|
2
2
|
describe '.apply' do
|
3
3
|
context 'when dealing with shipments that were never synced' do
|
4
4
|
it 'returns the shipments that are within the threshold' do
|
@@ -19,15 +19,15 @@ RSpec.describe SolidusBacktracs::Shipment::PendingApiSyncQuery do
|
|
19
19
|
stub_configuration(api_sync_threshold: 10.minutes)
|
20
20
|
shipment = create(:order_ready_to_ship).shipments.first.tap do |s|
|
21
21
|
s.order.update_columns(updated_at: 7.minutes.ago)
|
22
|
-
s.update_columns(
|
22
|
+
s.update_columns(bactracs_synced_at: 8.minutes.ago)
|
23
23
|
end
|
24
24
|
create(:order_ready_to_ship).shipments.first.tap do |s|
|
25
25
|
s.order.update_columns(updated_at: 9.minutes.ago)
|
26
|
-
s.update_columns(
|
26
|
+
s.update_columns(bactracs_synced_at: 8.minutes.ago)
|
27
27
|
end
|
28
28
|
create(:order_ready_to_ship).shipments.first.tap do |s|
|
29
29
|
s.order.update_columns(updated_at: 11.minutes.ago)
|
30
|
-
s.update_columns(
|
30
|
+
s.update_columns(bactracs_synced_at: 10.minutes.ago)
|
31
31
|
end
|
32
32
|
|
33
33
|
expect(described_class.apply(Spree::Shipment.all)).to match_array([shipment])
|
data/spec/spec_helper.rb
CHANGED
@@ -18,8 +18,8 @@ require 'solidus_dev_support/rspec/feature_helper'
|
|
18
18
|
# in spec/support/ and its subdirectories.
|
19
19
|
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
20
20
|
|
21
|
-
# Requires factories defined in lib/
|
22
|
-
SolidusDevSupport::TestingSupport::Factories.load_for(
|
21
|
+
# Requires factories defined in lib/solidus_bactracs/testing_support/factories.rb
|
22
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusBactracs::Engine)
|
23
23
|
|
24
24
|
RSpec.configure do |config|
|
25
25
|
config.infer_spec_type_from_file_location!
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ConfigurationHelper
|
2
2
|
def stub_configuration(options)
|
3
|
-
allow(
|
3
|
+
allow(SolidusBactracs.configuration).to receive_messages(options)
|
4
4
|
|
5
5
|
if options[:capture_at_notification]
|
6
6
|
stub_spree_preferences(require_payment_to_ship: false)
|