solidus_api 2.4.2 → 2.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +1 -5
- data/Rakefile +7 -8
- data/app/controllers/spree/api/line_items_controller.rb +1 -3
- data/app/controllers/spree/api/orders_controller.rb +1 -1
- data/app/controllers/spree/api/products_controller.rb +1 -1
- data/app/controllers/spree/api/shipments_controller.rb +21 -7
- data/app/controllers/spree/api/stock_items_controller.rb +4 -4
- data/app/controllers/spree/api/taxonomies_controller.rb +1 -0
- data/app/controllers/spree/api/taxons_controller.rb +1 -0
- data/app/controllers/spree/api/variants_controller.rb +13 -4
- data/app/helpers/spree/api/api_helpers.rb +0 -9
- data/app/views/spree/api/shared/_pagination.json.jbuilder +1 -1
- data/app/views/spree/api/shipments/estimated_rates.json.jbuilder +4 -0
- data/app/views/spree/api/variants/_big.json.jbuilder +0 -1
- data/app/views/spree/api/variants/_small.json.jbuilder +6 -1
- data/config/locales/en.yml +0 -6
- data/config/routes.rb +3 -7
- data/lib/spree/api/engine.rb +0 -10
- data/lib/spree_api.rb +0 -1
- data/solidus_api.gemspec +1 -2
- data/spec/controllers/spree/api/resource_controller_spec.rb +9 -9
- data/spec/features/checkout_spec.rb +8 -8
- data/spec/requests/api/address_books_spec.rb +1 -3
- data/spec/requests/spree/api/checkouts_controller_spec.rb +4 -5
- data/spec/requests/spree/api/config_controller_spec.rb +2 -2
- data/spec/requests/spree/api/orders_controller_spec.rb +27 -11
- data/spec/requests/spree/api/products_controller_spec.rb +1 -1
- data/spec/requests/spree/api/return_authorizations_controller_spec.rb +13 -13
- data/spec/requests/spree/api/shipments_controller_spec.rb +66 -4
- data/spec/requests/spree/api/stock_items_controller_spec.rb +4 -4
- data/spec/requests/spree/api/stock_locations_controller_spec.rb +7 -7
- data/spec/requests/spree/api/taxonomies_controller_spec.rb +1 -0
- data/spec/requests/spree/api/taxons_controller_spec.rb +3 -2
- data/spec/requests/spree/api/variants_controller_spec.rb +26 -0
- data/spec/spec_helper.rb +13 -23
- metadata +11 -41
- data/Gemfile +0 -5
- data/app/controllers/spree/api/stock_transfers_controller.rb +0 -20
- data/app/controllers/spree/api/transfer_items_controller.rb +0 -42
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +0 -1
- data/app/views/spree/api/stock_transfers/receive.json.jbuilder +0 -4
- data/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +0 -5
- data/app/views/spree/api/transfer_items/show.json.jbuilder +0 -1
- data/spec/requests/spree/api/stock_transfers_controller_spec.rb +0 -97
- data/spec/requests/spree/api/transfer_items_controller_spec.rb +0 -150
@@ -45,20 +45,20 @@ module Spree
|
|
45
45
|
|
46
46
|
it "does not include unpermitted params, or allow overriding the user" do
|
47
47
|
subject
|
48
|
-
expect(response).to
|
48
|
+
expect(response).to be_successful
|
49
49
|
order = Spree::Order.last
|
50
50
|
expect(order.user).to eq current_api_user
|
51
51
|
expect(order.email).to eq target_user.email
|
52
52
|
end
|
53
53
|
|
54
|
-
it { is_expected.to
|
54
|
+
it { is_expected.to be_successful }
|
55
55
|
|
56
56
|
context 'creating payment' do
|
57
57
|
let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
58
58
|
|
59
59
|
context "with allowed payment method" do
|
60
60
|
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
|
61
|
-
it { is_expected.to
|
61
|
+
it { is_expected.to be_successful }
|
62
62
|
it "creates a payment" do
|
63
63
|
expect {
|
64
64
|
subject
|
@@ -91,7 +91,7 @@ module Spree
|
|
91
91
|
expect(order.created_at).to eq date_override
|
92
92
|
end
|
93
93
|
|
94
|
-
it { is_expected.to
|
94
|
+
it { is_expected.to be_successful }
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'when the line items have custom attributes' do
|
@@ -126,7 +126,7 @@ module Spree
|
|
126
126
|
}.to change { order.reload.email }.to("foo@foobar.com")
|
127
127
|
end
|
128
128
|
|
129
|
-
it { is_expected.to
|
129
|
+
it { is_expected.to be_successful }
|
130
130
|
|
131
131
|
it "does not associate users" do
|
132
132
|
expect {
|
@@ -145,7 +145,7 @@ module Spree
|
|
145
145
|
|
146
146
|
context "with allowed payment method" do
|
147
147
|
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
|
148
|
-
it { is_expected.to
|
148
|
+
it { is_expected.to be_successful }
|
149
149
|
it "creates a payment" do
|
150
150
|
expect {
|
151
151
|
subject
|
@@ -269,7 +269,7 @@ module Spree
|
|
269
269
|
|
270
270
|
describe 'GET #show' do
|
271
271
|
let(:order) { create :order_with_line_items }
|
272
|
-
let(:adjustment) {
|
272
|
+
let(:adjustment) { FactoryBot.create(:adjustment, adjustable: order, order: order) }
|
273
273
|
|
274
274
|
subject { get spree.api_order_path(order) }
|
275
275
|
|
@@ -289,6 +289,22 @@ module Spree
|
|
289
289
|
end
|
290
290
|
end
|
291
291
|
|
292
|
+
context 'when an item does not track inventory' do
|
293
|
+
before do
|
294
|
+
order.line_items.first.variant.update_attributes!(track_inventory: false)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'contains stock information on variant' do
|
298
|
+
subject
|
299
|
+
variant = json_response['line_items'][0]['variant']
|
300
|
+
expect(variant).to_not be_nil
|
301
|
+
expect(variant['in_stock']).to eq(true)
|
302
|
+
expect(variant['total_on_hand']).to eq(nil)
|
303
|
+
expect(variant['is_backorderable']).to eq(true)
|
304
|
+
expect(variant['is_destroyed']).to eq(false)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
292
308
|
context 'when shipment adjustments are present' do
|
293
309
|
before do
|
294
310
|
order.shipments.first.adjustments << adjustment
|
@@ -541,7 +557,7 @@ module Spree
|
|
541
557
|
context "order has shipments" do
|
542
558
|
before { order.create_proposed_shipments }
|
543
559
|
|
544
|
-
it "clears out all existing shipments on line item
|
560
|
+
it "clears out all existing shipments on line item update" do
|
545
561
|
put spree.api_order_path(order), params: { order: {
|
546
562
|
line_items: {
|
547
563
|
0 => { id: line_item.id, quantity: 10 }
|
@@ -616,7 +632,7 @@ module Spree
|
|
616
632
|
|
617
633
|
context "when in delivery" do
|
618
634
|
let!(:shipping_method) do
|
619
|
-
|
635
|
+
FactoryBot.create(:shipping_method).tap do |shipping_method|
|
620
636
|
shipping_method.calculator.preferred_amount = 10
|
621
637
|
shipping_method.calculator.save
|
622
638
|
end
|
@@ -825,7 +841,7 @@ module Spree
|
|
825
841
|
expect(response.status).to eq 200
|
826
842
|
expect(order.reload.promotions).to eq [promo]
|
827
843
|
expect(json_response).to eq({
|
828
|
-
"success" =>
|
844
|
+
"success" => I18n.t('spree.coupon_code_applied'),
|
829
845
|
"error" => nil,
|
830
846
|
"successful" => true,
|
831
847
|
"status_code" => "coupon_code_applied"
|
@@ -843,7 +859,7 @@ module Spree
|
|
843
859
|
expect(order.reload.promotions).to eq []
|
844
860
|
expect(json_response).to eq({
|
845
861
|
"success" => nil,
|
846
|
-
"error" =>
|
862
|
+
"error" => I18n.t('spree.coupon_code_unknown_error'),
|
847
863
|
"successful" => false,
|
848
864
|
"status_code" => "coupon_code_unknown_error"
|
849
865
|
})
|
@@ -178,7 +178,7 @@ module Spree
|
|
178
178
|
specify do
|
179
179
|
get spree.api_product_path(product)
|
180
180
|
expect(json_response["slug"]).to match(/and-1-ways/)
|
181
|
-
product.
|
181
|
+
product.discard
|
182
182
|
|
183
183
|
get spree.api_product_path(other_product)
|
184
184
|
expect(json_response["slug"]).to match(/droids/)
|
@@ -14,8 +14,8 @@ module Spree
|
|
14
14
|
|
15
15
|
shared_examples_for 'a return authorization creator' do
|
16
16
|
it "can create a new return authorization" do
|
17
|
-
stock_location =
|
18
|
-
reason =
|
17
|
+
stock_location = FactoryBot.create(:stock_location)
|
18
|
+
reason = FactoryBot.create(:return_reason)
|
19
19
|
rma_params = { stock_location_id: stock_location.id,
|
20
20
|
return_reason_id: reason.id,
|
21
21
|
memo: "Defective" }
|
@@ -74,7 +74,7 @@ module Spree
|
|
74
74
|
sign_in_as_admin!
|
75
75
|
|
76
76
|
it "can show return authorization" do
|
77
|
-
|
77
|
+
FactoryBot.create(:return_authorization, order: order)
|
78
78
|
return_authorization = order.return_authorizations.first
|
79
79
|
get spree.api_order_return_authorization_path(order, return_authorization.id)
|
80
80
|
expect(response.status).to eq(200)
|
@@ -83,8 +83,8 @@ module Spree
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "can get a list of return authorizations" do
|
86
|
-
|
87
|
-
|
86
|
+
FactoryBot.create(:return_authorization, order: order)
|
87
|
+
FactoryBot.create(:return_authorization, order: order)
|
88
88
|
get spree.api_order_return_authorizations_path(order), params: { order_id: order.number }
|
89
89
|
expect(response.status).to eq(200)
|
90
90
|
return_authorizations = json_response["return_authorizations"]
|
@@ -93,8 +93,8 @@ module Spree
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'can control the page size through a parameter' do
|
96
|
-
|
97
|
-
|
96
|
+
FactoryBot.create(:return_authorization, order: order)
|
97
|
+
FactoryBot.create(:return_authorization, order: order)
|
98
98
|
get spree.api_order_return_authorizations_path(order), params: { order_id: order.number, per_page: 1 }
|
99
99
|
expect(json_response['count']).to eq(1)
|
100
100
|
expect(json_response['current_page']).to eq(1)
|
@@ -102,7 +102,7 @@ module Spree
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'can query the results through a paramter' do
|
105
|
-
|
105
|
+
FactoryBot.create(:return_authorization, order: order)
|
106
106
|
expected_result = create(:return_authorization, memo: 'damaged')
|
107
107
|
order.return_authorizations << expected_result
|
108
108
|
get spree.api_order_return_authorizations_path(order), params: { q: { memo_cont: 'damaged' } }
|
@@ -118,7 +118,7 @@ module Spree
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it "can update a return authorization on the order" do
|
121
|
-
|
121
|
+
FactoryBot.create(:return_authorization, order: order)
|
122
122
|
return_authorization = order.return_authorizations.first
|
123
123
|
put spree.api_order_return_authorization_path(order, return_authorization.id), params: { return_authorization: { memo: "ABC" } }
|
124
124
|
expect(response.status).to eq(200)
|
@@ -126,7 +126,7 @@ module Spree
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can cancel a return authorization on the order" do
|
129
|
-
|
129
|
+
FactoryBot.create(:new_return_authorization, order: order)
|
130
130
|
return_authorization = order.return_authorizations.first
|
131
131
|
expect(return_authorization.state).to eq("authorized")
|
132
132
|
put spree.cancel_api_order_return_authorization_path(order, return_authorization.id)
|
@@ -135,7 +135,7 @@ module Spree
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "can delete a return authorization on the order" do
|
138
|
-
|
138
|
+
FactoryBot.create(:return_authorization, order: order)
|
139
139
|
return_authorization = order.return_authorizations.first
|
140
140
|
delete spree.api_order_return_authorization_path(order, return_authorization.id)
|
141
141
|
expect(response.status).to eq(204)
|
@@ -152,7 +152,7 @@ module Spree
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "cannot update a return authorization on the order" do
|
155
|
-
|
155
|
+
FactoryBot.create(:return_authorization, order: order)
|
156
156
|
return_authorization = order.return_authorizations.first
|
157
157
|
put spree.api_order_return_authorization_path(order, return_authorization.id), params: { return_authorization: { memo: "ABC" } }
|
158
158
|
assert_unauthorized!
|
@@ -160,7 +160,7 @@ module Spree
|
|
160
160
|
end
|
161
161
|
|
162
162
|
it "cannot delete a return authorization on the order" do
|
163
|
-
|
163
|
+
FactoryBot.create(:return_authorization, order: order)
|
164
164
|
return_authorization = order.return_authorizations.first
|
165
165
|
delete spree.api_order_return_authorization_path(order, return_authorization.id)
|
166
166
|
assert_unauthorized!
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::Api::ShipmentsController, type: :request do
|
4
|
+
include ActiveSupport::Testing::TimeHelpers
|
5
|
+
|
4
6
|
let!(:shipment) { create(:shipment, inventory_units: [build(:inventory_unit, shipment: nil)]) }
|
5
7
|
let!(:attributes) { [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
|
6
8
|
|
@@ -126,7 +128,7 @@ describe Spree::Api::ShipmentsController, type: :request do
|
|
126
128
|
|
127
129
|
it 'removes a destroyed variant from a shipment' do
|
128
130
|
order.contents.add(variant, 2)
|
129
|
-
variant.
|
131
|
+
variant.discard
|
130
132
|
|
131
133
|
put spree.remove_api_shipment_path(shipment), params: { variant_id: variant.to_param, quantity: 1 }
|
132
134
|
expect(response.status).to eq(200)
|
@@ -134,6 +136,23 @@ describe Spree::Api::ShipmentsController, type: :request do
|
|
134
136
|
end
|
135
137
|
end
|
136
138
|
|
139
|
+
context 'for ready shipments' do
|
140
|
+
let(:order) { create :order_ready_to_ship, line_items_attributes: [{ variant: variant, quantity: 1 }] }
|
141
|
+
let(:shipment) { order.shipments.first }
|
142
|
+
|
143
|
+
it 'adds a variant to a shipment' do
|
144
|
+
put spree.add_api_shipment_path(shipment), params: { variant_id: variant.to_param, quantity: 1 }
|
145
|
+
expect(response.status).to eq(200)
|
146
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }['quantity']).to eq(2)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'removes a variant from a shipment' do
|
150
|
+
put spree.remove_api_shipment_path(shipment), params: { variant_id: variant.to_param, quantity: 1 }
|
151
|
+
expect(response.status).to eq(200)
|
152
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }).to be nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
137
156
|
context "for shipped shipments" do
|
138
157
|
let(:order) { create :shipped_order }
|
139
158
|
let(:shipment) { order.shipments.first }
|
@@ -218,6 +237,48 @@ describe Spree::Api::ShipmentsController, type: :request do
|
|
218
237
|
end
|
219
238
|
end
|
220
239
|
|
240
|
+
describe "#estimated_rates" do
|
241
|
+
let!(:user_shipping_method) { shipment.shipping_method }
|
242
|
+
let!(:admin_shipping_method) { create(:shipping_method, available_to_users: false, name: "Secret") }
|
243
|
+
|
244
|
+
sign_in_as_admin!
|
245
|
+
|
246
|
+
subject do
|
247
|
+
get spree.estimated_rates_api_shipment_path(shipment)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "returns success" do
|
251
|
+
subject
|
252
|
+
expect(response).to be_success
|
253
|
+
end
|
254
|
+
|
255
|
+
it "returns rates available to user" do
|
256
|
+
subject
|
257
|
+
expect(json_response['shipping_rates']).to include(
|
258
|
+
{
|
259
|
+
"name" => user_shipping_method.name,
|
260
|
+
"cost" => "100.0",
|
261
|
+
"shipping_method_id" => user_shipping_method.id,
|
262
|
+
"shipping_method_code" => user_shipping_method.code,
|
263
|
+
"display_cost" => "$100.00"
|
264
|
+
}
|
265
|
+
)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "returns rates available to admin" do
|
269
|
+
subject
|
270
|
+
expect(json_response['shipping_rates']).to include(
|
271
|
+
{
|
272
|
+
"name" => admin_shipping_method.name,
|
273
|
+
"cost" => "10.0",
|
274
|
+
"shipping_method_id" => admin_shipping_method.id,
|
275
|
+
"shipping_method_code" => admin_shipping_method.code,
|
276
|
+
"display_cost" => "$10.00"
|
277
|
+
}
|
278
|
+
)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
221
282
|
describe "#ship" do
|
222
283
|
let(:shipment) { create(:order_ready_to_ship).shipments.first }
|
223
284
|
|
@@ -230,11 +291,12 @@ describe Spree::Api::ShipmentsController, type: :request do
|
|
230
291
|
context "the user is allowed to ship the shipment" do
|
231
292
|
sign_in_as_admin!
|
232
293
|
it "ships the shipment" do
|
233
|
-
|
294
|
+
now = Time.current
|
295
|
+
travel_to(now) do
|
234
296
|
subject
|
235
297
|
shipment.reload
|
236
298
|
expect(shipment.state).to eq 'shipped'
|
237
|
-
expect(shipment.shipped_at.to_i).to eq
|
299
|
+
expect(shipment.shipped_at.to_i).to eq now.to_i
|
238
300
|
end
|
239
301
|
end
|
240
302
|
|
@@ -348,7 +410,7 @@ describe Spree::Api::ShipmentsController, type: :request do
|
|
348
410
|
|
349
411
|
it "returns the correct message" do
|
350
412
|
subject
|
351
|
-
expect(response).to
|
413
|
+
expect(response).to be_successful
|
352
414
|
expect(parsed_response["success"]).to be true
|
353
415
|
expect(parsed_response["message"]).to eq("Variants successfully transferred")
|
354
416
|
end
|
@@ -18,7 +18,7 @@ module Spree
|
|
18
18
|
describe "#index" do
|
19
19
|
it "can list stock items for an active stock location" do
|
20
20
|
get spree.api_stock_location_stock_items_path(stock_location)
|
21
|
-
expect(response).to
|
21
|
+
expect(response).to be_successful
|
22
22
|
expect(json_response['stock_items'].first).to have_attributes(attributes)
|
23
23
|
expect(json_response['stock_items'].first['variant']['sku']).to match /\ASKU-\d+\z/
|
24
24
|
end
|
@@ -169,7 +169,7 @@ module Spree
|
|
169
169
|
it "does not allow negative inventory for the stock item" do
|
170
170
|
subject
|
171
171
|
expect(response.status).to eq 422
|
172
|
-
expect(response.body).to match
|
172
|
+
expect(response.body).to match I18n.t('spree.stock_not_below_zero')
|
173
173
|
expect(assigns(:stock_item).count_on_hand).to eq 0
|
174
174
|
end
|
175
175
|
end
|
@@ -235,7 +235,7 @@ module Spree
|
|
235
235
|
it "does not allow negative inventory for the stock item" do
|
236
236
|
subject
|
237
237
|
expect(response.status).to eq 422
|
238
|
-
expect(response.body).to match
|
238
|
+
expect(response.body).to match I18n.t('spree.stock_not_below_zero')
|
239
239
|
expect(assigns(:stock_item).count_on_hand).to eq 10
|
240
240
|
end
|
241
241
|
end
|
@@ -293,7 +293,7 @@ module Spree
|
|
293
293
|
it "does not allow negative inventory for the stock item" do
|
294
294
|
subject
|
295
295
|
expect(response.status).to eq 422
|
296
|
-
expect(response.body).to match
|
296
|
+
expect(response.body).to match I18n.t('spree.stock_not_below_zero')
|
297
297
|
expect(assigns(:stock_item).count_on_hand).to eq 10
|
298
298
|
end
|
299
299
|
end
|
@@ -14,7 +14,7 @@ module Spree
|
|
14
14
|
describe "#index" do
|
15
15
|
it "can see active stock locations" do
|
16
16
|
get spree.api_stock_locations_path
|
17
|
-
expect(response).to
|
17
|
+
expect(response).to be_successful
|
18
18
|
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
19
19
|
expect(stock_locations).to include stock_location.name
|
20
20
|
end
|
@@ -22,7 +22,7 @@ module Spree
|
|
22
22
|
it "cannot see inactive stock locations" do
|
23
23
|
stock_location.update_attributes!(active: false)
|
24
24
|
get spree.api_stock_locations_path
|
25
|
-
expect(response).to
|
25
|
+
expect(response).to be_successful
|
26
26
|
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
27
27
|
expect(stock_locations).not_to include stock_location.name
|
28
28
|
end
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
describe "#show" do
|
32
32
|
it "can see active stock locations" do
|
33
33
|
get spree.api_stock_location_path(stock_location)
|
34
|
-
expect(response).to
|
34
|
+
expect(response).to be_successful
|
35
35
|
expect(json_response['name']).to eq stock_location.name
|
36
36
|
end
|
37
37
|
|
@@ -77,7 +77,7 @@ module Spree
|
|
77
77
|
describe "#index" do
|
78
78
|
it "can see active stock locations" do
|
79
79
|
get spree.api_stock_locations_path
|
80
|
-
expect(response).to
|
80
|
+
expect(response).to be_successful
|
81
81
|
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
82
82
|
expect(stock_locations).to include stock_location.name
|
83
83
|
end
|
@@ -85,7 +85,7 @@ module Spree
|
|
85
85
|
it "can see inactive stock locations" do
|
86
86
|
stock_location.update_attributes!(active: false)
|
87
87
|
get spree.api_stock_locations_path
|
88
|
-
expect(response).to
|
88
|
+
expect(response).to be_successful
|
89
89
|
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
90
90
|
expect(stock_locations).to include stock_location.name
|
91
91
|
end
|
@@ -116,14 +116,14 @@ module Spree
|
|
116
116
|
describe "#show" do
|
117
117
|
it "can see active stock locations" do
|
118
118
|
get spree.api_stock_location_path(stock_location)
|
119
|
-
expect(response).to
|
119
|
+
expect(response).to be_successful
|
120
120
|
expect(json_response['name']).to eq stock_location.name
|
121
121
|
end
|
122
122
|
|
123
123
|
it "can see inactive stock locations" do
|
124
124
|
stock_location.update_attributes!(active: false)
|
125
125
|
get spree.api_stock_location_path(stock_location)
|
126
|
-
expect(response).to
|
126
|
+
expect(response).to be_successful
|
127
127
|
expect(json_response['name']).to eq stock_location.name
|
128
128
|
end
|
129
129
|
end
|
@@ -59,6 +59,7 @@ module Spree
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "gets the jstree-friendly version of a taxonomy" do
|
62
|
+
expect(Spree::Deprecation).to(receive(:warn))
|
62
63
|
get spree.jstree_api_taxonomy_path(taxonomy.id)
|
63
64
|
expect(json_response["data"]).to eq(taxonomy.root.name)
|
64
65
|
expect(json_response["attr"]).to eq({ "id" => taxonomy.root.id, "name" => taxonomy.root.name })
|
@@ -92,6 +92,7 @@ module Spree
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "gets all taxons in JSTree form" do
|
95
|
+
expect(Spree::Deprecation).to(receive(:warn))
|
95
96
|
get spree.jstree_api_taxonomy_taxon_path(taxonomy, taxon.id)
|
96
97
|
response = json_response.first
|
97
98
|
expect(response["data"]).to eq(taxon2.name)
|
@@ -130,11 +131,11 @@ module Spree
|
|
130
131
|
|
131
132
|
it "handles exclude_data correctly" do
|
132
133
|
get spree.api_taxon_products_path, params: { id: taxon.id, simple: true }
|
133
|
-
expect(response).to
|
134
|
+
expect(response).to be_successful
|
134
135
|
simple_response = json_response
|
135
136
|
|
136
137
|
get spree.api_taxon_products_path, params: { id: taxon.id }
|
137
|
-
expect(response).to
|
138
|
+
expect(response).to be_successful
|
138
139
|
full_response = json_response
|
139
140
|
|
140
141
|
expect(simple_response["products"][0]["description"]).to be_nil
|
@@ -114,6 +114,32 @@ module Spree
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
context "only suplliable variants" do
|
118
|
+
subject { get spree.api_variants_path, params: { suppliable_only: "true" } }
|
119
|
+
|
120
|
+
context "variant is backorderable" do
|
121
|
+
before do
|
122
|
+
variant.stock_items.update_all(count_on_hand: 0, backorderable: true)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "is not returned in the results" do
|
126
|
+
subject
|
127
|
+
expect(json_response["variants"].count).to eq 1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "variant is unsuppliable" do
|
132
|
+
before do
|
133
|
+
variant.stock_items.update_all(count_on_hand: 0, backorderable: false)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "is returned in the results" do
|
137
|
+
subject
|
138
|
+
expect(json_response["variants"].count).to eq 0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
117
143
|
context "all variants" do
|
118
144
|
subject { get spree.api_variants_path, params: { in_stock_only: "false" } }
|
119
145
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
1
|
if ENV["COVERAGE"]
|
2
|
-
# Run Coverage report
|
3
2
|
require 'simplecov'
|
4
|
-
SimpleCov.start
|
5
|
-
add_group 'Controllers', 'app/controllers'
|
6
|
-
add_group 'Helpers', 'app/helpers'
|
7
|
-
add_group 'Mailers', 'app/mailers'
|
8
|
-
add_group 'Models', 'app/models'
|
9
|
-
add_group 'Views', 'app/views'
|
10
|
-
add_group 'Libraries', 'lib'
|
11
|
-
end
|
3
|
+
SimpleCov.start('rails')
|
12
4
|
end
|
13
5
|
|
14
6
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
15
7
|
ENV["RAILS_ENV"] ||= 'test'
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
require 'solidus_api'
|
10
|
+
require 'spree/testing_support/dummy_app'
|
11
|
+
DummyApp.setup(
|
12
|
+
gem_root: File.expand_path('../../', __FILE__),
|
13
|
+
lib_name: 'solidus_api'
|
14
|
+
)
|
23
15
|
|
16
|
+
require 'rails-controller-testing'
|
24
17
|
require 'rspec/rails'
|
25
|
-
require '
|
18
|
+
require 'rspec-activemodel-mocks'
|
19
|
+
|
20
|
+
require 'database_cleaner'
|
21
|
+
require 'with_model'
|
26
22
|
|
27
23
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
28
24
|
# in spec/support/ and its subdirectories.
|
@@ -49,7 +45,7 @@ RSpec.configure do |config|
|
|
49
45
|
c.syntax = :expect
|
50
46
|
end
|
51
47
|
|
52
|
-
config.include
|
48
|
+
config.include FactoryBot::Syntax::Methods
|
53
49
|
config.include Spree::Api::TestingSupport::Helpers, type: :request
|
54
50
|
config.extend Spree::Api::TestingSupport::Setup, type: :request
|
55
51
|
config.include Spree::Api::TestingSupport::Helpers, type: :controller
|
@@ -58,8 +54,6 @@ RSpec.configure do |config|
|
|
58
54
|
|
59
55
|
config.extend WithModel
|
60
56
|
|
61
|
-
config.fail_fast = ENV['FAIL_FAST'] || false
|
62
|
-
|
63
57
|
config.before(:each) do
|
64
58
|
Rails.cache.clear
|
65
59
|
reset_spree_preferences
|
@@ -67,10 +61,6 @@ RSpec.configure do |config|
|
|
67
61
|
end
|
68
62
|
|
69
63
|
config.include ActiveJob::TestHelper
|
70
|
-
config.include VersionCake::TestHelpers, type: :controller
|
71
|
-
config.before(:each, type: :controller) do
|
72
|
-
set_request_version('', 1)
|
73
|
-
end
|
74
64
|
|
75
65
|
config.use_transactional_fixtures = true
|
76
66
|
|