spree_api 2.3.4 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +2 -2
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/shipments_controller.rb +2 -2
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/helpers/spree/api/api_helpers.rb +0 -2
- data/app/views/spree/api/shipments/small.v1.rabl +4 -0
- data/app/views/spree/api/variants/small.v1.rabl +2 -0
- 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 +20 -20
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
- 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 +11 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
- 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 +170 -132
- data/spec/controllers/spree/api/payments_controller_spec.rb +46 -46
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +67 -67
- data/spec/controllers/spree/api/promotion_application_spec.rb +11 -11
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +40 -40
- data/spec/controllers/spree/api/shipments_controller_spec.rb +53 -30
- 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 +25 -25
- data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
- data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +0 -1
- metadata +4 -4
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionValuesController do
|
4
|
+
describe Api::OptionValuesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
|
@@ -13,8 +13,8 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_option_values(option_values)
|
16
|
-
option_values.count.
|
17
|
-
option_values.first.
|
16
|
+
expect(option_values.count).to eq(1)
|
17
|
+
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
18
18
|
:option_type_name, :option_type_id])
|
19
19
|
end
|
20
20
|
|
@@ -26,8 +26,8 @@ module Spree
|
|
26
26
|
|
27
27
|
it "can retreive a list of all option values" do
|
28
28
|
api_get :index
|
29
|
-
json_response.count.
|
30
|
-
json_response.first.
|
29
|
+
expect(json_response.count).to eq(2)
|
30
|
+
expect(json_response.first).to have_attributes(attributes)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,27 +36,27 @@ module Spree
|
|
36
36
|
|
37
37
|
it "can list all option values" do
|
38
38
|
api_get :index
|
39
|
-
json_response.count.
|
40
|
-
json_response.first.
|
39
|
+
expect(json_response.count).to eq(1)
|
40
|
+
expect(json_response.first).to have_attributes(attributes)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "can search for an option type" do
|
44
44
|
create(:option_value, :name => "buzz")
|
45
45
|
api_get :index, :q => { :name_cont => option_value.name }
|
46
|
-
json_response.count.
|
47
|
-
json_response.first.
|
46
|
+
expect(json_response.count).to eq(1)
|
47
|
+
expect(json_response.first).to have_attributes(attributes)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "can retreive a list of option types" do
|
51
51
|
option_value_1 = create(:option_value, :option_type => option_type)
|
52
52
|
option_value_2 = create(:option_value, :option_type => option_type)
|
53
53
|
api_get :index, :ids => [option_value.id, option_value_1.id]
|
54
|
-
json_response.count.
|
54
|
+
expect(json_response.count).to eq(2)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can list a single option value" do
|
58
58
|
api_get :show, :id => option_value.id
|
59
|
-
json_response.
|
59
|
+
expect(json_response).to have_attributes(attributes)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "cannot create a new option value" do
|
@@ -74,13 +74,13 @@ module Spree
|
|
74
74
|
:name => "Option Value"
|
75
75
|
}
|
76
76
|
assert_not_found!
|
77
|
-
option_type.reload.name.
|
77
|
+
expect(option_type.reload.name).to eq(original_name)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "cannot delete an option value" do
|
81
81
|
api_delete :destroy, :id => option_type.id
|
82
82
|
assert_not_found!
|
83
|
-
|
83
|
+
expect { option_type.reload }.not_to raise_error
|
84
84
|
end
|
85
85
|
|
86
86
|
context "as an admin" do
|
@@ -91,13 +91,13 @@ module Spree
|
|
91
91
|
:name => "Option Value",
|
92
92
|
:presentation => "Option Value"
|
93
93
|
}
|
94
|
-
json_response.
|
95
|
-
response.status.
|
94
|
+
expect(json_response).to have_attributes(attributes)
|
95
|
+
expect(response.status).to eq(201)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "cannot create an option type with invalid attributes" do
|
99
99
|
api_post :create, :option_value => {}
|
100
|
-
response.status.
|
100
|
+
expect(response.status).to eq(422)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "can update an option value" do
|
@@ -105,14 +105,14 @@ module Spree
|
|
105
105
|
api_put :update, :id => option_value.id, :option_value => {
|
106
106
|
:name => "Option Value",
|
107
107
|
}
|
108
|
-
response.status.
|
108
|
+
expect(response.status).to eq(200)
|
109
109
|
|
110
110
|
option_value.reload
|
111
|
-
option_value.name.
|
111
|
+
expect(option_value.name).to eq("Option Value")
|
112
112
|
end
|
113
113
|
|
114
114
|
it "permits the correct attributes" do
|
115
|
-
controller.
|
115
|
+
expect(controller).to receive(:permitted_option_value_attributes)
|
116
116
|
api_put :update, :id => option_value.id, :option_value => {
|
117
117
|
:name => ""
|
118
118
|
}
|
@@ -122,12 +122,12 @@ module Spree
|
|
122
122
|
api_put :update, :id => option_value.id, :option_value => {
|
123
123
|
:name => ""
|
124
124
|
}
|
125
|
-
response.status.
|
125
|
+
expect(response.status).to eq(422)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can delete an option value" do
|
129
129
|
api_delete :destroy, :id => option_value.id
|
130
|
-
response.status.
|
130
|
+
expect(response.status).to eq(204)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -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 do
|
5
|
+
describe Api::OrdersController, :type => :controller 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
|
-
response.status.
|
49
|
+
expect(response.status).to eq(401)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -57,72 +57,110 @@ module Spree
|
|
57
57
|
it "can view all of their own orders" do
|
58
58
|
api_get :mine
|
59
59
|
|
60
|
-
response.status.
|
61
|
-
json_response["pages"].
|
62
|
-
json_response["current_page"].
|
63
|
-
json_response["orders"].length.
|
64
|
-
json_response["orders"].first["number"].
|
65
|
-
json_response["orders"].first["line_items"].length.
|
66
|
-
json_response["orders"].first["line_items"].first["id"].
|
60
|
+
expect(response.status).to eq(200)
|
61
|
+
expect(json_response["pages"]).to eq(1)
|
62
|
+
expect(json_response["current_page"]).to eq(1)
|
63
|
+
expect(json_response["orders"].length).to eq(1)
|
64
|
+
expect(json_response["orders"].first["number"]).to eq(order.number)
|
65
|
+
expect(json_response["orders"].first["line_items"].length).to eq(1)
|
66
|
+
expect(json_response["orders"].first["line_items"].first["id"]).to eq(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
|
-
response.status.
|
73
|
-
json_response["orders"].length.
|
72
|
+
expect(response.status).to eq(200)
|
73
|
+
expect(json_response["orders"].length).to eq(0)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "returns orders in reverse chronological order" do
|
77
77
|
order2 = create(:order, line_items: [line_item], user: order.user)
|
78
|
-
order2.created_at.
|
78
|
+
expect(order2.created_at).to be > order.created_at
|
79
79
|
|
80
80
|
api_get :mine
|
81
|
-
response.status.
|
82
|
-
json_response["pages"].
|
83
|
-
json_response["orders"].length.
|
84
|
-
json_response["orders"][0]["number"].
|
85
|
-
json_response["orders"][1]["number"].
|
81
|
+
expect(response.status).to eq(200)
|
82
|
+
expect(json_response["pages"]).to eq(1)
|
83
|
+
expect(json_response["orders"].length).to eq(2)
|
84
|
+
expect(json_response["orders"][0]["number"]).to eq(order2.number)
|
85
|
+
expect(json_response["orders"][1]["number"]).to eq(order.number)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
it "can view their own order" do
|
90
|
-
Order.
|
90
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
91
91
|
api_get :show, :id => order.to_param
|
92
|
-
response.status.
|
93
|
-
json_response.
|
94
|
-
json_response["adjustments"].
|
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) }
|
100
|
+
|
101
|
+
subject { api_get :show, id: order.to_param }
|
102
|
+
|
103
|
+
before do
|
104
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when inventory information is present' do
|
108
|
+
it 'contains stock information on variant' do
|
109
|
+
subject
|
110
|
+
variant = json_response['line_items'][0]['variant']
|
111
|
+
expect(variant).to_not be_nil
|
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)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when shipment adjustments are present' do
|
119
|
+
before do
|
120
|
+
order.shipments.first.adjustments << adjustment
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'contains adjustments on shipment' do
|
124
|
+
subject
|
125
|
+
|
126
|
+
# Test to insure shipment has adjustments
|
127
|
+
shipment = json_response['shipments'][0]
|
128
|
+
expect(shipment).to_not be_nil
|
129
|
+
expect(shipment['adjustments'][0]).not_to be_empty
|
130
|
+
expect(shipment['adjustments'][0]['label']).to eq(adjustment.label)
|
131
|
+
end
|
132
|
+
end
|
95
133
|
end
|
96
134
|
|
97
135
|
it "orders contain the basic checkout steps" do
|
98
|
-
Order.
|
136
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
99
137
|
api_get :show, :id => order.to_param
|
100
|
-
response.status.
|
101
|
-
json_response["checkout_steps"].
|
138
|
+
expect(response.status).to eq(200)
|
139
|
+
expect(json_response["checkout_steps"]).to eq(["address", "delivery", "complete"])
|
102
140
|
end
|
103
141
|
|
104
142
|
# Regression test for #1992
|
105
143
|
it "can view an order not in a standard state" do
|
106
|
-
Order.
|
144
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
107
145
|
order.update_column(:state, 'shipped')
|
108
146
|
api_get :show, :id => order.to_param
|
109
147
|
end
|
110
148
|
|
111
149
|
it "can not view someone else's order" do
|
112
|
-
Order.
|
150
|
+
allow_any_instance_of(Order).to receive_messages :user => stub_model(Spree::LegacyUser)
|
113
151
|
api_get :show, :id => order.to_param
|
114
152
|
assert_unauthorized!
|
115
153
|
end
|
116
154
|
|
117
155
|
it "can view an order if the token is known" do
|
118
156
|
api_get :show, :id => order.to_param, :order_token => order.guest_token
|
119
|
-
response.status.
|
157
|
+
expect(response.status).to eq(200)
|
120
158
|
end
|
121
159
|
|
122
160
|
it "can view an order if the token is passed in header" do
|
123
161
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
124
162
|
api_get :show, :id => order.to_param
|
125
|
-
response.status.
|
163
|
+
expect(response.status).to eq(200)
|
126
164
|
end
|
127
165
|
|
128
166
|
context "with BarAbility registered" do
|
@@ -131,12 +169,12 @@ module Spree
|
|
131
169
|
|
132
170
|
it "can view an order" do
|
133
171
|
user = mock_model(Spree::LegacyUser)
|
134
|
-
user.
|
135
|
-
user.
|
136
|
-
user.
|
137
|
-
controller.
|
172
|
+
allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
|
173
|
+
allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
|
174
|
+
allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
|
175
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
138
176
|
api_get :show, :id => order.to_param
|
139
|
-
response.status.
|
177
|
+
expect(response.status).to eq(200)
|
140
178
|
end
|
141
179
|
end
|
142
180
|
|
@@ -154,19 +192,19 @@ module Spree
|
|
154
192
|
|
155
193
|
it "can create an order" do
|
156
194
|
api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
|
157
|
-
response.status.
|
195
|
+
expect(response.status).to eq(201)
|
158
196
|
|
159
197
|
order = Order.last
|
160
|
-
order.line_items.count.
|
161
|
-
order.line_items.first.variant.
|
162
|
-
order.line_items.first.quantity.
|
163
|
-
|
164
|
-
json_response['number'].
|
165
|
-
json_response["token"].
|
166
|
-
json_response["state"].
|
167
|
-
order.user.
|
168
|
-
order.email.
|
169
|
-
json_response["user_id"].
|
198
|
+
expect(order.line_items.count).to eq(1)
|
199
|
+
expect(order.line_items.first.variant).to eq(variant)
|
200
|
+
expect(order.line_items.first.quantity).to eq(5)
|
201
|
+
|
202
|
+
expect(json_response['number']).to be_present
|
203
|
+
expect(json_response["token"]).not_to be_blank
|
204
|
+
expect(json_response["state"]).to eq("cart")
|
205
|
+
expect(order.user).to eq(current_api_user)
|
206
|
+
expect(order.email).to eq(current_api_user.email)
|
207
|
+
expect(json_response["user_id"]).to eq(current_api_user.id)
|
170
208
|
end
|
171
209
|
|
172
210
|
it "assigns email when creating a new order" do
|
@@ -177,12 +215,12 @@ module Spree
|
|
177
215
|
|
178
216
|
# Regression test for #3404
|
179
217
|
it "can specify additional parameters for a line item" do
|
180
|
-
Order.
|
181
|
-
order.
|
182
|
-
order.
|
183
|
-
line_item.
|
218
|
+
expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
|
219
|
+
allow(order).to receive(:associate_user!)
|
220
|
+
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
221
|
+
expect(line_item).to receive(:update_attributes!).with("special" => true)
|
184
222
|
|
185
|
-
controller.
|
223
|
+
allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
186
224
|
api_post :create, :order => {
|
187
225
|
:line_items => {
|
188
226
|
"0" => {
|
@@ -190,7 +228,7 @@ module Spree
|
|
190
228
|
}
|
191
229
|
}
|
192
230
|
}
|
193
|
-
response.status.
|
231
|
+
expect(response.status).to eq(201)
|
194
232
|
end
|
195
233
|
|
196
234
|
it "cannot arbitrarily set the line items price" do
|
@@ -208,8 +246,8 @@ module Spree
|
|
208
246
|
|
209
247
|
context "admin user imports order" do
|
210
248
|
before do
|
211
|
-
current_api_user.
|
212
|
-
current_api_user.
|
249
|
+
allow(current_api_user).to receive_messages has_spree_role?: true
|
250
|
+
allow(current_api_user).to receive_message_chain :spree_roles, pluck: ["admin"]
|
213
251
|
end
|
214
252
|
|
215
253
|
it "is able to set any default unpermitted attribute" do
|
@@ -221,10 +259,10 @@ module Spree
|
|
221
259
|
|
222
260
|
# Regression test for #3404
|
223
261
|
it "does not update line item needlessly" do
|
224
|
-
Order.
|
225
|
-
order.
|
226
|
-
order.
|
227
|
-
line_item.
|
262
|
+
expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
|
263
|
+
allow(order).to receive(:associate_user!)
|
264
|
+
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
265
|
+
expect(line_item).not_to receive(:update_attributes)
|
228
266
|
api_post :create, :order => {
|
229
267
|
:line_items => {
|
230
268
|
"0" => {
|
@@ -235,10 +273,10 @@ module Spree
|
|
235
273
|
end
|
236
274
|
|
237
275
|
it "can create an order without any parameters" do
|
238
|
-
|
239
|
-
response.status.
|
276
|
+
expect { api_post :create }.not_to raise_error
|
277
|
+
expect(response.status).to eq(201)
|
240
278
|
order = Order.last
|
241
|
-
json_response["state"].
|
279
|
+
expect(json_response["state"]).to eq("cart")
|
242
280
|
end
|
243
281
|
|
244
282
|
context "working with an order" do
|
@@ -256,12 +294,12 @@ module Spree
|
|
256
294
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
257
295
|
|
258
296
|
before do
|
259
|
-
Order.
|
297
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
260
298
|
order.next # Switch from cart to address
|
261
299
|
order.bill_address = nil
|
262
300
|
order.ship_address = nil
|
263
301
|
order.save
|
264
|
-
order.state.
|
302
|
+
expect(order.state).to eq("address")
|
265
303
|
end
|
266
304
|
|
267
305
|
def clean_address(address)
|
@@ -287,9 +325,9 @@ module Spree
|
|
287
325
|
}
|
288
326
|
}
|
289
327
|
|
290
|
-
response.status.
|
291
|
-
json_response['line_items'].count.
|
292
|
-
json_response['line_items'].first['quantity'].
|
328
|
+
expect(response.status).to eq(200)
|
329
|
+
expect(json_response['line_items'].count).to eq(1)
|
330
|
+
expect(json_response['line_items'].first['quantity']).to eq(10)
|
293
331
|
end
|
294
332
|
|
295
333
|
it "adds an extra line item" do
|
@@ -301,11 +339,11 @@ module Spree
|
|
301
339
|
}
|
302
340
|
}
|
303
341
|
|
304
|
-
response.status.
|
305
|
-
json_response['line_items'].count.
|
306
|
-
json_response['line_items'][0]['quantity'].
|
307
|
-
json_response['line_items'][1]['variant_id'].
|
308
|
-
json_response['line_items'][1]['quantity'].
|
342
|
+
expect(response.status).to eq(200)
|
343
|
+
expect(json_response['line_items'].count).to eq(2)
|
344
|
+
expect(json_response['line_items'][0]['quantity']).to eq(10)
|
345
|
+
expect(json_response['line_items'][1]['variant_id']).to eq(variant2.id)
|
346
|
+
expect(json_response['line_items'][1]['quantity']).to eq(1)
|
309
347
|
end
|
310
348
|
|
311
349
|
it "cannot change the price of an existing line item" do
|
@@ -315,8 +353,8 @@ module Spree
|
|
315
353
|
}
|
316
354
|
}
|
317
355
|
|
318
|
-
response.status.
|
319
|
-
json_response['line_items'].count.
|
356
|
+
expect(response.status).to eq(200)
|
357
|
+
expect(json_response['line_items'].count).to eq(1)
|
320
358
|
expect(json_response['line_items'].first['price'].to_f).to_not eq(0)
|
321
359
|
expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price)
|
322
360
|
end
|
@@ -324,7 +362,7 @@ module Spree
|
|
324
362
|
it "can add billing address" do
|
325
363
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
326
364
|
|
327
|
-
order.reload.bill_address.
|
365
|
+
expect(order.reload.bill_address).not_to be_nil
|
328
366
|
end
|
329
367
|
|
330
368
|
it "receives error message if trying to add billing address with errors" do
|
@@ -332,28 +370,28 @@ module Spree
|
|
332
370
|
|
333
371
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
334
372
|
|
335
|
-
json_response['error'].
|
336
|
-
json_response['errors'].
|
337
|
-
json_response['errors']['bill_address.firstname'].first.
|
373
|
+
expect(json_response['error']).not_to be_nil
|
374
|
+
expect(json_response['errors']).not_to be_nil
|
375
|
+
expect(json_response['errors']['bill_address.firstname'].first).to eq "can't be blank"
|
338
376
|
end
|
339
377
|
|
340
378
|
it "can add shipping address" do
|
341
|
-
order.ship_address.
|
379
|
+
expect(order.ship_address).to be_nil
|
342
380
|
|
343
381
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
344
382
|
|
345
|
-
order.reload.ship_address.
|
383
|
+
expect(order.reload.ship_address).not_to be_nil
|
346
384
|
end
|
347
385
|
|
348
386
|
it "receives error message if trying to add shipping address with errors" do
|
349
|
-
order.ship_address.
|
387
|
+
expect(order.ship_address).to be_nil
|
350
388
|
shipping_address[:firstname] = ""
|
351
389
|
|
352
390
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
353
391
|
|
354
|
-
json_response['error'].
|
355
|
-
json_response['errors'].
|
356
|
-
json_response['errors']['ship_address.firstname'].first.
|
392
|
+
expect(json_response['error']).not_to be_nil
|
393
|
+
expect(json_response['errors']).not_to be_nil
|
394
|
+
expect(json_response['errors']['ship_address.firstname'].first).to eq "can't be blank"
|
357
395
|
end
|
358
396
|
|
359
397
|
it "cannot set the user_id for the order" do
|
@@ -361,7 +399,7 @@ module Spree
|
|
361
399
|
original_id = order.user_id
|
362
400
|
api_post :update, :id => order.to_param, :order => { user_id: user.id }
|
363
401
|
expect(response.status).to eq 200
|
364
|
-
json_response["user_id"].
|
402
|
+
expect(json_response["user_id"]).to eq(original_id)
|
365
403
|
end
|
366
404
|
|
367
405
|
context "order has shipments" do
|
@@ -381,17 +419,17 @@ module Spree
|
|
381
419
|
context "with a line item" do
|
382
420
|
let(:order_with_line_items) do
|
383
421
|
order = create(:order_with_line_items)
|
384
|
-
create(:adjustment, :adjustable
|
422
|
+
create(:adjustment, order: order, adjustable: order)
|
385
423
|
order
|
386
424
|
end
|
387
425
|
|
388
426
|
it "can empty an order" do
|
389
|
-
order_with_line_items.adjustments.count.
|
427
|
+
expect(order_with_line_items.adjustments.count).to eq(1)
|
390
428
|
api_put :empty, :id => order_with_line_items.to_param
|
391
|
-
response.status.
|
429
|
+
expect(response.status).to eq(200)
|
392
430
|
order_with_line_items.reload
|
393
|
-
order_with_line_items.line_items.
|
394
|
-
order_with_line_items.adjustments.
|
431
|
+
expect(order_with_line_items.line_items).to be_empty
|
432
|
+
expect(order_with_line_items.adjustments).to be_empty
|
395
433
|
end
|
396
434
|
|
397
435
|
it "can list its line items with images" do
|
@@ -399,22 +437,22 @@ module Spree
|
|
399
437
|
|
400
438
|
api_get :show, :id => order.to_param
|
401
439
|
|
402
|
-
json_response['line_items'].first['variant'].
|
440
|
+
expect(json_response['line_items'].first['variant']).to have_attributes([:images])
|
403
441
|
end
|
404
442
|
|
405
443
|
it "lists variants product id" do
|
406
444
|
api_get :show, :id => order.to_param
|
407
445
|
|
408
|
-
json_response['line_items'].first['variant'].
|
446
|
+
expect(json_response['line_items'].first['variant']).to have_attributes([:product_id])
|
409
447
|
end
|
410
448
|
|
411
449
|
it "includes the tax_total in the response" do
|
412
450
|
api_get :show, :id => order.to_param
|
413
451
|
|
414
|
-
json_response['included_tax_total'].
|
415
|
-
json_response['additional_tax_total'].
|
416
|
-
json_response['display_included_tax_total'].
|
417
|
-
json_response['display_additional_tax_total'].
|
452
|
+
expect(json_response['included_tax_total']).to eq('0.0')
|
453
|
+
expect(json_response['additional_tax_total']).to eq('0.0')
|
454
|
+
expect(json_response['display_included_tax_total']).to eq('$0.00')
|
455
|
+
expect(json_response['display_additional_tax_total']).to eq('$0.00')
|
418
456
|
end
|
419
457
|
|
420
458
|
it "lists line item adjustments" do
|
@@ -426,8 +464,8 @@ module Spree
|
|
426
464
|
api_get :show, :id => order.to_param
|
427
465
|
|
428
466
|
adjustment = json_response['line_items'].first['adjustments'].first
|
429
|
-
adjustment['label'].
|
430
|
-
adjustment['amount'].
|
467
|
+
expect(adjustment['label']).to eq("10% off!")
|
468
|
+
expect(adjustment['amount']).to eq("5.0")
|
431
469
|
end
|
432
470
|
|
433
471
|
it "lists payments source without gateway info" do
|
@@ -468,31 +506,31 @@ module Spree
|
|
468
506
|
|
469
507
|
it "returns available shipments for an order" do
|
470
508
|
api_get :show, :id => order.to_param
|
471
|
-
response.status.
|
472
|
-
json_response["shipments"].
|
509
|
+
expect(response.status).to eq(200)
|
510
|
+
expect(json_response["shipments"]).not_to be_empty
|
473
511
|
shipment = json_response["shipments"][0]
|
474
512
|
# Test for correct shipping method attributes
|
475
513
|
# Regression test for #3206
|
476
|
-
shipment["shipping_methods"].
|
514
|
+
expect(shipment["shipping_methods"]).not_to be_nil
|
477
515
|
json_shipping_method = shipment["shipping_methods"][0]
|
478
|
-
json_shipping_method["id"].
|
479
|
-
json_shipping_method["name"].
|
480
|
-
json_shipping_method["zones"].
|
481
|
-
json_shipping_method["shipping_categories"].
|
516
|
+
expect(json_shipping_method["id"]).to eq(shipping_method.id)
|
517
|
+
expect(json_shipping_method["name"]).to eq(shipping_method.name)
|
518
|
+
expect(json_shipping_method["zones"]).not_to be_empty
|
519
|
+
expect(json_shipping_method["shipping_categories"]).not_to be_empty
|
482
520
|
|
483
521
|
# Test for correct shipping rates attributes
|
484
522
|
# Regression test for #3206
|
485
|
-
shipment["shipping_rates"].
|
523
|
+
expect(shipment["shipping_rates"]).not_to be_nil
|
486
524
|
shipping_rate = shipment["shipping_rates"][0]
|
487
|
-
shipping_rate["name"].
|
488
|
-
shipping_rate["cost"].
|
489
|
-
shipping_rate["selected"].
|
490
|
-
shipping_rate["display_cost"].
|
525
|
+
expect(shipping_rate["name"]).to eq(json_shipping_method["name"])
|
526
|
+
expect(shipping_rate["cost"]).to eq("10.0")
|
527
|
+
expect(shipping_rate["selected"]).to be true
|
528
|
+
expect(shipping_rate["display_cost"]).to eq("$10.00")
|
491
529
|
|
492
|
-
shipment["stock_location_name"].
|
530
|
+
expect(shipment["stock_location_name"]).not_to be_blank
|
493
531
|
manifest_item = shipment["manifest"][0]
|
494
|
-
manifest_item["quantity"].
|
495
|
-
manifest_item["variant_id"].
|
532
|
+
expect(manifest_item["quantity"]).to eq(1)
|
533
|
+
expect(manifest_item["variant_id"]).to eq(order.line_items.first.variant_id)
|
496
534
|
end
|
497
535
|
end
|
498
536
|
end
|
@@ -505,7 +543,7 @@ module Spree
|
|
505
543
|
before { Spree::Order.delete_all }
|
506
544
|
it "still returns a root :orders key" do
|
507
545
|
api_get :index
|
508
|
-
json_response["orders"].
|
546
|
+
expect(json_response["orders"]).to eq([])
|
509
547
|
end
|
510
548
|
end
|
511
549
|
|
@@ -558,20 +596,20 @@ module Spree
|
|
558
596
|
|
559
597
|
it "can view all orders" do
|
560
598
|
api_get :index
|
561
|
-
json_response["orders"].first.
|
562
|
-
json_response["count"].
|
563
|
-
json_response["current_page"].
|
564
|
-
json_response["pages"].
|
599
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
600
|
+
expect(json_response["count"]).to eq(2)
|
601
|
+
expect(json_response["current_page"]).to eq(1)
|
602
|
+
expect(json_response["pages"]).to eq(1)
|
565
603
|
end
|
566
604
|
|
567
605
|
# Test for #1763
|
568
606
|
it "can control the page size through a parameter" do
|
569
607
|
api_get :index, :per_page => 1
|
570
|
-
json_response["orders"].count.
|
571
|
-
json_response["orders"].first.
|
572
|
-
json_response["count"].
|
573
|
-
json_response["current_page"].
|
574
|
-
json_response["pages"].
|
608
|
+
expect(json_response["orders"].count).to eq(1)
|
609
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
610
|
+
expect(json_response["count"]).to eq(1)
|
611
|
+
expect(json_response["current_page"]).to eq(1)
|
612
|
+
expect(json_response["pages"]).to eq(2)
|
575
613
|
end
|
576
614
|
end
|
577
615
|
|
@@ -585,21 +623,21 @@ module Spree
|
|
585
623
|
|
586
624
|
it "can query the results through a parameter" do
|
587
625
|
api_get :index, :q => { :email_cont => 'spree' }
|
588
|
-
json_response["orders"].count.
|
589
|
-
json_response["orders"].first.
|
590
|
-
json_response["orders"].first["email"].
|
591
|
-
json_response["count"].
|
592
|
-
json_response["current_page"].
|
593
|
-
json_response["pages"].
|
626
|
+
expect(json_response["orders"].count).to eq(1)
|
627
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
628
|
+
expect(json_response["orders"].first["email"]).to eq(expected_result.email)
|
629
|
+
expect(json_response["count"]).to eq(1)
|
630
|
+
expect(json_response["current_page"]).to eq(1)
|
631
|
+
expect(json_response["pages"]).to eq(1)
|
594
632
|
end
|
595
633
|
end
|
596
634
|
|
597
635
|
context "creation" do
|
598
636
|
it "can create an order without any parameters" do
|
599
|
-
|
600
|
-
response.status.
|
637
|
+
expect { api_post :create }.not_to raise_error
|
638
|
+
expect(response.status).to eq(201)
|
601
639
|
order = Order.last
|
602
|
-
json_response["state"].
|
640
|
+
expect(json_response["state"]).to eq("cart")
|
603
641
|
end
|
604
642
|
|
605
643
|
it "can arbitrarily set the line items price" do
|
@@ -618,7 +656,7 @@ module Spree
|
|
618
656
|
user = Spree.user_class.create
|
619
657
|
api_post :create, :order => { user_id: user.id }
|
620
658
|
expect(response.status).to eq 201
|
621
|
-
json_response["user_id"].
|
659
|
+
expect(json_response["user_id"]).to eq(user.id)
|
622
660
|
end
|
623
661
|
end
|
624
662
|
|
@@ -627,7 +665,7 @@ module Spree
|
|
627
665
|
user = Spree.user_class.create
|
628
666
|
api_post :update, :id => order.number, :order => { user_id: user.id }
|
629
667
|
expect(response.status).to eq 200
|
630
|
-
json_response["user_id"].
|
668
|
+
expect(json_response["user_id"]).to eq(user.id)
|
631
669
|
end
|
632
670
|
end
|
633
671
|
|
@@ -643,7 +681,7 @@ module Spree
|
|
643
681
|
|
644
682
|
specify do
|
645
683
|
api_put :cancel, :id => order.to_param
|
646
|
-
json_response["state"].
|
684
|
+
expect(json_response["state"]).to eq("canceled")
|
647
685
|
end
|
648
686
|
end
|
649
687
|
end
|