solidus_api 2.10.0 → 2.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/controllers/spree/api/addresses_controller.rb +1 -1
  4. data/app/controllers/spree/api/base_controller.rb +11 -3
  5. data/app/controllers/spree/api/checkouts_controller.rb +18 -15
  6. data/app/controllers/spree/api/countries_controller.rb +2 -2
  7. data/app/controllers/spree/api/credit_cards_controller.rb +2 -2
  8. data/app/controllers/spree/api/customer_returns_controller.rb +67 -0
  9. data/app/controllers/spree/api/images_controller.rb +4 -4
  10. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  11. data/app/controllers/spree/api/option_types_controller.rb +3 -3
  12. data/app/controllers/spree/api/option_values_controller.rb +2 -2
  13. data/app/controllers/spree/api/orders_controller.rb +8 -2
  14. data/app/controllers/spree/api/payments_controller.rb +1 -1
  15. data/app/controllers/spree/api/product_properties_controller.rb +9 -14
  16. data/app/controllers/spree/api/promotions_controller.rb +3 -12
  17. data/app/controllers/spree/api/properties_controller.rb +3 -3
  18. data/app/controllers/spree/api/resource_controller.rb +2 -2
  19. data/app/controllers/spree/api/return_authorizations_controller.rb +3 -3
  20. data/app/controllers/spree/api/shipments_controller.rb +1 -1
  21. data/app/controllers/spree/api/states_controller.rb +3 -3
  22. data/app/controllers/spree/api/stock_items_controller.rb +2 -2
  23. data/app/controllers/spree/api/stock_locations_controller.rb +3 -3
  24. data/app/controllers/spree/api/stock_movements_controller.rb +3 -3
  25. data/app/controllers/spree/api/stores_controller.rb +3 -3
  26. data/app/controllers/spree/api/taxonomies_controller.rb +2 -2
  27. data/app/controllers/spree/api/taxons_controller.rb +4 -4
  28. data/app/controllers/spree/api/users_controller.rb +13 -0
  29. data/app/controllers/spree/api/variants_controller.rb +3 -3
  30. data/app/controllers/spree/api/zones_controller.rb +2 -2
  31. data/app/helpers/spree/api/api_helpers.rb +18 -5
  32. data/app/views/spree/api/customer_returns/index.json.jbuilder +6 -0
  33. data/app/views/spree/api/customer_returns/new.json.jbuilder +4 -0
  34. data/app/views/spree/api/customer_returns/show.json.jbuilder +3 -0
  35. data/app/views/spree/api/errors/could_not_transition.json.jbuilder +4 -0
  36. data/app/views/spree/api/orders/could_not_transition.json.jbuilder +5 -0
  37. data/config/locales/en.yml +2 -0
  38. data/config/routes.rb +6 -3
  39. data/lib/spree/api/testing_support/helpers.rb +11 -2
  40. data/openapi/authentication.md +9 -1
  41. data/openapi/checkout-flow.md +17 -4
  42. data/openapi/main.hub.yml +1 -1
  43. data/openapi/solidus-api.oas.yml +6753 -0
  44. data/solidus_api.gemspec +19 -19
  45. metadata +17 -117
  46. data/openapi/api.oas2.yml +0 -6105
  47. data/script/rails +0 -10
  48. data/spec/controllers/spree/api/base_controller_spec.rb +0 -118
  49. data/spec/controllers/spree/api/resource_controller_spec.rb +0 -190
  50. data/spec/features/checkout_spec.rb +0 -192
  51. data/spec/fixtures/thinking-cat.jpg +0 -0
  52. data/spec/lib/spree_api_responders_spec.rb +0 -10
  53. data/spec/models/spree/legacy_user_spec.rb +0 -103
  54. data/spec/requests/api/address_books_spec.rb +0 -240
  55. data/spec/requests/jbuilder_cache_spec.rb +0 -34
  56. data/spec/requests/ransackable_attributes_spec.rb +0 -79
  57. data/spec/requests/spree/api/addresses_controller_spec.rb +0 -57
  58. data/spec/requests/spree/api/checkouts_controller_spec.rb +0 -456
  59. data/spec/requests/spree/api/classifications_controller_spec.rb +0 -50
  60. data/spec/requests/spree/api/config_controller_spec.rb +0 -26
  61. data/spec/requests/spree/api/countries_controller_spec.rb +0 -48
  62. data/spec/requests/spree/api/coupon_codes_controller_spec.rb +0 -105
  63. data/spec/requests/spree/api/credit_cards_controller_spec.rb +0 -105
  64. data/spec/requests/spree/api/images_controller_spec.rb +0 -99
  65. data/spec/requests/spree/api/inventory_units_controller_spec.rb +0 -55
  66. data/spec/requests/spree/api/line_items_controller_spec.rb +0 -213
  67. data/spec/requests/spree/api/option_types_controller_spec.rb +0 -116
  68. data/spec/requests/spree/api/option_values_controller_spec.rb +0 -138
  69. data/spec/requests/spree/api/orders_controller_spec.rb +0 -931
  70. data/spec/requests/spree/api/payments_controller_spec.rb +0 -259
  71. data/spec/requests/spree/api/product_properties_controller_spec.rb +0 -114
  72. data/spec/requests/spree/api/products_controller_spec.rb +0 -422
  73. data/spec/requests/spree/api/promotion_application_spec.rb +0 -50
  74. data/spec/requests/spree/api/promotions_controller_spec.rb +0 -67
  75. data/spec/requests/spree/api/properties_controller_spec.rb +0 -102
  76. data/spec/requests/spree/api/return_authorizations_controller_spec.rb +0 -180
  77. data/spec/requests/spree/api/shipments_controller_spec.rb +0 -532
  78. data/spec/requests/spree/api/states_controller_spec.rb +0 -69
  79. data/spec/requests/spree/api/stock_items_controller_spec.rb +0 -311
  80. data/spec/requests/spree/api/stock_locations_controller_spec.rb +0 -170
  81. data/spec/requests/spree/api/stock_movements_controller_spec.rb +0 -81
  82. data/spec/requests/spree/api/store_credit_events_controller_spec.rb +0 -59
  83. data/spec/requests/spree/api/stores_controller_spec.rb +0 -134
  84. data/spec/requests/spree/api/taxonomies_controller_spec.rb +0 -114
  85. data/spec/requests/spree/api/taxons_controller_spec.rb +0 -217
  86. data/spec/requests/spree/api/unauthenticated_products_controller_spec.rb +0 -27
  87. data/spec/requests/spree/api/users_controller_spec.rb +0 -151
  88. data/spec/requests/spree/api/variants_controller_spec.rb +0 -340
  89. data/spec/requests/spree/api/zones_controller_spec.rb +0 -89
  90. data/spec/shared_examples/protect_product_actions.rb +0 -18
  91. data/spec/spec_helper.rb +0 -73
  92. data/spec/support/be_paginated_matcher.rb +0 -9
  93. data/spec/support/controller_hacks.rb +0 -43
  94. data/spec/support/database_cleaner.rb +0 -16
  95. data/spec/support/have_attributes_matcher.rb +0 -11
  96. data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +0 -3
  97. data/spec/test_views/spree/api/widgets/index.json.jbuilder +0 -9
  98. data/spec/test_views/spree/api/widgets/new.json.jbuilder +0 -3
  99. data/spec/test_views/spree/api/widgets/show.json.jbuilder +0 -3
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Spree
6
- describe Api::AddressesController, type: :request do
7
- before do
8
- stub_authentication!
9
- @address = create(:address)
10
- @order = create(:order, bill_address: @address)
11
- end
12
-
13
- context "with order" do
14
- before do
15
- allow_any_instance_of(Order).to receive_messages user: current_api_user
16
- end
17
-
18
- context "with their own address" do
19
- it "gets an address" do
20
- get spree.api_order_address_path(@order, @address.id)
21
- expect(json_response['address1']).to eq @address.address1
22
- end
23
-
24
- it "update replaces the readonly Address associated to the Order" do
25
- put spree.api_order_address_path(@order, @address.id), params: { address: { address1: "123 Test Lane" } }
26
- expect(Order.find(@order.id).bill_address_id).not_to eq @address.id
27
- expect(json_response['address1']).to eq '123 Test Lane'
28
- end
29
-
30
- it "receives the errors object if address is invalid" do
31
- put spree.api_order_address_path(@order, @address.id), params: { address: { address1: "" } }
32
-
33
- expect(json_response['error']).not_to be_nil
34
- expect(json_response['errors']).not_to be_nil
35
- expect(json_response['errors']['address1'].first).to eq "can't be blank"
36
- end
37
- end
38
- end
39
-
40
- context "on an address that does not belong to this order" do
41
- before do
42
- @order.bill_address_id = nil
43
- @order.ship_address = nil
44
- end
45
-
46
- it "cannot retrieve address information" do
47
- get spree.api_order_address_path(@order, @address.id)
48
- assert_unauthorized!
49
- end
50
-
51
- it "cannot update address information" do
52
- get spree.api_order_address_path(@order, @address.id)
53
- assert_unauthorized!
54
- end
55
- end
56
- end
57
- end
@@ -1,456 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Spree
6
- describe Api::CheckoutsController, type: :request do
7
- before(:each) do
8
- stub_authentication!
9
- stub_spree_preferences(track_inventory_levels: false)
10
- country_zone = create(:zone, name: 'CountryZone')
11
- @state = create(:state)
12
- @country = @state.country
13
- country_zone.members.create(zoneable: @country)
14
- create(:stock_location)
15
-
16
- @shipping_method = create(:shipping_method, zones: [country_zone])
17
- @payment_method = create(:credit_card_payment_method)
18
- end
19
-
20
- context "PUT 'update'" do
21
- let(:order) do
22
- order = create(:order_with_line_items)
23
- # Order should be in a pristine state
24
- # Without doing this, the order may transition from 'cart' straight to 'delivery'
25
- order.shipments.delete_all
26
- order
27
- end
28
-
29
- before(:each) do
30
- allow_any_instance_of(Order).to receive_messages(payment_required?: true)
31
- end
32
-
33
- it "should transition a recently created order from cart to address" do
34
- expect(order.state).to eq "cart"
35
- expect(order.email).not_to be_nil
36
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
37
- expect(order.reload.state).to eq "address"
38
- end
39
-
40
- it "should transition a recently created order from cart to address with order token in header" do
41
- expect(order.state).to eq "cart"
42
- expect(order.email).not_to be_nil
43
- put spree.api_checkout_path(order), headers: { "X-Spree-Order-Token" => order.guest_token }
44
- expect(order.reload.state).to eq "address"
45
- end
46
-
47
- it "can take line_items_attributes as a parameter" do
48
- line_item = order.line_items.first
49
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } } }
50
- expect(response.status).to eq(200)
51
- expect(order.reload.state).to eq "address"
52
- end
53
-
54
- it "can take line_items as a parameter" do
55
- line_item = order.line_items.first
56
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } } }
57
- expect(response.status).to eq(200)
58
- expect(order.reload.state).to eq "address"
59
- end
60
-
61
- it "will return an error if the order cannot transition" do
62
- skip "not sure if this test is valid"
63
- order.bill_address = nil
64
- order.save
65
- order.update_column(:state, "address")
66
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
67
- # Order has not transitioned
68
- expect(response.status).to eq(422)
69
- end
70
-
71
- context "transitioning to delivery" do
72
- before do
73
- order.update_column(:state, "address")
74
- end
75
-
76
- let(:address) do
77
- {
78
- firstname: 'John',
79
- lastname: 'Doe',
80
- address1: '7735 Old Georgetown Road',
81
- city: 'Bethesda',
82
- phone: '3014445002',
83
- zipcode: '20814',
84
- state_id: @state.id,
85
- country_id: @country.id
86
- }
87
- end
88
-
89
- it "can update addresses and transition from address to delivery" do
90
- put spree.api_checkout_path(order),
91
- params: { order_token: order.guest_token, order: {
92
- bill_address_attributes: address,
93
- ship_address_attributes: address
94
- } }
95
- expect(json_response['state']).to eq('delivery')
96
- expect(json_response['bill_address']['firstname']).to eq('John')
97
- expect(json_response['ship_address']['firstname']).to eq('John')
98
- expect(response.status).to eq(200)
99
- end
100
-
101
- # Regression Spec for https://github.com/spree/spree/issues/5389 and https://github.com/spree/spree/issues/5880
102
- it "can update addresses but not transition to delivery w/o shipping setup" do
103
- Spree::ShippingMethod.all.each(&:really_destroy!)
104
- put spree.api_checkout_path(order),
105
- params: { order_token: order.guest_token, order: {
106
- bill_address_attributes: address,
107
- ship_address_attributes: address
108
- } }
109
- expect(json_response['error']).to eq(I18n.t(:could_not_transition, scope: "spree.api.order"))
110
- expect(response.status).to eq(422)
111
- end
112
-
113
- # Regression test for https://github.com/spree/spree/issues/4498
114
- it "does not contain duplicate variant data in delivery return" do
115
- put spree.api_checkout_path(order),
116
- params: { order_token: order.guest_token, order: {
117
- bill_address_attributes: address,
118
- ship_address_attributes: address
119
- } }
120
- # Shipments manifests should not return the ENTIRE variant
121
- # This information is already present within the order's line items
122
- expect(json_response['shipments'].first['manifest'].first['variant']).to be_nil
123
- expect(json_response['shipments'].first['manifest'].first['variant_id']).to_not be_nil
124
- end
125
- end
126
-
127
- it "can update shipping method and transition from delivery to payment" do
128
- order.update_column(:state, "delivery")
129
- shipment = create(:shipment, order: order)
130
- shipment.refresh_rates
131
- shipping_rate = shipment.shipping_rates.where(selected: false).first
132
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } } }
133
- expect(response.status).to eq(200)
134
- # Find the correct shipment...
135
- json_shipment = json_response['shipments'].detect { |value| value["id"] == shipment.id }
136
- # Find the correct shipping rate for that shipment...
137
- json_shipping_rate = json_shipment['shipping_rates'].detect { |value| value["id"] == shipping_rate.id }
138
- # ... And finally ensure that it's selected
139
- expect(json_shipping_rate['selected']).to be true
140
- # Order should automatically transfer to payment because all criteria are met
141
- expect(json_response['state']).to eq('payment')
142
- end
143
-
144
- it "can update payment method and transition from payment to confirm" do
145
- order.update_column(:state, "payment")
146
- allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
147
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
148
- expect(json_response['state']).to eq('confirm')
149
- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
150
- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
151
- expect(response.status).to eq(200)
152
- end
153
-
154
- context "with disallowed payment method" do
155
- it "returns not found" do
156
- order.update_column(:state, "payment")
157
- allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
158
- @payment_method.update!(available_to_users: false)
159
- expect {
160
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
161
- }.not_to change { Spree::Payment.count }
162
- expect(response.status).to eq(404)
163
- end
164
- end
165
-
166
- it "returns errors when source is required and missing" do
167
- order.update_column(:state, "payment")
168
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
169
- expect(response.status).to eq(422)
170
- source_errors = json_response['errors']['payments.source']
171
- expect(source_errors).to include("can't be blank")
172
- end
173
-
174
- describe 'setting the payment amount' do
175
- let(:params) do
176
- {
177
- order_token: order.guest_token,
178
- order: {
179
- payments_attributes: [
180
- {
181
- payment_method_id: @payment_method.id.to_s,
182
- source_attributes: attributes_for(:credit_card)
183
- }
184
- ]
185
- }
186
- }
187
- end
188
-
189
- it 'sets the payment amount to the order total' do
190
- put spree.api_checkout_path(order), params: params
191
- expect(response.status).to eq(200)
192
- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
193
- end
194
- end
195
-
196
- describe 'payment method with source and transition from payment to confirm' do
197
- before do
198
- order.update_column(:state, "payment")
199
- end
200
-
201
- let(:params) do
202
- {
203
- order_token: order.guest_token,
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
- it 'succeeds' do
216
- put spree.api_checkout_path(order), params: params
217
- expect(response.status).to eq(200)
218
- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
219
- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
220
- end
221
- end
222
-
223
- context 'when source is missing attributes' do
224
- before do
225
- order.update_column(:state, "payment")
226
- end
227
-
228
- let(:params) do
229
- {
230
- order_token: order.guest_token,
231
- order: {
232
- payments_attributes: [
233
- {
234
- payment_method_id: @payment_method.id.to_s,
235
- source_attributes: { name: "Spree" }
236
- }
237
- ]
238
- }
239
- }
240
- end
241
-
242
- it 'returns errors' do
243
- put spree.api_checkout_path(order), params: params
244
-
245
- expect(response.status).to eq(422)
246
- cc_errors = json_response['errors']['payments.Credit Card']
247
- expect(cc_errors).to include("Card Number can't be blank")
248
- expect(cc_errors).to include("Month is not a number")
249
- expect(cc_errors).to include("Year is not a number")
250
- expect(cc_errors).to include("Verification Value can't be blank")
251
- end
252
- end
253
-
254
- context 'reusing a credit card' do
255
- before do
256
- order.update_column(:state, "payment")
257
- end
258
-
259
- let(:params) do
260
- {
261
- order_token: order.guest_token,
262
- order: {
263
- payments_attributes: [
264
- {
265
- source_attributes: {
266
- wallet_payment_source_id: wallet_payment_source.id.to_param,
267
- verification_value: '456'
268
- }
269
- }
270
- ]
271
- }
272
- }
273
- end
274
-
275
- let!(:wallet_payment_source) do
276
- order.user.wallet.add(credit_card)
277
- end
278
-
279
- let(:credit_card) do
280
- create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)
281
- end
282
-
283
- it 'succeeds' do
284
- # unfortunately the credit card gets reloaded by `@order.next` before
285
- # the controller action finishes so this is the best way I could think
286
- # of to test that the verification_value gets set.
287
- expect_any_instance_of(Spree::CreditCard).to(
288
- receive(:verification_value=).with('456').and_call_original
289
- )
290
-
291
- put spree.api_checkout_path(order), params: params
292
-
293
- expect(response.status).to eq 200
294
- expect(order.credit_cards).to match_array [credit_card]
295
- end
296
-
297
- context 'with deprecated existing_card_id param' do
298
- let(:params) do
299
- {
300
- order_token: order.guest_token,
301
- order: {
302
- payments_attributes: [
303
- {
304
- source_attributes: {
305
- existing_card_id: credit_card.id.to_param,
306
- verification_value: '456'
307
- }
308
- }
309
- ]
310
- }
311
- }
312
- end
313
-
314
- it 'succeeds' do
315
- Spree::Deprecation.silence do
316
- put spree.api_checkout_path(order), params: params
317
- end
318
-
319
- expect(response.status).to eq 200
320
- expect(order.credit_cards).to match_array [credit_card]
321
- end
322
- end
323
- end
324
-
325
- it "returns the order if the order is already complete" do
326
- order.update_columns(completed_at: Time.current, state: 'complete')
327
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
328
- assert_unauthorized!
329
- end
330
-
331
- # Regression test for https://github.com/spree/spree/issues/3784
332
- it "can update the special instructions for an order" do
333
- instructions = "Don't drop it. (Please)"
334
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
335
- expect(json_response['special_instructions']).to eql(instructions)
336
- end
337
-
338
- context "as an admin" do
339
- sign_in_as_admin!
340
- it "can assign a user to the order" do
341
- user = create(:user)
342
- # Need to pass email as well so that validations succeed
343
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { user_id: user.id, email: "guest@spreecommerce.com" } }
344
- expect(response.status).to eq(200)
345
- expect(json_response['user_id']).to eq(user.id)
346
- end
347
- end
348
-
349
- it "can assign an email to the order" do
350
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { email: "guest@spreecommerce.com" } }
351
- expect(json_response['email']).to eq("guest@spreecommerce.com")
352
- expect(response.status).to eq(200)
353
- end
354
-
355
- it "can apply a coupon code to an order" do
356
- expect(Spree::Deprecation).to receive(:warn)
357
- order.update_column(:state, "payment")
358
- expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
359
- expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
360
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
361
- expect(response.status).to eq(200)
362
- end
363
-
364
- it "renders error failing to apply coupon" do
365
- expect(Spree::Deprecation).to receive(:warn)
366
- order.update_column(:state, "payment")
367
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
368
- expect(response.status).to eq(422)
369
- expect(json_response).to eq({ "error" => "The coupon code you entered doesn't exist. Please try again." })
370
- end
371
- end
372
-
373
- context "PUT 'next'" do
374
- let!(:order) { create(:order_with_line_items) }
375
- it "cannot transition to address without a line item" do
376
- order.line_items.delete_all
377
- order.update_column(:email, "spree@example.com")
378
- put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
379
- expect(response.status).to eq(422)
380
- expect(json_response["errors"]["base"]).to include(I18n.t('spree.there_are_no_items_for_this_order'))
381
- end
382
-
383
- it "can transition an order to the next state" do
384
- order.update_column(:email, "spree@example.com")
385
-
386
- put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
387
- expect(response.status).to eq(200)
388
- expect(json_response['state']).to eq('address')
389
- end
390
-
391
- it "cannot transition if order email is blank" do
392
- order.update_columns(
393
- state: 'address',
394
- email: nil
395
- )
396
-
397
- put spree.next_api_checkout_path(order), params: { id: order.to_param, order_token: order.guest_token }
398
- expect(response.status).to eq(422)
399
- expect(json_response['error']).to match(/could not be transitioned/)
400
- end
401
- end
402
-
403
- context "complete" do
404
- context "with order in confirm state" do
405
- subject do
406
- put spree.complete_api_checkout_path(order), params: params
407
- end
408
-
409
- let(:params) { { order_token: order.guest_token } }
410
- let(:order) { create(:order_with_line_items) }
411
-
412
- before do
413
- order.update_column(:state, "confirm")
414
- end
415
-
416
- it "can transition from confirm to complete" do
417
- allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
418
- subject
419
- expect(json_response['state']).to eq('complete')
420
- expect(response.status).to eq(200)
421
- end
422
-
423
- it "returns a sensible error when no payment method is specified" do
424
- # put :complete, id: order.to_param, order_token: order.token, order: {}
425
- subject
426
- expect(json_response["errors"]["base"]).to include(I18n.t('spree.no_payment_found'))
427
- end
428
-
429
- context "with mismatched expected_total" do
430
- let(:params) { super().merge(expected_total: order.total + 1) }
431
-
432
- it "returns an error if expected_total is present and does not match actual total" do
433
- # put :complete, id: order.to_param, order_token: order.token, expected_total: order.total + 1
434
- subject
435
- expect(response.status).to eq(400)
436
- expect(json_response['errors']['expected_total']).to include(I18n.t('spree.api.order.expected_total_mismatch'))
437
- end
438
- end
439
- end
440
- end
441
-
442
- context "PUT 'advance'" do
443
- let!(:order) { create(:order_with_line_items) }
444
-
445
- it 'continues to advance an order while it can move forward' do
446
- expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
447
- put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
448
- end
449
-
450
- it 'returns the order' do
451
- put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
452
- expect(json_response['id']).to eq(order.id)
453
- end
454
- end
455
- end
456
- end