solidus_afterpay 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/Gemfile +6 -3
- data/README.md +3 -0
- data/app/controllers/solidus_afterpay/callbacks_controller.rb +5 -1
- data/app/controllers/solidus_afterpay/express_callbacks_controller.rb +5 -1
- data/app/models/solidus_afterpay/order_component_builder.rb +1 -1
- data/bin/sandbox +1 -1
- data/lib/solidus_afterpay/configuration.rb +9 -2
- data/lib/solidus_afterpay/engine.rb +1 -1
- data/lib/solidus_afterpay/testing_support/factories.rb +1 -1
- data/lib/solidus_afterpay/version.rb +1 -1
- data/solidus_afterpay.gemspec +4 -4
- metadata +11 -99
- data/spec/fixtures/vcr_casettes/create_checkout/invalid.yml +0 -65
- data/spec/fixtures/vcr_casettes/create_checkout/valid.yml +0 -64
- data/spec/fixtures/vcr_casettes/credit/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/credit/valid.yml +0 -63
- data/spec/fixtures/vcr_casettes/deferred/authorize/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/authorize/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/authorize/valid.yml +0 -120
- data/spec/fixtures/vcr_casettes/deferred/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/capture/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/deferred/void/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/deferred/void/valid.yml +0 -137
- data/spec/fixtures/vcr_casettes/find_order/invalid.yml +0 -64
- data/spec/fixtures/vcr_casettes/find_order/valid.yml +0 -120
- data/spec/fixtures/vcr_casettes/find_payment/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/find_payment/valid.yml +0 -140
- data/spec/fixtures/vcr_casettes/immediate/capture/declined_payment.yml +0 -120
- data/spec/fixtures/vcr_casettes/immediate/capture/invalid.yml +0 -61
- data/spec/fixtures/vcr_casettes/immediate/capture/valid.yml +0 -134
- data/spec/fixtures/vcr_casettes/retrieve_configuration/valid.yml +0 -67
- data/spec/helpers/solidus_afterpay/afterpay_helper_spec.rb +0 -39
- data/spec/models/solidus_afterpay/gateway_spec.rb +0 -492
- data/spec/models/solidus_afterpay/order_component_builder_spec.rb +0 -198
- data/spec/models/solidus_afterpay/payment_method_spec.rb +0 -207
- data/spec/models/solidus_afterpay/payment_source_spec.rb +0 -61
- data/spec/models/solidus_afterpay/user_agent_generator_spec.rb +0 -22
- data/spec/models/spree/order_spec.rb +0 -158
- data/spec/presenters/solidus_afterpay/order_presenter_spec.rb +0 -34
- data/spec/presenters/solidus_afterpay/shipping_rate_presenter_spec.rb +0 -28
- data/spec/requests/solidus_afterpay/callbacks_controller_spec.rb +0 -127
- data/spec/requests/solidus_afterpay/checkouts_controller_spec.rb +0 -258
- data/spec/requests/solidus_afterpay/express_callbacks_controller_spec.rb +0 -167
- data/spec/services/solidus_afterpay/base_service_spec.rb +0 -13
- data/spec/services/solidus_afterpay/shipping_rate_builder_service_spec.rb +0 -34
- data/spec/services/solidus_afterpay/update_order_addresses_service_spec.rb +0 -82
- data/spec/services/solidus_afterpay/update_order_attributes_service_spec.rb +0 -58
- data/spec/spec_helper.rb +0 -31
- data/spec/support/auth.rb +0 -15
- data/spec/support/cache.rb +0 -5
- data/spec/support/preferences.rb +0 -33
- data/spec/support/solidus.rb +0 -1
- data/spec/support/vcr.rb +0 -18
- data/spec/views/solidus_afterpay/express_checkout_button_spec.rb +0 -33
- data/spec/views/spree/shared/afterpay_messaging_spec.rb +0 -44
@@ -1,258 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::CheckoutsController, type: :request do
|
6
|
-
describe 'POST create' do
|
7
|
-
subject(:request) { post '/solidus_afterpay/checkouts.json', params: params, headers: headers }
|
8
|
-
|
9
|
-
let(:order) { create(:order_with_totals, state: 'payment', user: user) }
|
10
|
-
let(:payment_method) { create(:afterpay_payment_method) }
|
11
|
-
let(:user) { create(:user, :with_api_key) }
|
12
|
-
|
13
|
-
let(:order_number) { order.number }
|
14
|
-
let(:payment_method_id) { payment_method.id }
|
15
|
-
|
16
|
-
let(:params) { { order_number: order_number, payment_method_id: payment_method_id } }
|
17
|
-
|
18
|
-
let(:order_token) { 'ORDER_TOKEN' }
|
19
|
-
let(:gateway_response_success?) { true }
|
20
|
-
let(:gateway_response_message) { 'Success message' }
|
21
|
-
let(:gateway_response_error_code) { nil }
|
22
|
-
let(:gateway_response_params) { { 'token' => order_token } }
|
23
|
-
let(:headers) { {} }
|
24
|
-
|
25
|
-
let(:gateway_response) do
|
26
|
-
ActiveMerchant::Billing::Response.new(
|
27
|
-
gateway_response_success?,
|
28
|
-
gateway_response_message,
|
29
|
-
gateway_response_params,
|
30
|
-
{ error_code: gateway_response_error_code }
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:gateway) { instance_double(SolidusAfterpay::Gateway, create_checkout: gateway_response) }
|
35
|
-
|
36
|
-
before do
|
37
|
-
allow(SolidusAfterpay::Gateway).to receive(:new).and_return(gateway)
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when the use solidus api config is set to false' do
|
41
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
42
|
-
context 'with valid data' do
|
43
|
-
before do
|
44
|
-
allow(Spree::Order).to receive(:find_by!).with(number: order.number).and_return(order)
|
45
|
-
request
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'returns a 201 status code' do
|
49
|
-
expect(response).to have_http_status(:created)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns the order_token' do
|
53
|
-
expect(JSON.parse(response.body)['token']).to eq(order_token)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns the correct params' do
|
57
|
-
expect(JSON.parse(response.body)).to include('token', 'expires', 'redirectCheckoutUrl')
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when no redirect URLs are passed as params' do
|
61
|
-
let(:redirect_confirm_url) do
|
62
|
-
"http://www.example.com/solidus_afterpay/callbacks/confirm?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
63
|
-
end
|
64
|
-
|
65
|
-
let(:redirect_cancel_url) do
|
66
|
-
"http://www.example.com/solidus_afterpay/callbacks/cancel?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'calls the create_checkout with the correct arguments' do
|
70
|
-
expect(gateway).to have_received(:create_checkout).with(
|
71
|
-
order,
|
72
|
-
redirect_confirm_url: redirect_confirm_url,
|
73
|
-
redirect_cancel_url: redirect_cancel_url,
|
74
|
-
mode: nil,
|
75
|
-
popup_origin_url: nil
|
76
|
-
)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when redirect URLs are passed as params' do
|
81
|
-
let(:redirect_confirm_url) { 'http://www.example.com/confirm_url' }
|
82
|
-
let(:redirect_cancel_url) { 'http://www.example.com/cancel_url' }
|
83
|
-
|
84
|
-
let(:params) do
|
85
|
-
{
|
86
|
-
order_number: order_number,
|
87
|
-
payment_method_id: payment_method_id,
|
88
|
-
redirect_confirm_url: redirect_confirm_url,
|
89
|
-
redirect_cancel_url: redirect_cancel_url
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'calls the create_checkout with the correct arguments' do
|
94
|
-
expect(gateway).to have_received(:create_checkout).with(
|
95
|
-
order,
|
96
|
-
redirect_confirm_url: redirect_confirm_url,
|
97
|
-
redirect_cancel_url: redirect_cancel_url,
|
98
|
-
mode: nil,
|
99
|
-
popup_origin_url: nil
|
100
|
-
)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when the mode is passed as params' do
|
105
|
-
let(:params) do
|
106
|
-
{
|
107
|
-
order_number: order_number,
|
108
|
-
payment_method_id: payment_method_id,
|
109
|
-
mode: 'express'
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
let(:redirect_confirm_url) do
|
114
|
-
"http://www.example.com/solidus_afterpay/callbacks/confirm?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
115
|
-
end
|
116
|
-
|
117
|
-
let(:redirect_cancel_url) do
|
118
|
-
"http://www.example.com/solidus_afterpay/callbacks/cancel?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'calls the create_checkout with the correct arguments' do
|
122
|
-
expect(gateway).to have_received(:create_checkout).with(
|
123
|
-
order,
|
124
|
-
redirect_confirm_url: redirect_confirm_url,
|
125
|
-
redirect_cancel_url: redirect_cancel_url,
|
126
|
-
popup_origin_url: nil,
|
127
|
-
mode: 'express'
|
128
|
-
)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'when the order_number is invalid' do
|
134
|
-
let(:order_number) { 'INVALID_ORDER_NUMBER' }
|
135
|
-
|
136
|
-
before { request }
|
137
|
-
|
138
|
-
it 'returns a 404 status code' do
|
139
|
-
expect(response).to have_http_status(:not_found)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'returns a resource not found error message' do
|
143
|
-
expect(JSON.parse(response.body)['error']).to eq('The resource you were looking for could not be found.')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when the payment_method_id is invalid' do
|
148
|
-
let(:payment_method_id) { 0 }
|
149
|
-
|
150
|
-
before { request }
|
151
|
-
|
152
|
-
it 'returns a 404 status code' do
|
153
|
-
expect(response).to have_http_status(:not_found)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'returns a resource not found error message' do
|
157
|
-
expect(JSON.parse(response.body)['error']).to eq('The resource you were looking for could not be found.')
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'when the payment_method_id is not passed as param' do
|
162
|
-
let(:redirect_confirm_url) do
|
163
|
-
"http://www.example.com/solidus_afterpay/callbacks/confirm?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
164
|
-
end
|
165
|
-
|
166
|
-
let(:redirect_cancel_url) do
|
167
|
-
"http://www.example.com/solidus_afterpay/callbacks/cancel?order_number=#{order.number}&payment_method_id=#{payment_method.id}"
|
168
|
-
end
|
169
|
-
|
170
|
-
let(:params) do
|
171
|
-
{
|
172
|
-
order_number: order_number,
|
173
|
-
mode: 'express'
|
174
|
-
}
|
175
|
-
end
|
176
|
-
|
177
|
-
before do
|
178
|
-
payment_method
|
179
|
-
request
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'uses the first solidus afterpay payment method' do
|
183
|
-
expect(gateway).to have_received(:create_checkout).with(
|
184
|
-
order,
|
185
|
-
redirect_confirm_url: redirect_confirm_url,
|
186
|
-
redirect_cancel_url: redirect_cancel_url,
|
187
|
-
popup_origin_url: nil,
|
188
|
-
mode: 'express'
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'when the gateway responds with error' do
|
194
|
-
let(:gateway_response_success?) { false }
|
195
|
-
let(:gateway_response_message) { 'Error message' }
|
196
|
-
let(:gateway_response_error_code) { 'errorCode' }
|
197
|
-
|
198
|
-
before { request }
|
199
|
-
|
200
|
-
it 'returns a 422 status code' do
|
201
|
-
expect(response).to have_http_status(:unprocessable_entity)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'returns a resource not found error message' do
|
205
|
-
expect(JSON.parse(response.body)['error']).to eq(gateway_response_message)
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'returns the error_code' do
|
209
|
-
expect(JSON.parse(response.body)['errorCode']).to eq(gateway_response_error_code)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
context 'when the user is a guest user', with_guest_session: true do
|
215
|
-
it 'returns a 201 status code' do
|
216
|
-
request
|
217
|
-
expect(response).to have_http_status(:created)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
context 'when the user is not logged in' do
|
222
|
-
it 'returns a 401 status code' do
|
223
|
-
request
|
224
|
-
expect(response).to have_http_status(:unauthorized)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context 'when the use solidus api config is set to true', use_solidus_api: true do
|
230
|
-
context 'when the user is logged in' do
|
231
|
-
let(:headers) { { Authorization: "Bearer #{user.spree_api_key}" } }
|
232
|
-
|
233
|
-
it 'returns a 201 status code' do
|
234
|
-
request
|
235
|
-
expect(response).to have_http_status(:created)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context 'when the user is a guest user' do
|
240
|
-
let(:headers) { { 'X-Spree-Order-Token': order.guest_token } }
|
241
|
-
|
242
|
-
it 'returns a 201 status code' do
|
243
|
-
request
|
244
|
-
expect(response).to have_http_status(:created)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'when the user is not logged in' do
|
249
|
-
let(:headers) { { Authorization: 'Bearer 1234' } }
|
250
|
-
|
251
|
-
it 'returns a 401 status code' do
|
252
|
-
request
|
253
|
-
expect(response).to have_http_status(:unauthorized)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::ExpressCallbacksController, type: :request do
|
6
|
-
describe 'PATCH update' do
|
7
|
-
subject(:request) { patch "/solidus_afterpay/express_callbacks/#{order.number}.json", params: params }
|
8
|
-
|
9
|
-
let(:user) { create(:user) }
|
10
|
-
let(:order) { create(:order_with_line_items, state: 'address', line_items_count: 2, user: user) }
|
11
|
-
|
12
|
-
let(:params) do
|
13
|
-
{
|
14
|
-
address: {
|
15
|
-
name: 'John Doe',
|
16
|
-
address1: '8125 Centre St',
|
17
|
-
address2: '',
|
18
|
-
suburb: 'Citronelle',
|
19
|
-
postcode: '36522-2156',
|
20
|
-
phoneNumber: '1234567',
|
21
|
-
countryCode: 'US',
|
22
|
-
state: 'AL'
|
23
|
-
}
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when the user is not authorized' do
|
28
|
-
it 'returns 401 status code' do
|
29
|
-
request
|
30
|
-
expect(response).to have_http_status(:unauthorized)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when the user is a guest user', with_guest_session: true do
|
35
|
-
it 'returns 200 status code' do
|
36
|
-
request
|
37
|
-
expect(response).to have_http_status(:ok)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
42
|
-
let(:update_order_address_service_result) { true }
|
43
|
-
|
44
|
-
before do
|
45
|
-
allow(SolidusAfterpay::UpdateOrderAddressesService)
|
46
|
-
.to receive(:call)
|
47
|
-
.and_return(update_order_address_service_result)
|
48
|
-
|
49
|
-
allow(SolidusAfterpay.shipping_rate_builder_service_class)
|
50
|
-
.to receive(:call)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns 200 status code' do
|
54
|
-
request
|
55
|
-
expect(response).to have_http_status(:ok)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'calls the update order addresses service' do
|
59
|
-
request
|
60
|
-
expect(SolidusAfterpay::UpdateOrderAddressesService)
|
61
|
-
.to have_received(:call)
|
62
|
-
.with(order: order, address_params: ActionController::Parameters.new(params[:address]))
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'changes the order status' do
|
66
|
-
expect { request }.to change { order.reload.state }.from('address').to('delivery')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'changes the order email if it has a dummy email' do
|
70
|
-
order.update!(email: SolidusAfterpay.configuration.dummy_email)
|
71
|
-
expect { request }.to change { order.reload.email }.from(SolidusAfterpay.configuration.dummy_email).to(nil)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'calls the shipping rate builder service class' do
|
75
|
-
request
|
76
|
-
expect(SolidusAfterpay.shipping_rate_builder_service_class)
|
77
|
-
.to have_received(:call)
|
78
|
-
.with(order: order)
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when the update order addresses service returns false' do
|
82
|
-
let(:update_order_address_service_result) { false }
|
83
|
-
|
84
|
-
it 'retuns an internal server error' do
|
85
|
-
request
|
86
|
-
expect(response).to have_http_status(:internal_server_error)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe 'POST create' do
|
93
|
-
subject(:request) { post "/solidus_afterpay/express_callbacks/#{order.number}.json", params: params }
|
94
|
-
|
95
|
-
let(:user) { create(:user) }
|
96
|
-
let(:order) { create(:order_with_line_items, state: 'delivery', line_items_count: 2, user: user) }
|
97
|
-
let(:payment_method) { create(:afterpay_payment_method) }
|
98
|
-
|
99
|
-
let(:order_token) { 'TOKEN' }
|
100
|
-
let(:update_order_attributes_service_result) { true }
|
101
|
-
|
102
|
-
let(:params) do
|
103
|
-
{
|
104
|
-
token: order_token,
|
105
|
-
order_number: order.number,
|
106
|
-
payment_method_id: payment_method.id,
|
107
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
before do
|
111
|
-
allow(SolidusAfterpay.update_order_attributes_service_class)
|
112
|
-
.to receive(:call)
|
113
|
-
.and_return(update_order_attributes_service_result)
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when the user is not authorized' do
|
117
|
-
it 'returns 401 status code' do
|
118
|
-
request
|
119
|
-
expect(response).to have_http_status(:unauthorized)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'when the user is a guest user', with_guest_session: true do
|
124
|
-
it 'returns 200 status code' do
|
125
|
-
request
|
126
|
-
expect(response).to have_http_status(:ok)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'when the user is logged in', with_signed_in_user: true do
|
131
|
-
it 'returns 200 status code' do
|
132
|
-
request
|
133
|
-
expect(response).to have_http_status(:ok)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'calls the update order attributes service class' do
|
137
|
-
request
|
138
|
-
expect(SolidusAfterpay.update_order_attributes_service_class)
|
139
|
-
.to have_received(:call)
|
140
|
-
.with(
|
141
|
-
order: order,
|
142
|
-
afterpay_order_token: order_token,
|
143
|
-
payment_method: payment_method,
|
144
|
-
request_env: an_instance_of(Hash)
|
145
|
-
)
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'changes the order state to confirm' do
|
149
|
-
expect { request }.to change { order.reload.state }.from('delivery').to('confirm')
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'redirects the user to the checkout confirm step' do
|
153
|
-
request
|
154
|
-
expect(JSON.parse(response.body)['redirect_url']).to eq('http://www.example.com/checkout/confirm')
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'when the update order attributes service fails' do
|
158
|
-
let(:update_order_attributes_service_result) { false }
|
159
|
-
|
160
|
-
it 'returns 500 status code' do
|
161
|
-
request
|
162
|
-
expect(response).to have_http_status(:internal_server_error)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::BaseService do
|
6
|
-
describe '#call' do
|
7
|
-
subject(:service) { described_class.new.call }
|
8
|
-
|
9
|
-
it 'raises a not implemented error' do
|
10
|
-
expect { service }.to raise_error(::NotImplementedError)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::ShippingRateBuilderService do
|
6
|
-
subject(:service) { described_class.call(order: order) }
|
7
|
-
|
8
|
-
let(:order) { ::Spree::TestingSupport::OrderWalkthrough.up_to(:delivery) }
|
9
|
-
|
10
|
-
context 'when the order is in a valid state' do
|
11
|
-
it 'returns the afterpay compliant shipping rate object' do
|
12
|
-
expect(service).to eq(
|
13
|
-
[
|
14
|
-
{
|
15
|
-
id: order.reload.shipments.first.shipping_rates.first.id.to_s,
|
16
|
-
name: 'UPS Ground',
|
17
|
-
description: '$10.00',
|
18
|
-
shipping_amount: '10.0',
|
19
|
-
currency: 'USD',
|
20
|
-
order_amount: '20.0'
|
21
|
-
}
|
22
|
-
]
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when the order is not in a valid state' do
|
28
|
-
before { order.shipments = [] }
|
29
|
-
|
30
|
-
it 'returns an empty array' do
|
31
|
-
expect(service).to be_empty
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::UpdateOrderAddressesService do
|
6
|
-
subject(:service) { described_class.call(order: order, address_params: address_params) }
|
7
|
-
|
8
|
-
let(:order) { create(:order, state: 'payment', ship_address: nil, bill_address: nil) }
|
9
|
-
|
10
|
-
before do
|
11
|
-
country = create(:country)
|
12
|
-
create(:state, country: country)
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when the address params are valid' do
|
16
|
-
let(:address_params) do
|
17
|
-
{
|
18
|
-
address1: '8125 Centre St',
|
19
|
-
address2: '',
|
20
|
-
name: 'John Doe',
|
21
|
-
suburb: 'Citronelle',
|
22
|
-
postcode: '36522-2156',
|
23
|
-
phoneNumber: '12345',
|
24
|
-
countryCode: 'US',
|
25
|
-
state: 'AL'
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns true' do
|
30
|
-
expect(service).to be_truthy
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'changes the order state to address' do
|
34
|
-
expect { service }.to change { order.reload.state }.from('payment').to('address')
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when the order has an email set' do
|
38
|
-
it 'does not change the order email' do
|
39
|
-
expect { service }.not_to(change { order.reload.email })
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when the order does not have an email set' do
|
44
|
-
# rubocop:disable Rails/SkipsModelValidations
|
45
|
-
before { order.update_columns(email: nil) }
|
46
|
-
# rubocop:enable Rails/SkipsModelValidations
|
47
|
-
|
48
|
-
it 'changes the order email with a dummy one' do
|
49
|
-
expect { service }
|
50
|
-
.to change { order.reload.email }
|
51
|
-
.to(SolidusAfterpay.configuration.dummy_email)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when the address params are not valid' do
|
57
|
-
let(:address_params) do
|
58
|
-
{
|
59
|
-
address1: '',
|
60
|
-
address2: '',
|
61
|
-
name: 'John Doe',
|
62
|
-
suburb: '',
|
63
|
-
postcode: '36522-2156',
|
64
|
-
phoneNumber: '12345',
|
65
|
-
countryCode: 'US',
|
66
|
-
state: 'AL'
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'returns false' do
|
71
|
-
expect(service).to be_falsey
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'changes the order state to address' do
|
75
|
-
expect { service }.not_to(change { order.reload.state })
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'does not change the order email' do
|
79
|
-
expect { service }.not_to(change { order.reload.email })
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SolidusAfterpay::UpdateOrderAttributesService do
|
6
|
-
subject(:service) do
|
7
|
-
described_class.call(
|
8
|
-
order: order,
|
9
|
-
afterpay_order_token: afterpay_order_token,
|
10
|
-
payment_method: payment_method,
|
11
|
-
request_env: 'env'
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
let!(:order) { create(:order_with_line_items, line_items_count: 2, state: 'delivery') }
|
16
|
-
let!(:payment_method) { create(:afterpay_payment_method) }
|
17
|
-
|
18
|
-
before do
|
19
|
-
allow(Spree::ShippingRate).to receive(:find).and_return(Spree::ShippingRate.first)
|
20
|
-
allow(order).to receive(:available_payment_methods).and_return(Spree::PaymentMethod.all)
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when the afterpay find order is a success', vcr: 'find_order/valid' do
|
24
|
-
let(:afterpay_order_token) { '002.cb9qevbs1o4el3adh817hqkotkbv4b8u1jkekofd3nb2m8lu' }
|
25
|
-
|
26
|
-
it 'returns true' do
|
27
|
-
expect(service).to be_truthy
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'updates the order email with the Afterpay order email' do
|
31
|
-
expect { service }.to change { order.reload.email }.to('andreavassallo@nebulab.com')
|
32
|
-
end
|
33
|
-
|
34
|
-
# rubocop:disable RSpec/MultipleExpectations
|
35
|
-
it 'updates the payments information with the afterpay payment information' do
|
36
|
-
expect { service }.to change { order.payments.reload.count }.from(0).to(1)
|
37
|
-
expect(order.payments.first.amount).to eq(53.53)
|
38
|
-
expect(order.payments.first.source.token).to eq(afterpay_order_token)
|
39
|
-
end
|
40
|
-
# rubocop:enable RSpec/MultipleExpectations
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when the afterpay find order is a failure', vcr: 'find_order/invalid' do
|
44
|
-
let(:afterpay_order_token) { 'INVALID_TOKEN' }
|
45
|
-
|
46
|
-
it 'returns false' do
|
47
|
-
expect(service).to be_falsey
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'does not change the order email' do
|
51
|
-
expect { service }.not_to(change { order.reload.email })
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'does not change the payments count' do
|
55
|
-
expect { service }.not_to(change { order.payments.reload.count })
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Configure Rails Environment
|
4
|
-
ENV['RAILS_ENV'] = 'test'
|
5
|
-
|
6
|
-
# Run Coverage report
|
7
|
-
require 'solidus_dev_support/rspec/coverage'
|
8
|
-
|
9
|
-
# Create the dummy app if it's still missing.
|
10
|
-
dummy_env = "#{__dir__}/dummy/config/environment.rb"
|
11
|
-
system 'bin/rake extension:test_app' unless File.exist? dummy_env
|
12
|
-
require dummy_env
|
13
|
-
|
14
|
-
# Requires factories and other useful helpers defined in spree_core.
|
15
|
-
require 'solidus_dev_support/rspec/feature_helper'
|
16
|
-
|
17
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
|
-
# in spec/support/ and its subdirectories.
|
19
|
-
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
20
|
-
|
21
|
-
# Requires factories defined in lib/solidus_afterpay/testing_support/factories.rb
|
22
|
-
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusAfterpay::Engine)
|
23
|
-
|
24
|
-
RSpec.configure do |config|
|
25
|
-
config.infer_spec_type_from_file_location!
|
26
|
-
config.use_transactional_fixtures = false
|
27
|
-
|
28
|
-
if Spree.solidus_gem_version < Gem::Version.new('2.11')
|
29
|
-
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
|
30
|
-
end
|
31
|
-
end
|
data/spec/support/auth.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
config.include Devise::Test::IntegrationHelpers, type: :request
|
5
|
-
|
6
|
-
config.before(:each, with_signed_in_user: true) { login_as user }
|
7
|
-
|
8
|
-
config.before(:each, with_guest_session: true) do
|
9
|
-
# rubocop:disable RSpec/AnyInstance
|
10
|
-
allow_any_instance_of(ActionDispatch::Cookies::CookieJar).to(
|
11
|
-
receive(:signed).and_return({ guest_token: order.guest_token })
|
12
|
-
)
|
13
|
-
# rubocop:enable RSpec/AnyInstance
|
14
|
-
end
|
15
|
-
end
|