solidus_frontend 2.10.0 → 2.11.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_frontend might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/frontend/checkout/address.js +1 -1
- data/app/assets/javascripts/spree/frontend/checkout/coupon-code.js +1 -1
- data/app/controllers/spree/checkout_controller.rb +26 -10
- data/app/controllers/spree/orders_controller.rb +9 -9
- data/app/controllers/spree/products_controller.rb +1 -1
- data/app/views/spree/address/_form.html.erb +15 -8
- data/app/views/spree/address/_form_hidden.html.erb +6 -2
- data/app/views/spree/checkout/payment/_gateway.html.erb +1 -1
- data/app/views/spree/orders/_form.html.erb +1 -1
- data/app/views/spree/shared/_address.html.erb +1 -1
- data/app/views/spree/shared/_image.html.erb +3 -2
- data/solidus_frontend.gemspec +5 -5
- metadata +13 -56
- data/script/rails +0 -10
- data/spec/controllers/controller_helpers_spec.rb +0 -29
- data/spec/controllers/locale_controller_spec.rb +0 -57
- data/spec/controllers/spree/checkout_controller_spec.rb +0 -581
- data/spec/controllers/spree/checkout_controller_with_views_spec.rb +0 -37
- data/spec/controllers/spree/content_controller_spec.rb +0 -9
- data/spec/controllers/spree/current_order_tracking_spec.rb +0 -47
- data/spec/controllers/spree/home_controller_spec.rb +0 -29
- data/spec/controllers/spree/orders_controller_ability_spec.rb +0 -90
- data/spec/controllers/spree/orders_controller_spec.rb +0 -254
- data/spec/controllers/spree/orders_controller_transitions_spec.rb +0 -33
- data/spec/controllers/spree/products_controller_spec.rb +0 -38
- data/spec/controllers/spree/taxons_controller_spec.rb +0 -14
- data/spec/features/address_spec.rb +0 -78
- data/spec/features/automatic_promotion_adjustments_spec.rb +0 -49
- data/spec/features/caching/products_spec.rb +0 -48
- data/spec/features/caching/taxons_spec.rb +0 -21
- data/spec/features/cart_spec.rb +0 -85
- data/spec/features/checkout_confirm_insufficient_stock_spec.rb +0 -71
- data/spec/features/checkout_spec.rb +0 -750
- data/spec/features/checkout_unshippable_spec.rb +0 -37
- data/spec/features/coupon_code_spec.rb +0 -266
- data/spec/features/currency_spec.rb +0 -20
- data/spec/features/first_order_promotion_spec.rb +0 -59
- data/spec/features/free_shipping_promotions_spec.rb +0 -60
- data/spec/features/locale_spec.rb +0 -26
- data/spec/features/order_spec.rb +0 -73
- data/spec/features/products_spec.rb +0 -291
- data/spec/features/promotion_code_invalidation_spec.rb +0 -54
- data/spec/features/quantity_promotions_spec.rb +0 -130
- data/spec/features/taxons_spec.rb +0 -158
- data/spec/features/template_rendering_spec.rb +0 -20
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/generators/solidus/views/override_generator_spec.rb +0 -50
- data/spec/helpers/base_helper_spec.rb +0 -13
- data/spec/helpers/order_helper_spec.rb +0 -14
- data/spec/helpers/taxon_filters_helper_spec.rb +0 -12
- data/spec/spec_helper.rb +0 -106
- data/spec/support/shared_contexts/checkout_setup.rb +0 -12
- data/spec/support/shared_contexts/custom_products.rb +0 -28
- data/spec/support/shared_contexts/locales.rb +0 -16
- data/spec/views/spree/checkout/_summary_spec.rb +0 -11
@@ -1,581 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Spree::CheckoutController, type: :controller do
|
6
|
-
let(:token) { 'some_token' }
|
7
|
-
let(:user) { create(:user) }
|
8
|
-
let(:order) { FactoryBot.create(:order_with_totals) }
|
9
|
-
|
10
|
-
let(:address_params) do
|
11
|
-
address = FactoryBot.build(:address)
|
12
|
-
address.attributes.except("created_at", "updated_at")
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
allow(controller).to receive_messages try_spree_current_user: user
|
17
|
-
allow(controller).to receive_messages current_order: order
|
18
|
-
end
|
19
|
-
|
20
|
-
context "#edit" do
|
21
|
-
it 'should check if the user is authorized for :edit' do
|
22
|
-
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
23
|
-
request.cookie_jar.signed[:guest_token] = token
|
24
|
-
get :edit, params: { state: 'address' }
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should redirect to the cart path unless checkout_allowed?" do
|
28
|
-
allow(order).to receive_messages checkout_allowed?: false
|
29
|
-
get :edit, params: { state: "delivery" }
|
30
|
-
expect(response).to redirect_to(spree.cart_path)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should redirect to the cart path if current_order is nil" do
|
34
|
-
allow(controller).to receive(:current_order).and_return(nil)
|
35
|
-
get :edit, params: { state: "delivery" }
|
36
|
-
expect(response).to redirect_to(spree.cart_path)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should redirect to cart if order is completed" do
|
40
|
-
allow(order).to receive_messages(completed?: true)
|
41
|
-
get :edit, params: { state: "address" }
|
42
|
-
expect(response).to redirect_to(spree.cart_path)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Regression test for https://github.com/spree/spree/issues/2280
|
46
|
-
it "should redirect to current step trying to access a future step" do
|
47
|
-
order.update_column(:state, "address")
|
48
|
-
get :edit, params: { state: "delivery" }
|
49
|
-
expect(response).to redirect_to spree.checkout_state_path("address")
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when entering the checkout" do
|
53
|
-
before do
|
54
|
-
# The first step for checkout controller is address
|
55
|
-
# Transitioning into this state first is required
|
56
|
-
order.update_column(:state, "address")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should associate the order with a user" do
|
60
|
-
order.update_column :user_id, nil
|
61
|
-
expect(order).to receive(:associate_user!).with(user)
|
62
|
-
get :edit
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "#update" do
|
68
|
-
it 'should check if the user is authorized for :edit' do
|
69
|
-
expect(controller).to receive(:authorize!).with(:edit, order, token)
|
70
|
-
request.cookie_jar.signed[:guest_token] = token
|
71
|
-
post :update, params: { state: 'address' }
|
72
|
-
end
|
73
|
-
|
74
|
-
context "save successful" do
|
75
|
-
def post_address
|
76
|
-
post :update, params: {
|
77
|
-
state: "address",
|
78
|
-
order: {
|
79
|
-
bill_address_attributes: address_params,
|
80
|
-
use_billing: true
|
81
|
-
}
|
82
|
-
}
|
83
|
-
end
|
84
|
-
|
85
|
-
let!(:payment_method) { create(:payment_method) }
|
86
|
-
before do
|
87
|
-
# Must have *a* shipping method and a payment method so updating from address works
|
88
|
-
allow(order).to receive_messages ensure_available_shipping_rates: true
|
89
|
-
order.line_items << FactoryBot.create(:line_item)
|
90
|
-
end
|
91
|
-
|
92
|
-
context "with the order in the cart state", partial_double_verification: false do
|
93
|
-
before do
|
94
|
-
order.update! user: user
|
95
|
-
order.update_column(:state, "cart")
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should assign order" do
|
99
|
-
post :update, params: { state: "address" }
|
100
|
-
expect(assigns[:order]).not_to be_nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should advance the state" do
|
104
|
-
post_address
|
105
|
-
expect(order.reload.state).to eq("delivery")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should redirect the next state" do
|
109
|
-
post_address
|
110
|
-
expect(response).to redirect_to spree.checkout_state_path("delivery")
|
111
|
-
end
|
112
|
-
|
113
|
-
context "current_user respond to save address method" do
|
114
|
-
it "calls persist order address on user" do
|
115
|
-
expect(user).to receive(:persist_order_address)
|
116
|
-
post :update, params: {
|
117
|
-
state: "address",
|
118
|
-
order: {
|
119
|
-
bill_address_attributes: address_params,
|
120
|
-
use_billing: true
|
121
|
-
},
|
122
|
-
save_user_address: "1"
|
123
|
-
}
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "current_user doesnt respond to persist_order_address" do
|
128
|
-
it "doesnt raise any error" do
|
129
|
-
post :update, params: {
|
130
|
-
state: "address",
|
131
|
-
order: {
|
132
|
-
bill_address_attributes: address_params,
|
133
|
-
use_billing: true
|
134
|
-
},
|
135
|
-
save_user_address: "1"
|
136
|
-
}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "with the order in the address state", partial_double_verification: false do
|
142
|
-
before do
|
143
|
-
order.update! user: user
|
144
|
-
order.update_columns(ship_address_id: create(:address).id, state: "address")
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'landing to address page' do
|
148
|
-
it "tries to associate user addresses to order" do
|
149
|
-
expect(order).to receive(:assign_default_user_addresses)
|
150
|
-
get :edit
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "with a billing and shipping address", partial_double_verification: false do
|
155
|
-
subject do
|
156
|
-
post :update, params: {
|
157
|
-
state: "address",
|
158
|
-
order: {
|
159
|
-
bill_address_attributes: order.bill_address.attributes.except("created_at", "updated_at").compact,
|
160
|
-
ship_address_attributes: order.ship_address.attributes.except("created_at", "updated_at").compact,
|
161
|
-
use_billing: false
|
162
|
-
}
|
163
|
-
}
|
164
|
-
end
|
165
|
-
|
166
|
-
it "doesn't change bill address" do
|
167
|
-
expect {
|
168
|
-
subject
|
169
|
-
}.not_to change { order.reload.ship_address.id }
|
170
|
-
end
|
171
|
-
|
172
|
-
it "doesn't change ship address" do
|
173
|
-
expect {
|
174
|
-
subject
|
175
|
-
}.not_to change { order.reload.bill_address.id }
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# This is the only time that we need the 'set_payment_parameters_amount'
|
181
|
-
# controller code, because otherwise the transition to 'confirm' will
|
182
|
-
# trigger the 'add_store_credit_payments' transition code which will do
|
183
|
-
# the same thing here.
|
184
|
-
# Perhaps we can just remove 'set_payment_parameters_amount' entirely at
|
185
|
-
# some point?
|
186
|
-
context "when there is a checkout step between payment and confirm", partial_double_verification: false do
|
187
|
-
before do
|
188
|
-
@old_checkout_flow = Spree::Order.checkout_flow
|
189
|
-
Spree::Order.class_eval do
|
190
|
-
insert_checkout_step :new_step, after: :payment
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
after do
|
195
|
-
Spree::Order.checkout_flow(&@old_checkout_flow)
|
196
|
-
end
|
197
|
-
|
198
|
-
let(:order) { create(:order_with_line_items) }
|
199
|
-
let(:payment_method) { create(:credit_card_payment_method) }
|
200
|
-
|
201
|
-
let(:params) do
|
202
|
-
{
|
203
|
-
state: 'payment',
|
204
|
-
order: {
|
205
|
-
payments_attributes: [
|
206
|
-
{
|
207
|
-
payment_method_id: payment_method.id.to_s,
|
208
|
-
source_attributes: attributes_for(:credit_card)
|
209
|
-
}
|
210
|
-
]
|
211
|
-
}
|
212
|
-
}
|
213
|
-
end
|
214
|
-
|
215
|
-
before do
|
216
|
-
order.update! user: user
|
217
|
-
3.times { order.next! } # should put us in the payment state
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'sets the payment amount' do
|
221
|
-
post :update, params: params
|
222
|
-
order.reload
|
223
|
-
expect(order.state).to eq('new_step')
|
224
|
-
expect(order.payments.size).to eq(1)
|
225
|
-
expect(order.payments.first.amount).to eq(order.total)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context "when in the payment state", partial_double_verification: false do
|
230
|
-
let(:order) { create(:order_with_line_items) }
|
231
|
-
let(:payment_method) { create(:credit_card_payment_method) }
|
232
|
-
|
233
|
-
let(:params) do
|
234
|
-
{
|
235
|
-
state: 'payment',
|
236
|
-
order: {
|
237
|
-
payments_attributes: [
|
238
|
-
{
|
239
|
-
payment_method_id: payment_method.id.to_s,
|
240
|
-
source_attributes: attributes_for(:credit_card)
|
241
|
-
}
|
242
|
-
]
|
243
|
-
}
|
244
|
-
}
|
245
|
-
end
|
246
|
-
|
247
|
-
before do
|
248
|
-
order.update! user: user
|
249
|
-
3.times { order.next! } # should put us in the payment state
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'with a permitted payment method' do
|
253
|
-
it 'sets the payment amount' do
|
254
|
-
post :update, params: params
|
255
|
-
order.reload
|
256
|
-
expect(order.state).to eq('confirm')
|
257
|
-
expect(order.payments.size).to eq(1)
|
258
|
-
expect(order.payments.first.amount).to eq(order.total)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context 'with an unpermitted payment method' do
|
263
|
-
before { payment_method.update!(available_to_users: false) }
|
264
|
-
|
265
|
-
it 'sets the payment amount' do
|
266
|
-
expect {
|
267
|
-
post :update, params: params
|
268
|
-
}.to raise_error(ActiveRecord::RecordNotFound)
|
269
|
-
|
270
|
-
expect(order.state).to eq('payment')
|
271
|
-
expect(order.payments).to be_empty
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "when in the confirm state" do
|
277
|
-
before do
|
278
|
-
order.update! user: user
|
279
|
-
order.update_column(:state, "confirm")
|
280
|
-
# An order requires a payment to reach the complete state
|
281
|
-
# This is because payment_required? is true on the order
|
282
|
-
create(:payment, amount: order.total, order: order)
|
283
|
-
order.create_proposed_shipments
|
284
|
-
order.payments.reload
|
285
|
-
end
|
286
|
-
|
287
|
-
# This inadvertently is a regression test for https://github.com/spree/spree/issues/2694
|
288
|
-
it "should redirect to the order view" do
|
289
|
-
post :update, params: { state: "confirm" }
|
290
|
-
expect(response).to redirect_to spree.order_path(order)
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should populate the flash message" do
|
294
|
-
post :update, params: { state: "confirm" }
|
295
|
-
expect(flash.notice).to eq(I18n.t('spree.order_processed_successfully'))
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should remove completed order from current_order" do
|
299
|
-
post :update, params: { state: "confirm" }
|
300
|
-
expect(assigns(:current_order)).to be_nil
|
301
|
-
expect(assigns(:order)).to eql controller.current_order
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context "save unsuccessful" do
|
307
|
-
before do
|
308
|
-
order.update! user: user
|
309
|
-
allow(order).to receive_messages valid?: false
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should not assign order" do
|
313
|
-
post :update, params: { state: "address", email: '' }
|
314
|
-
expect(assigns[:order]).not_to be_nil
|
315
|
-
end
|
316
|
-
|
317
|
-
it "should not change the order state" do
|
318
|
-
post :update, params: { state: 'address' }
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should render the edit template" do
|
322
|
-
post :update, params: { state: 'address' }
|
323
|
-
expect(response).to render_template :edit
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
context "when current_order is nil" do
|
328
|
-
before { allow(controller).to receive_messages current_order: nil }
|
329
|
-
|
330
|
-
it "should not change the state if order is completed" do
|
331
|
-
expect(order).not_to receive(:update_attribute)
|
332
|
-
post :update, params: { state: "confirm" }
|
333
|
-
end
|
334
|
-
|
335
|
-
it "should redirect to the cart_path" do
|
336
|
-
post :update, params: { state: "confirm" }
|
337
|
-
expect(response).to redirect_to spree.cart_path
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context "Spree::Core::GatewayError" do
|
342
|
-
before do
|
343
|
-
order.update! user: user
|
344
|
-
allow(order).to receive(:next).and_raise(Spree::Core::GatewayError.new("Invalid something or other."))
|
345
|
-
post :update, params: { state: "address" }
|
346
|
-
end
|
347
|
-
|
348
|
-
it "should render the edit template and display exception message" do
|
349
|
-
expect(response).to render_template :edit
|
350
|
-
expect(flash.now[:error]).to eq(I18n.t('spree.spree_gateway_error_flash_for_checkout'))
|
351
|
-
expect(assigns(:order).errors[:base]).to include("Invalid something or other.")
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
context "fails to transition from address" do
|
356
|
-
let(:order) do
|
357
|
-
FactoryBot.create(:order_with_line_items).tap do |order|
|
358
|
-
order.next!
|
359
|
-
expect(order.state).to eq('address')
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
before do
|
364
|
-
allow(controller).to receive_messages current_order: order
|
365
|
-
allow(controller).to receive_messages check_authorization: true
|
366
|
-
end
|
367
|
-
|
368
|
-
context "when the order is invalid" do
|
369
|
-
before do
|
370
|
-
allow(order).to receive_messages valid?: true, next: nil
|
371
|
-
order.errors.add :base, 'Base error'
|
372
|
-
order.errors.add :adjustments, 'error'
|
373
|
-
end
|
374
|
-
|
375
|
-
it "due to the order having errors" do
|
376
|
-
put :update, params: { state: order.state, order: {} }
|
377
|
-
expect(flash[:error]).to eq("Base error\nAdjustments error")
|
378
|
-
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
context "when the country is not a shippable country" do
|
383
|
-
let(:foreign_address) { create(:address, country_iso_code: "CA") }
|
384
|
-
|
385
|
-
before do
|
386
|
-
order.update(shipping_address: foreign_address)
|
387
|
-
end
|
388
|
-
|
389
|
-
it "due to no available shipping rates for any of the shipments" do
|
390
|
-
put :update, params: { state: "address", order: {} }
|
391
|
-
expect(flash[:error]).to eq(I18n.t('spree.items_cannot_be_shipped'))
|
392
|
-
expect(response).to redirect_to(spree.checkout_state_path('address'))
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
context "when GatewayError is raised" do
|
398
|
-
let(:order) do
|
399
|
-
FactoryBot.create(:order_with_line_items).tap do |order|
|
400
|
-
until order.state == 'payment'
|
401
|
-
order.next!
|
402
|
-
end
|
403
|
-
# So that the confirmation step is skipped and we get straight to the action.
|
404
|
-
payment_method = FactoryBot.create(:simple_credit_card_payment_method)
|
405
|
-
payment = FactoryBot.create(:payment, payment_method: payment_method, amount: order.total)
|
406
|
-
order.payments << payment
|
407
|
-
order.next!
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
before do
|
412
|
-
allow(controller).to receive_messages current_order: order
|
413
|
-
allow(controller).to receive_messages check_authorization: true
|
414
|
-
end
|
415
|
-
|
416
|
-
it "fails to transition from payment to complete" do
|
417
|
-
allow_any_instance_of(Spree::Payment).to receive(:process!).and_raise(Spree::Core::GatewayError.new(I18n.t('spree.payment_processing_failed')))
|
418
|
-
put :update, params: { state: order.state, order: {} }
|
419
|
-
expect(flash[:error]).to eq(I18n.t('spree.payment_processing_failed'))
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
context "when InsufficientStock error is raised" do
|
424
|
-
before do
|
425
|
-
allow(controller).to receive_messages current_order: order
|
426
|
-
allow(controller).to receive_messages check_authorization: true
|
427
|
-
allow(controller).to receive_messages ensure_sufficient_stock_lines: true
|
428
|
-
end
|
429
|
-
|
430
|
-
context "when the order has no shipments" do
|
431
|
-
let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:address) }
|
432
|
-
|
433
|
-
before do
|
434
|
-
allow(order).to receive_messages shipments: []
|
435
|
-
# Order#next is the tipical failure point here:
|
436
|
-
allow(order).to receive(:next).and_raise(Spree::Order::InsufficientStock)
|
437
|
-
end
|
438
|
-
|
439
|
-
it "redirects the customer to the cart page with an error message" do
|
440
|
-
put :update, params: { state: order.state, order: {} }
|
441
|
-
expect(flash[:error]).to eq(I18n.t('spree.insufficient_stock_for_order'))
|
442
|
-
expect(response).to redirect_to(spree.cart_path)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
context "when the order has shipments" do
|
447
|
-
let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
|
448
|
-
|
449
|
-
context "when items become somehow not available anymore" do
|
450
|
-
before { Spree::StockItem.update_all backorderable: false }
|
451
|
-
|
452
|
-
it "redirects the customer to the address checkout page with an error message" do
|
453
|
-
put :update, params: { state: order.state, order: {} }
|
454
|
-
error = I18n.t('spree.inventory_error_flash_for_insufficient_shipment_quantity', unavailable_items: order.products.first.name)
|
455
|
-
expect(flash[:error]).to eq(error)
|
456
|
-
expect(response).to redirect_to(spree.checkout_state_path(state: :address))
|
457
|
-
end
|
458
|
-
end
|
459
|
-
end
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
context "When last inventory item has been purchased" do
|
464
|
-
let(:product) { mock_model(Spree::Product, name: "Amazing Object") }
|
465
|
-
let(:variant) { mock_model(Spree::Variant) }
|
466
|
-
let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true, amount: 0, name: "Amazing Item" }
|
467
|
-
let(:order) { create(:order) }
|
468
|
-
|
469
|
-
before do
|
470
|
-
allow(order).to receive_messages(line_items: [line_item], state: "payment")
|
471
|
-
|
472
|
-
stub_spree_preferences(track_inventory_levels: true)
|
473
|
-
end
|
474
|
-
|
475
|
-
context "and back orders are not allowed" do
|
476
|
-
before do
|
477
|
-
post :update, params: { state: "payment" }
|
478
|
-
end
|
479
|
-
|
480
|
-
it "should redirect to cart" do
|
481
|
-
expect(response).to redirect_to spree.cart_path
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should set flash message for no inventory" do
|
485
|
-
expect(flash[:error]).to eq("Amazing Item became unavailable.")
|
486
|
-
end
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
context "order doesn't have a delivery step" do
|
491
|
-
before do
|
492
|
-
allow(order).to receive_messages(checkout_steps: ["cart", "address", "payment"])
|
493
|
-
allow(order).to receive_messages state: "address"
|
494
|
-
allow(controller).to receive_messages check_authorization: true
|
495
|
-
end
|
496
|
-
|
497
|
-
it "doesn't set shipping address on the order" do
|
498
|
-
expect(order).to_not receive(:ship_address=)
|
499
|
-
post :update, params: { state: order.state }
|
500
|
-
end
|
501
|
-
|
502
|
-
it "doesn't remove unshippable items before payment" do
|
503
|
-
expect {
|
504
|
-
post :update, params: { state: "payment" }
|
505
|
-
}.to_not change { order.line_items }
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
it "does remove unshippable items before payment" do
|
510
|
-
allow(order).to receive_messages payment_required?: true
|
511
|
-
allow(controller).to receive_messages check_authorization: true
|
512
|
-
|
513
|
-
expect {
|
514
|
-
post :update, params: { state: "payment" }
|
515
|
-
}.to change { order.line_items.to_a.size }.from(1).to(0)
|
516
|
-
end
|
517
|
-
|
518
|
-
context 'trying to apply a coupon code' do
|
519
|
-
let(:order) { create(:order_with_line_items, state: 'payment', guest_token: 'a token') }
|
520
|
-
let(:coupon_code) { "coupon_code" }
|
521
|
-
|
522
|
-
before { cookies.signed[:guest_token] = order.guest_token }
|
523
|
-
|
524
|
-
context "when coupon code is empty" do
|
525
|
-
let(:coupon_code) { "" }
|
526
|
-
|
527
|
-
it 'does not try to apply coupon code' do
|
528
|
-
expect(Spree::PromotionHandler::Coupon).not_to receive :new
|
529
|
-
|
530
|
-
put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
|
531
|
-
|
532
|
-
expect(response).to redirect_to(spree.checkout_state_path('confirm'))
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
context "when coupon code is applied" do
|
537
|
-
let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') }
|
538
|
-
|
539
|
-
it "continues checkout flow normally" do
|
540
|
-
expect(Spree::Deprecation).to receive(:warn)
|
541
|
-
|
542
|
-
expect(Spree::PromotionHandler::Coupon)
|
543
|
-
.to receive_message_chain(:new, :apply)
|
544
|
-
.and_return(promotion_handler)
|
545
|
-
|
546
|
-
put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
|
547
|
-
|
548
|
-
expect(response).to render_template :edit
|
549
|
-
expect(flash.now[:success]).to eq('Coupon Applied!')
|
550
|
-
end
|
551
|
-
|
552
|
-
context "when coupon code is not applied" do
|
553
|
-
let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) }
|
554
|
-
|
555
|
-
it "setups the current step correctly before rendering" do
|
556
|
-
expect(Spree::Deprecation).to receive(:warn)
|
557
|
-
|
558
|
-
expect(Spree::PromotionHandler::Coupon)
|
559
|
-
.to receive_message_chain(:new, :apply)
|
560
|
-
.and_return(promotion_handler)
|
561
|
-
expect(controller).to receive(:setup_for_current_state)
|
562
|
-
|
563
|
-
put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
|
564
|
-
end
|
565
|
-
|
566
|
-
it "render cart with coupon error" do
|
567
|
-
expect(Spree::Deprecation).to receive(:warn)
|
568
|
-
|
569
|
-
expect(Spree::PromotionHandler::Coupon)
|
570
|
-
.to receive_message_chain(:new, :apply)
|
571
|
-
.and_return(promotion_handler)
|
572
|
-
|
573
|
-
put :update, params: { state: order.state, order: { coupon_code: coupon_code } }
|
574
|
-
|
575
|
-
expect(response).to render_template :edit
|
576
|
-
expect(flash.now[:error]).to eq('Some error')
|
577
|
-
end
|
578
|
-
end
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|