spree_api 2.3.13 → 2.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -43
- data/Gemfile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +22 -9
- data/app/controllers/spree/api/checkouts_controller.rb +2 -2
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
- data/app/controllers/spree/api/images_controller.rb +5 -0
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/line_items_controller.rb +7 -7
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +17 -6
- data/app/controllers/spree/api/payments_controller.rb +3 -11
- data/app/controllers/spree/api/product_properties_controller.rb +2 -2
- data/app/controllers/spree/api/promotions_controller.rb +26 -0
- data/app/controllers/spree/api/properties_controller.rb +1 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
- data/app/controllers/spree/api/shipments_controller.rb +71 -4
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +1 -2
- data/app/helpers/spree/api/api_helpers.rb +19 -5
- data/app/views/spree/api/images/index.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -1
- data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
- data/app/views/spree/api/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/shipments/small.v1.rabl +1 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/variants/big.v1.rabl +6 -1
- data/app/views/spree/api/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/variants/small.v1.rabl +2 -3
- data/config/routes.rb +9 -0
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +6 -6
- data/lib/spree/api/testing_support/setup.rb +2 -2
- data/spec/controllers/spree/api/addresses_controller_spec.rb +7 -7
- data/spec/controllers/spree/api/base_controller_spec.rb +66 -19
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
- data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
- data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/images_controller_spec.rb +37 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
- data/spec/controllers/spree/api/option_types_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/option_values_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/orders_controller_spec.rb +177 -161
- data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
- data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
- data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
- data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
- data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
- data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/users_controller_spec.rb +41 -41
- data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -0
- metadata +14 -9
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'spree/testing_support/bar_ability'
|
3
3
|
|
4
4
|
module Spree
|
5
|
-
describe Api::OrdersController
|
5
|
+
describe Api::OrdersController do
|
6
6
|
render_views
|
7
7
|
|
8
8
|
let!(:order) { create(:order) }
|
@@ -46,7 +46,7 @@ module Spree
|
|
46
46
|
|
47
47
|
it "returns a 401" do
|
48
48
|
api_get :mine
|
49
|
-
|
49
|
+
response.status.should == 401
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -57,110 +57,123 @@ module Spree
|
|
57
57
|
it "can view all of their own orders" do
|
58
58
|
api_get :mine
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
response.status.should == 200
|
61
|
+
json_response["pages"].should == 1
|
62
|
+
json_response["current_page"].should == 1
|
63
|
+
json_response["orders"].length.should == 1
|
64
|
+
json_response["orders"].first["number"].should == order.number
|
65
|
+
json_response["orders"].first["line_items"].length.should == 1
|
66
|
+
json_response["orders"].first["line_items"].first["id"].should == line_item.id
|
67
67
|
end
|
68
68
|
|
69
69
|
it "can filter the returned results" do
|
70
70
|
api_get :mine, q: {completed_at_not_null: 1}
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
response.status.should == 200
|
73
|
+
json_response["orders"].length.should == 0
|
74
74
|
end
|
75
75
|
|
76
|
-
it "returns orders in reverse chronological order" do
|
77
|
-
|
78
|
-
|
76
|
+
it "returns orders in reverse chronological order by completed_at" do
|
77
|
+
order.update_columns completed_at: Time.now
|
78
|
+
|
79
|
+
order2 = Order.create user: order.user, completed_at: Time.now - 1.day
|
80
|
+
order2.created_at.should > order.created_at
|
81
|
+
order3 = Order.create user: order.user, completed_at: nil
|
82
|
+
order3.created_at.should > order2.created_at
|
83
|
+
order4 = Order.create user: order.user, completed_at: nil
|
84
|
+
order4.created_at.should > order3.created_at
|
79
85
|
|
80
86
|
api_get :mine
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
response.status.should == 200
|
88
|
+
json_response["pages"].should == 1
|
89
|
+
json_response["orders"].length.should == 4
|
90
|
+
json_response["orders"][0]["number"].should == order.number
|
91
|
+
json_response["orders"][1]["number"].should == order2.number
|
92
|
+
json_response["orders"][2]["number"].should == order4.number
|
93
|
+
json_response["orders"][3]["number"].should == order3.number
|
86
94
|
end
|
87
95
|
end
|
88
96
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
expect(response.status).to eq(200)
|
93
|
-
expect(json_response).to have_attributes(attributes)
|
94
|
-
expect(json_response["adjustments"]).to be_empty
|
95
|
-
end
|
96
|
-
|
97
|
-
describe 'GET #show' do
|
98
|
-
let(:order) { create :order_with_line_items }
|
99
|
-
let(:adjustment) { FactoryGirl.create(:adjustment, order: order) }
|
97
|
+
describe 'current' do
|
98
|
+
let(:current_api_user) { order.user }
|
99
|
+
let!(:order) { create(:order, line_items: [line_item]) }
|
100
100
|
|
101
|
-
subject
|
101
|
+
subject do
|
102
|
+
api_get :current, format: 'json'
|
103
|
+
end
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
+
context "an incomplete order exists" do
|
106
|
+
it "returns that order" do
|
107
|
+
expect(JSON.parse(subject.body)['id']).to eq order.id
|
108
|
+
expect(subject).to be_success
|
109
|
+
end
|
105
110
|
end
|
106
111
|
|
107
|
-
context
|
108
|
-
it
|
109
|
-
|
110
|
-
|
111
|
-
expect(
|
112
|
-
expect(variant['in_stock']).to eq(false)
|
113
|
-
expect(variant['total_on_hand']).to eq(0)
|
114
|
-
expect(variant['is_backorderable']).to eq(true)
|
112
|
+
context "multiple incomplete orders exist" do
|
113
|
+
it "returns the latest incomplete order" do
|
114
|
+
new_order = Spree::Order.create! user: order.user
|
115
|
+
expect(new_order.created_at).to be > order.created_at
|
116
|
+
expect(JSON.parse(subject.body)['id']).to eq new_order.id
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
118
|
-
context
|
120
|
+
context "an incomplete order does not exist" do
|
121
|
+
|
119
122
|
before do
|
120
|
-
order.
|
123
|
+
order.update_attribute(:state, order_state)
|
124
|
+
order.update_attribute(:completed_at, 5.minutes.ago)
|
121
125
|
end
|
122
126
|
|
123
|
-
|
124
|
-
|
127
|
+
["complete", "returned", "awaiting_return"].each do |order_state|
|
128
|
+
context "order is in the #{order_state} state" do
|
129
|
+
let(:order_state) { order_state }
|
125
130
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
+
it "returns no content" do
|
132
|
+
expect(subject.status).to eq 204
|
133
|
+
expect(subject.body).to be_blank
|
134
|
+
end
|
135
|
+
end
|
131
136
|
end
|
132
137
|
end
|
133
138
|
end
|
134
139
|
|
140
|
+
it "can view their own order" do
|
141
|
+
Order.any_instance.stub :user => current_api_user
|
142
|
+
api_get :show, :id => order.to_param
|
143
|
+
response.status.should == 200
|
144
|
+
json_response.should have_attributes(attributes)
|
145
|
+
json_response["adjustments"].should be_empty
|
146
|
+
end
|
147
|
+
|
135
148
|
it "orders contain the basic checkout steps" do
|
136
|
-
|
149
|
+
Order.any_instance.stub :user => current_api_user
|
137
150
|
api_get :show, :id => order.to_param
|
138
|
-
|
139
|
-
|
151
|
+
response.status.should == 200
|
152
|
+
json_response["checkout_steps"].should == ["address", "delivery", "complete"]
|
140
153
|
end
|
141
154
|
|
142
155
|
# Regression test for #1992
|
143
156
|
it "can view an order not in a standard state" do
|
144
|
-
|
157
|
+
Order.any_instance.stub :user => current_api_user
|
145
158
|
order.update_column(:state, 'shipped')
|
146
159
|
api_get :show, :id => order.to_param
|
147
160
|
end
|
148
161
|
|
149
162
|
it "can not view someone else's order" do
|
150
|
-
|
163
|
+
Order.any_instance.stub :user => stub_model(Spree::LegacyUser)
|
151
164
|
api_get :show, :id => order.to_param
|
152
165
|
assert_unauthorized!
|
153
166
|
end
|
154
167
|
|
155
168
|
it "can view an order if the token is known" do
|
156
169
|
api_get :show, :id => order.to_param, :order_token => order.guest_token
|
157
|
-
|
170
|
+
response.status.should == 200
|
158
171
|
end
|
159
172
|
|
160
173
|
it "can view an order if the token is passed in header" do
|
161
174
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
162
175
|
api_get :show, :id => order.to_param
|
163
|
-
|
176
|
+
response.status.should == 200
|
164
177
|
end
|
165
178
|
|
166
179
|
context "with BarAbility registered" do
|
@@ -169,12 +182,12 @@ module Spree
|
|
169
182
|
|
170
183
|
it "can view an order" do
|
171
184
|
user = mock_model(Spree::LegacyUser)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
185
|
+
user.stub_chain(:spree_roles, :pluck).and_return(["bar"])
|
186
|
+
user.stub(:has_spree_role?).with('bar').and_return(true)
|
187
|
+
user.stub(:has_spree_role?).with('admin').and_return(false)
|
188
|
+
controller.stub try_spree_current_user: user
|
176
189
|
api_get :show, :id => order.to_param
|
177
|
-
|
190
|
+
response.status.should == 200
|
178
191
|
end
|
179
192
|
end
|
180
193
|
|
@@ -192,19 +205,19 @@ module Spree
|
|
192
205
|
|
193
206
|
it "can create an order" do
|
194
207
|
api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
|
195
|
-
|
208
|
+
response.status.should == 201
|
196
209
|
|
197
210
|
order = Order.last
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
211
|
+
order.line_items.count.should == 1
|
212
|
+
order.line_items.first.variant.should == variant
|
213
|
+
order.line_items.first.quantity.should == 5
|
214
|
+
|
215
|
+
json_response['number'].should be_present
|
216
|
+
json_response["token"].should_not be_blank
|
217
|
+
json_response["state"].should == "cart"
|
218
|
+
order.user.should == current_api_user
|
219
|
+
order.email.should == current_api_user.email
|
220
|
+
json_response["user_id"].should == current_api_user.id
|
208
221
|
end
|
209
222
|
|
210
223
|
it "assigns email when creating a new order" do
|
@@ -215,12 +228,12 @@ module Spree
|
|
215
228
|
|
216
229
|
# Regression test for #3404
|
217
230
|
it "can specify additional parameters for a line item" do
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
231
|
+
Order.should_receive(:create!).and_return(order = Spree::Order.new)
|
232
|
+
order.stub(:associate_user!)
|
233
|
+
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
234
|
+
line_item.should_receive(:update_attributes!).with("special" => true)
|
222
235
|
|
223
|
-
|
236
|
+
controller.stub(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
224
237
|
api_post :create, :order => {
|
225
238
|
:line_items => {
|
226
239
|
"0" => {
|
@@ -228,7 +241,7 @@ module Spree
|
|
228
241
|
}
|
229
242
|
}
|
230
243
|
}
|
231
|
-
|
244
|
+
response.status.should == 201
|
232
245
|
end
|
233
246
|
|
234
247
|
it "cannot arbitrarily set the line items price" do
|
@@ -246,8 +259,8 @@ module Spree
|
|
246
259
|
|
247
260
|
context "admin user imports order" do
|
248
261
|
before do
|
249
|
-
|
250
|
-
|
262
|
+
current_api_user.stub has_spree_role?: true
|
263
|
+
current_api_user.stub_chain :spree_roles, pluck: ["admin"]
|
251
264
|
end
|
252
265
|
|
253
266
|
it "is able to set any default unpermitted attribute" do
|
@@ -259,10 +272,10 @@ module Spree
|
|
259
272
|
|
260
273
|
# Regression test for #3404
|
261
274
|
it "does not update line item needlessly" do
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
275
|
+
Order.should_receive(:create!).and_return(order = Spree::Order.new)
|
276
|
+
order.stub(:associate_user!)
|
277
|
+
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
278
|
+
line_item.should_not_receive(:update_attributes)
|
266
279
|
api_post :create, :order => {
|
267
280
|
:line_items => {
|
268
281
|
"0" => {
|
@@ -273,10 +286,10 @@ module Spree
|
|
273
286
|
end
|
274
287
|
|
275
288
|
it "can create an order without any parameters" do
|
276
|
-
|
277
|
-
|
289
|
+
lambda { api_post :create }.should_not raise_error
|
290
|
+
response.status.should == 201
|
278
291
|
order = Order.last
|
279
|
-
|
292
|
+
json_response["state"].should == "cart"
|
280
293
|
end
|
281
294
|
|
282
295
|
context "working with an order" do
|
@@ -294,12 +307,13 @@ module Spree
|
|
294
307
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
295
308
|
|
296
309
|
before do
|
297
|
-
|
310
|
+
Spree::LineItem.stub(:find_by_id).and_return(Spree::LineItem.new)
|
311
|
+
Order.any_instance.stub :user => current_api_user
|
298
312
|
order.next # Switch from cart to address
|
299
313
|
order.bill_address = nil
|
300
314
|
order.ship_address = nil
|
301
315
|
order.save
|
302
|
-
|
316
|
+
order.state.should == "address"
|
303
317
|
end
|
304
318
|
|
305
319
|
def clean_address(address)
|
@@ -325,9 +339,9 @@ module Spree
|
|
325
339
|
}
|
326
340
|
}
|
327
341
|
|
328
|
-
|
329
|
-
|
330
|
-
|
342
|
+
response.status.should == 200
|
343
|
+
json_response['line_items'].count.should == 1
|
344
|
+
json_response['line_items'].first['quantity'].should == 10
|
331
345
|
end
|
332
346
|
|
333
347
|
it "adds an extra line item" do
|
@@ -339,11 +353,11 @@ module Spree
|
|
339
353
|
}
|
340
354
|
}
|
341
355
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
356
|
+
response.status.should == 200
|
357
|
+
json_response['line_items'].count.should == 2
|
358
|
+
json_response['line_items'][0]['quantity'].should == 10
|
359
|
+
json_response['line_items'][1]['variant_id'].should == variant2.id
|
360
|
+
json_response['line_items'][1]['quantity'].should == 1
|
347
361
|
end
|
348
362
|
|
349
363
|
it "cannot change the price of an existing line item" do
|
@@ -353,8 +367,8 @@ module Spree
|
|
353
367
|
}
|
354
368
|
}
|
355
369
|
|
356
|
-
|
357
|
-
|
370
|
+
response.status.should == 200
|
371
|
+
json_response['line_items'].count.should == 1
|
358
372
|
expect(json_response['line_items'].first['price'].to_f).to_not eq(0)
|
359
373
|
expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price)
|
360
374
|
end
|
@@ -362,7 +376,7 @@ module Spree
|
|
362
376
|
it "can add billing address" do
|
363
377
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
364
378
|
|
365
|
-
|
379
|
+
order.reload.bill_address.should_not be_nil
|
366
380
|
end
|
367
381
|
|
368
382
|
it "receives error message if trying to add billing address with errors" do
|
@@ -370,28 +384,28 @@ module Spree
|
|
370
384
|
|
371
385
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
372
386
|
|
373
|
-
|
374
|
-
|
375
|
-
|
387
|
+
json_response['error'].should_not be_nil
|
388
|
+
json_response['errors'].should_not be_nil
|
389
|
+
json_response['errors']['bill_address.firstname'].first.should eq "can't be blank"
|
376
390
|
end
|
377
391
|
|
378
392
|
it "can add shipping address" do
|
379
|
-
|
393
|
+
order.ship_address.should be_nil
|
380
394
|
|
381
395
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
382
396
|
|
383
|
-
|
397
|
+
order.reload.ship_address.should_not be_nil
|
384
398
|
end
|
385
399
|
|
386
400
|
it "receives error message if trying to add shipping address with errors" do
|
387
|
-
|
401
|
+
order.ship_address.should be_nil
|
388
402
|
shipping_address[:firstname] = ""
|
389
403
|
|
390
404
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
391
405
|
|
392
|
-
|
393
|
-
|
394
|
-
|
406
|
+
json_response['error'].should_not be_nil
|
407
|
+
json_response['errors'].should_not be_nil
|
408
|
+
json_response['errors']['ship_address.firstname'].first.should eq "can't be blank"
|
395
409
|
end
|
396
410
|
|
397
411
|
it "cannot set the user_id for the order" do
|
@@ -399,7 +413,7 @@ module Spree
|
|
399
413
|
original_id = order.user_id
|
400
414
|
api_post :update, :id => order.to_param, :order => { user_id: user.id }
|
401
415
|
expect(response.status).to eq 200
|
402
|
-
|
416
|
+
json_response["user_id"].should == original_id
|
403
417
|
end
|
404
418
|
|
405
419
|
context "order has shipments" do
|
@@ -419,17 +433,17 @@ module Spree
|
|
419
433
|
context "with a line item" do
|
420
434
|
let(:order_with_line_items) do
|
421
435
|
order = create(:order_with_line_items)
|
422
|
-
create(:adjustment,
|
436
|
+
create(:adjustment, :adjustable => order)
|
423
437
|
order
|
424
438
|
end
|
425
439
|
|
426
440
|
it "can empty an order" do
|
427
|
-
|
441
|
+
order_with_line_items.adjustments.count.should be == 1
|
428
442
|
api_put :empty, :id => order_with_line_items.to_param
|
429
|
-
|
443
|
+
response.status.should == 204
|
430
444
|
order_with_line_items.reload
|
431
|
-
|
432
|
-
|
445
|
+
order_with_line_items.line_items.should be_empty
|
446
|
+
order_with_line_items.adjustments.should be_empty
|
433
447
|
end
|
434
448
|
|
435
449
|
it "can list its line items with images" do
|
@@ -437,22 +451,22 @@ module Spree
|
|
437
451
|
|
438
452
|
api_get :show, :id => order.to_param
|
439
453
|
|
440
|
-
|
454
|
+
json_response['line_items'].first['variant'].should have_attributes([:images])
|
441
455
|
end
|
442
456
|
|
443
457
|
it "lists variants product id" do
|
444
458
|
api_get :show, :id => order.to_param
|
445
459
|
|
446
|
-
|
460
|
+
json_response['line_items'].first['variant'].should have_attributes([:product_id])
|
447
461
|
end
|
448
462
|
|
449
463
|
it "includes the tax_total in the response" do
|
450
464
|
api_get :show, :id => order.to_param
|
451
465
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
466
|
+
json_response['included_tax_total'].should == '0.0'
|
467
|
+
json_response['additional_tax_total'].should == '0.0'
|
468
|
+
json_response['display_included_tax_total'].should == '$0.00'
|
469
|
+
json_response['display_additional_tax_total'].should == '$0.00'
|
456
470
|
end
|
457
471
|
|
458
472
|
it "lists line item adjustments" do
|
@@ -464,8 +478,8 @@ module Spree
|
|
464
478
|
api_get :show, :id => order.to_param
|
465
479
|
|
466
480
|
adjustment = json_response['line_items'].first['adjustments'].first
|
467
|
-
|
468
|
-
|
481
|
+
adjustment['label'].should == "10% off!"
|
482
|
+
adjustment['amount'].should == "5.0"
|
469
483
|
end
|
470
484
|
|
471
485
|
it "lists payments source without gateway info" do
|
@@ -506,31 +520,33 @@ module Spree
|
|
506
520
|
|
507
521
|
it "returns available shipments for an order" do
|
508
522
|
api_get :show, :id => order.to_param
|
509
|
-
|
510
|
-
|
523
|
+
response.status.should == 200
|
524
|
+
json_response["shipments"].should_not be_empty
|
511
525
|
shipment = json_response["shipments"][0]
|
512
526
|
# Test for correct shipping method attributes
|
513
527
|
# Regression test for #3206
|
514
|
-
|
528
|
+
shipment["shipping_methods"].should_not be_nil
|
515
529
|
json_shipping_method = shipment["shipping_methods"][0]
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
530
|
+
json_shipping_method["id"].should == shipping_method.id
|
531
|
+
json_shipping_method["name"].should == shipping_method.name
|
532
|
+
json_shipping_method["code"].should == shipping_method.code
|
533
|
+
json_shipping_method["zones"].should_not be_empty
|
534
|
+
json_shipping_method["shipping_categories"].should_not be_empty
|
520
535
|
|
521
536
|
# Test for correct shipping rates attributes
|
522
537
|
# Regression test for #3206
|
523
|
-
|
538
|
+
shipment["shipping_rates"].should_not be_nil
|
524
539
|
shipping_rate = shipment["shipping_rates"][0]
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
540
|
+
shipping_rate["name"].should == json_shipping_method["name"]
|
541
|
+
shipping_rate["cost"].should == "10.0"
|
542
|
+
shipping_rate["selected"].should be true
|
543
|
+
shipping_rate["display_cost"].should == "$10.00"
|
544
|
+
shipping_rate["shipping_method_code"].should == json_shipping_method["code"]
|
529
545
|
|
530
|
-
|
546
|
+
shipment["stock_location_name"].should_not be_blank
|
531
547
|
manifest_item = shipment["manifest"][0]
|
532
|
-
|
533
|
-
|
548
|
+
manifest_item["quantity"].should == 1
|
549
|
+
manifest_item["variant_id"].should == order.line_items.first.variant_id
|
534
550
|
end
|
535
551
|
end
|
536
552
|
end
|
@@ -543,7 +559,7 @@ module Spree
|
|
543
559
|
before { Spree::Order.delete_all }
|
544
560
|
it "still returns a root :orders key" do
|
545
561
|
api_get :index
|
546
|
-
|
562
|
+
json_response["orders"].should == []
|
547
563
|
end
|
548
564
|
end
|
549
565
|
|
@@ -596,20 +612,20 @@ module Spree
|
|
596
612
|
|
597
613
|
it "can view all orders" do
|
598
614
|
api_get :index
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
615
|
+
json_response["orders"].first.should have_attributes(attributes)
|
616
|
+
json_response["count"].should == 2
|
617
|
+
json_response["current_page"].should == 1
|
618
|
+
json_response["pages"].should == 1
|
603
619
|
end
|
604
620
|
|
605
621
|
# Test for #1763
|
606
622
|
it "can control the page size through a parameter" do
|
607
623
|
api_get :index, :per_page => 1
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
624
|
+
json_response["orders"].count.should == 1
|
625
|
+
json_response["orders"].first.should have_attributes(attributes)
|
626
|
+
json_response["count"].should == 1
|
627
|
+
json_response["current_page"].should == 1
|
628
|
+
json_response["pages"].should == 2
|
613
629
|
end
|
614
630
|
end
|
615
631
|
|
@@ -623,21 +639,21 @@ module Spree
|
|
623
639
|
|
624
640
|
it "can query the results through a parameter" do
|
625
641
|
api_get :index, :q => { :email_cont => 'spree' }
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
642
|
+
json_response["orders"].count.should == 1
|
643
|
+
json_response["orders"].first.should have_attributes(attributes)
|
644
|
+
json_response["orders"].first["email"].should == expected_result.email
|
645
|
+
json_response["count"].should == 1
|
646
|
+
json_response["current_page"].should == 1
|
647
|
+
json_response["pages"].should == 1
|
632
648
|
end
|
633
649
|
end
|
634
650
|
|
635
651
|
context "creation" do
|
636
652
|
it "can create an order without any parameters" do
|
637
|
-
|
638
|
-
|
653
|
+
lambda { api_post :create }.should_not raise_error
|
654
|
+
response.status.should == 201
|
639
655
|
order = Order.last
|
640
|
-
|
656
|
+
json_response["state"].should == "cart"
|
641
657
|
end
|
642
658
|
|
643
659
|
it "can arbitrarily set the line items price" do
|
@@ -656,7 +672,7 @@ module Spree
|
|
656
672
|
user = Spree.user_class.create
|
657
673
|
api_post :create, :order => { user_id: user.id }
|
658
674
|
expect(response.status).to eq 201
|
659
|
-
|
675
|
+
json_response["user_id"].should == user.id
|
660
676
|
end
|
661
677
|
end
|
662
678
|
|
@@ -665,7 +681,7 @@ module Spree
|
|
665
681
|
user = Spree.user_class.create
|
666
682
|
api_post :update, :id => order.number, :order => { user_id: user.id }
|
667
683
|
expect(response.status).to eq 200
|
668
|
-
|
684
|
+
json_response["user_id"].should == user.id
|
669
685
|
end
|
670
686
|
end
|
671
687
|
|
@@ -681,7 +697,7 @@ module Spree
|
|
681
697
|
|
682
698
|
specify do
|
683
699
|
api_put :cancel, :id => order.to_param
|
684
|
-
|
700
|
+
json_response["state"].should == "canceled"
|
685
701
|
end
|
686
702
|
end
|
687
703
|
end
|