solidus_api 2.10.5 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +11 -3
- data/app/controllers/spree/api/checkouts_controller.rb +1 -11
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +2 -2
- data/app/controllers/spree/api/customer_returns_controller.rb +67 -0
- data/app/controllers/spree/api/images_controller.rb +4 -4
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/option_types_controller.rb +3 -3
- data/app/controllers/spree/api/option_values_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +1 -1
- data/app/controllers/spree/api/payments_controller.rb +1 -1
- data/app/controllers/spree/api/product_properties_controller.rb +9 -14
- data/app/controllers/spree/api/promotions_controller.rb +3 -12
- data/app/controllers/spree/api/properties_controller.rb +3 -3
- data/app/controllers/spree/api/resource_controller.rb +2 -2
- data/app/controllers/spree/api/return_authorizations_controller.rb +3 -3
- data/app/controllers/spree/api/shipments_controller.rb +1 -1
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +2 -2
- data/app/controllers/spree/api/stock_locations_controller.rb +3 -3
- data/app/controllers/spree/api/stock_movements_controller.rb +3 -3
- data/app/controllers/spree/api/stores_controller.rb +3 -3
- data/app/controllers/spree/api/taxonomies_controller.rb +2 -2
- data/app/controllers/spree/api/taxons_controller.rb +4 -4
- data/app/controllers/spree/api/users_controller.rb +13 -0
- data/app/controllers/spree/api/variants_controller.rb +3 -3
- data/app/controllers/spree/api/zones_controller.rb +2 -2
- data/app/helpers/spree/api/api_helpers.rb +18 -5
- data/app/views/spree/api/customer_returns/index.json.jbuilder +6 -0
- data/app/views/spree/api/customer_returns/new.json.jbuilder +4 -0
- data/app/views/spree/api/customer_returns/show.json.jbuilder +3 -0
- data/app/views/spree/api/errors/could_not_transition.json.jbuilder +4 -0
- data/app/views/spree/api/orders/could_not_transition.json.jbuilder +5 -0
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +6 -3
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/openapi/authentication.md +9 -1
- data/openapi/checkout-flow.md +17 -4
- data/openapi/main.hub.yml +1 -1
- data/openapi/solidus-api.oas.yml +6753 -0
- data/solidus_api.gemspec +19 -19
- metadata +14 -114
- data/openapi/api.oas2.yml +0 -6108
- data/script/rails +0 -10
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -118
- data/spec/controllers/spree/api/resource_controller_spec.rb +0 -190
- data/spec/features/checkout_spec.rb +0 -192
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/lib/spree_api_responders_spec.rb +0 -10
- data/spec/models/spree/legacy_user_spec.rb +0 -103
- data/spec/requests/api/address_books_spec.rb +0 -240
- data/spec/requests/jbuilder_cache_spec.rb +0 -34
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
- data/spec/requests/spree/api/addresses_controller_spec.rb +0 -57
- data/spec/requests/spree/api/checkouts_controller_spec.rb +0 -484
- data/spec/requests/spree/api/classifications_controller_spec.rb +0 -50
- data/spec/requests/spree/api/config_controller_spec.rb +0 -26
- data/spec/requests/spree/api/countries_controller_spec.rb +0 -48
- data/spec/requests/spree/api/coupon_codes_controller_spec.rb +0 -105
- data/spec/requests/spree/api/credit_cards_controller_spec.rb +0 -105
- data/spec/requests/spree/api/images_controller_spec.rb +0 -99
- data/spec/requests/spree/api/inventory_units_controller_spec.rb +0 -55
- data/spec/requests/spree/api/line_items_controller_spec.rb +0 -213
- data/spec/requests/spree/api/option_types_controller_spec.rb +0 -116
- data/spec/requests/spree/api/option_values_controller_spec.rb +0 -138
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -954
- data/spec/requests/spree/api/payments_controller_spec.rb +0 -259
- data/spec/requests/spree/api/product_properties_controller_spec.rb +0 -114
- data/spec/requests/spree/api/products_controller_spec.rb +0 -422
- data/spec/requests/spree/api/promotion_application_spec.rb +0 -50
- data/spec/requests/spree/api/promotions_controller_spec.rb +0 -67
- data/spec/requests/spree/api/properties_controller_spec.rb +0 -102
- data/spec/requests/spree/api/return_authorizations_controller_spec.rb +0 -180
- data/spec/requests/spree/api/shipments_controller_spec.rb +0 -532
- data/spec/requests/spree/api/states_controller_spec.rb +0 -69
- data/spec/requests/spree/api/stock_items_controller_spec.rb +0 -311
- data/spec/requests/spree/api/stock_locations_controller_spec.rb +0 -170
- data/spec/requests/spree/api/stock_movements_controller_spec.rb +0 -81
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +0 -59
- data/spec/requests/spree/api/stores_controller_spec.rb +0 -134
- data/spec/requests/spree/api/taxonomies_controller_spec.rb +0 -114
- data/spec/requests/spree/api/taxons_controller_spec.rb +0 -217
- data/spec/requests/spree/api/unauthenticated_products_controller_spec.rb +0 -27
- data/spec/requests/spree/api/users_controller_spec.rb +0 -151
- data/spec/requests/spree/api/variants_controller_spec.rb +0 -340
- data/spec/requests/spree/api/zones_controller_spec.rb +0 -89
- data/spec/shared_examples/protect_product_actions.rb +0 -18
- data/spec/spec_helper.rb +0 -73
- data/spec/support/be_paginated_matcher.rb +0 -9
- data/spec/support/controller_hacks.rb +0 -43
- data/spec/support/database_cleaner.rb +0 -16
- data/spec/support/have_attributes_matcher.rb +0 -11
- data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +0 -3
- data/spec/test_views/spree/api/widgets/index.json.jbuilder +0 -9
- data/spec/test_views/spree/api/widgets/new.json.jbuilder +0 -3
- 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,484 +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(:order) { create(:order_with_line_items, state: :payment) }
|
176
|
-
let(:params) do
|
177
|
-
{
|
178
|
-
order_token: order.guest_token,
|
179
|
-
order: {
|
180
|
-
payments_attributes: [
|
181
|
-
{
|
182
|
-
payment_method_id: @payment_method.id.to_s,
|
183
|
-
source_attributes: attributes_for(:credit_card)
|
184
|
-
}
|
185
|
-
]
|
186
|
-
}
|
187
|
-
}
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'sets the payment amount to the order total' do
|
191
|
-
put spree.api_checkout_path(order), params: params
|
192
|
-
expect(response.status).to eq(200)
|
193
|
-
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe 'payment method with source and transition from payment to confirm' do
|
198
|
-
before do
|
199
|
-
order.update_column(:state, "payment")
|
200
|
-
end
|
201
|
-
|
202
|
-
let(:params) do
|
203
|
-
{
|
204
|
-
order_token: order.guest_token,
|
205
|
-
order: {
|
206
|
-
payments_attributes: [
|
207
|
-
{
|
208
|
-
payment_method_id: @payment_method.id.to_s,
|
209
|
-
source_attributes: attributes_for(:credit_card)
|
210
|
-
}
|
211
|
-
]
|
212
|
-
}
|
213
|
-
}
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'succeeds' do
|
217
|
-
put spree.api_checkout_path(order), params: params
|
218
|
-
expect(response.status).to eq(200)
|
219
|
-
expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
|
220
|
-
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context 'when source is missing attributes' do
|
225
|
-
before do
|
226
|
-
order.update_column(:state, "payment")
|
227
|
-
end
|
228
|
-
|
229
|
-
let(:params) do
|
230
|
-
{
|
231
|
-
order_token: order.guest_token,
|
232
|
-
order: {
|
233
|
-
payments_attributes: [
|
234
|
-
{
|
235
|
-
payment_method_id: @payment_method.id.to_s,
|
236
|
-
source_attributes: { name: "Spree" }
|
237
|
-
}
|
238
|
-
]
|
239
|
-
}
|
240
|
-
}
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'returns errors' do
|
244
|
-
put spree.api_checkout_path(order), params: params
|
245
|
-
|
246
|
-
expect(response.status).to eq(422)
|
247
|
-
cc_errors = json_response['errors']['payments.Credit Card']
|
248
|
-
expect(cc_errors).to include("Card Number can't be blank")
|
249
|
-
expect(cc_errors).to include("Month is not a number")
|
250
|
-
expect(cc_errors).to include("Year is not a number")
|
251
|
-
expect(cc_errors).to include("Verification Value can't be blank")
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
context 'reusing a credit card' do
|
256
|
-
before do
|
257
|
-
order.update_column(:state, "payment")
|
258
|
-
end
|
259
|
-
|
260
|
-
let(:params) do
|
261
|
-
{
|
262
|
-
order_token: order.guest_token,
|
263
|
-
order: {
|
264
|
-
payments_attributes: [
|
265
|
-
{
|
266
|
-
source_attributes: {
|
267
|
-
wallet_payment_source_id: wallet_payment_source.id.to_param,
|
268
|
-
verification_value: '456'
|
269
|
-
}
|
270
|
-
}
|
271
|
-
]
|
272
|
-
}
|
273
|
-
}
|
274
|
-
end
|
275
|
-
|
276
|
-
let!(:wallet_payment_source) do
|
277
|
-
order.user.wallet.add(credit_card)
|
278
|
-
end
|
279
|
-
|
280
|
-
let(:credit_card) do
|
281
|
-
create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'succeeds' do
|
285
|
-
# unfortunately the credit card gets reloaded by `@order.next` before
|
286
|
-
# the controller action finishes so this is the best way I could think
|
287
|
-
# of to test that the verification_value gets set.
|
288
|
-
expect_any_instance_of(Spree::CreditCard).to(
|
289
|
-
receive(:verification_value=).with('456').and_call_original
|
290
|
-
)
|
291
|
-
|
292
|
-
put spree.api_checkout_path(order), params: params
|
293
|
-
|
294
|
-
expect(response.status).to eq 200
|
295
|
-
expect(order.credit_cards).to match_array [credit_card]
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'with deprecated existing_card_id param' do
|
299
|
-
let(:params) do
|
300
|
-
{
|
301
|
-
order_token: order.guest_token,
|
302
|
-
order: {
|
303
|
-
payments_attributes: [
|
304
|
-
{
|
305
|
-
source_attributes: {
|
306
|
-
existing_card_id: credit_card.id.to_param,
|
307
|
-
verification_value: '456'
|
308
|
-
}
|
309
|
-
}
|
310
|
-
]
|
311
|
-
}
|
312
|
-
}
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'succeeds' do
|
316
|
-
Spree::Deprecation.silence do
|
317
|
-
put spree.api_checkout_path(order), params: params
|
318
|
-
end
|
319
|
-
|
320
|
-
expect(response.status).to eq 200
|
321
|
-
expect(order.credit_cards).to match_array [credit_card]
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
it "cannot update attributes of another step" do
|
327
|
-
order.update_column(:state, "payment")
|
328
|
-
|
329
|
-
params = {
|
330
|
-
order_token: order.guest_token,
|
331
|
-
order: {
|
332
|
-
payments_attributes: [
|
333
|
-
{
|
334
|
-
payment_method_id: @payment_method.id.to_s,
|
335
|
-
source_attributes: attributes_for(:credit_card)
|
336
|
-
}
|
337
|
-
],
|
338
|
-
ship_address_attributes: {
|
339
|
-
zipcode: 'MALICIOUS ZIPCODE'
|
340
|
-
}
|
341
|
-
}
|
342
|
-
}
|
343
|
-
expect do
|
344
|
-
put spree.api_checkout_path(order), params: params
|
345
|
-
end.not_to change { order.reload.ship_address.zipcode }
|
346
|
-
expect(response.status).to eq(200)
|
347
|
-
end
|
348
|
-
|
349
|
-
it "returns the order if the order is already complete" do
|
350
|
-
order.update_columns(completed_at: Time.current, state: 'complete')
|
351
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
|
352
|
-
assert_unauthorized!
|
353
|
-
end
|
354
|
-
|
355
|
-
context "in delivery state" do
|
356
|
-
let(:order) { create(:order_with_line_items, state: :delivery) }
|
357
|
-
|
358
|
-
# Regression test for https://github.com/spree/spree/issues/3784
|
359
|
-
it "can update the special instructions for an order" do
|
360
|
-
instructions = "Don't drop it. (Please)"
|
361
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
|
362
|
-
expect(json_response['special_instructions']).to eql(instructions)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
context "as an admin" do
|
367
|
-
sign_in_as_admin!
|
368
|
-
it "can assign a user to the order" do
|
369
|
-
user = create(:user)
|
370
|
-
# Need to pass email as well so that validations succeed
|
371
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { user_id: user.id, email: "guest@spreecommerce.com" } }
|
372
|
-
expect(response.status).to eq(200)
|
373
|
-
expect(json_response['user_id']).to eq(user.id)
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
it "can assign an email to the order" do
|
378
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { email: "guest@spreecommerce.com" } }
|
379
|
-
expect(json_response['email']).to eq("guest@spreecommerce.com")
|
380
|
-
expect(response.status).to eq(200)
|
381
|
-
end
|
382
|
-
|
383
|
-
it "can apply a coupon code to an order" do
|
384
|
-
expect(Spree::Deprecation).to receive(:warn)
|
385
|
-
order.update_column(:state, "payment")
|
386
|
-
expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
|
387
|
-
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
388
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
|
389
|
-
expect(response.status).to eq(200)
|
390
|
-
end
|
391
|
-
|
392
|
-
it "renders error failing to apply coupon" do
|
393
|
-
expect(Spree::Deprecation).to receive(:warn)
|
394
|
-
order.update_column(:state, "payment")
|
395
|
-
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
|
396
|
-
expect(response.status).to eq(422)
|
397
|
-
expect(json_response).to eq({ "error" => "The coupon code you entered doesn't exist. Please try again." })
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
context "PUT 'next'" do
|
402
|
-
let!(:order) { create(:order_with_line_items) }
|
403
|
-
it "cannot transition to address without a line item" do
|
404
|
-
order.line_items.delete_all
|
405
|
-
order.update_column(:email, "spree@example.com")
|
406
|
-
put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
|
407
|
-
expect(response.status).to eq(422)
|
408
|
-
expect(json_response["errors"]["base"]).to include(I18n.t('spree.there_are_no_items_for_this_order'))
|
409
|
-
end
|
410
|
-
|
411
|
-
it "can transition an order to the next state" do
|
412
|
-
order.update_column(:email, "spree@example.com")
|
413
|
-
|
414
|
-
put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
|
415
|
-
expect(response.status).to eq(200)
|
416
|
-
expect(json_response['state']).to eq('address')
|
417
|
-
end
|
418
|
-
|
419
|
-
it "cannot transition if order email is blank" do
|
420
|
-
order.update_columns(
|
421
|
-
state: 'address',
|
422
|
-
email: nil
|
423
|
-
)
|
424
|
-
|
425
|
-
put spree.next_api_checkout_path(order), params: { id: order.to_param, order_token: order.guest_token }
|
426
|
-
expect(response.status).to eq(422)
|
427
|
-
expect(json_response['error']).to match(/could not be transitioned/)
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
context "complete" do
|
432
|
-
context "with order in confirm state" do
|
433
|
-
subject do
|
434
|
-
put spree.complete_api_checkout_path(order), params: params
|
435
|
-
end
|
436
|
-
|
437
|
-
let(:params) { { order_token: order.guest_token } }
|
438
|
-
let(:order) { create(:order_with_line_items) }
|
439
|
-
|
440
|
-
before do
|
441
|
-
order.update_column(:state, "confirm")
|
442
|
-
end
|
443
|
-
|
444
|
-
it "can transition from confirm to complete" do
|
445
|
-
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
446
|
-
subject
|
447
|
-
expect(json_response['state']).to eq('complete')
|
448
|
-
expect(response.status).to eq(200)
|
449
|
-
end
|
450
|
-
|
451
|
-
it "returns a sensible error when no payment method is specified" do
|
452
|
-
# put :complete, id: order.to_param, order_token: order.token, order: {}
|
453
|
-
subject
|
454
|
-
expect(json_response["errors"]["base"]).to include(I18n.t('spree.no_payment_found'))
|
455
|
-
end
|
456
|
-
|
457
|
-
context "with mismatched expected_total" do
|
458
|
-
let(:params) { super().merge(expected_total: order.total + 1) }
|
459
|
-
|
460
|
-
it "returns an error if expected_total is present and does not match actual total" do
|
461
|
-
# put :complete, id: order.to_param, order_token: order.token, expected_total: order.total + 1
|
462
|
-
subject
|
463
|
-
expect(response.status).to eq(400)
|
464
|
-
expect(json_response['errors']['expected_total']).to include(I18n.t('spree.api.order.expected_total_mismatch'))
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
context "PUT 'advance'" do
|
471
|
-
let!(:order) { create(:order_with_line_items) }
|
472
|
-
|
473
|
-
it 'continues to advance an order while it can move forward' do
|
474
|
-
expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
|
475
|
-
put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
|
476
|
-
end
|
477
|
-
|
478
|
-
it 'returns the order' do
|
479
|
-
put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
|
480
|
-
expect(json_response['id']).to eq(order.id)
|
481
|
-
end
|
482
|
-
end
|
483
|
-
end
|
484
|
-
end
|