solidus_api 2.2.2 → 2.3.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 +4 -4
- data/app/controllers/spree/api/images_controller.rb +2 -2
- data/app/controllers/spree/api/line_items_controller.rb +2 -10
- data/app/controllers/spree/api/orders_controller.rb +2 -12
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/app/controllers/spree/api/promotions_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +2 -1
- data/app/views/spree/api/orders/show.v1.rabl +2 -1
- data/lib/spree/api/testing_support/setup.rb +1 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +7 -7
- data/spec/controllers/spree/api/resource_controller_spec.rb +16 -16
- data/spec/requests/api/address_books_spec.rb +1 -1
- data/spec/{controllers → requests}/spree/api/addresses_controller_spec.rb +6 -9
- data/spec/{controllers → requests}/spree/api/checkouts_controller_spec.rb +38 -69
- data/spec/{controllers → requests}/spree/api/classifications_controller_spec.rb +4 -4
- data/spec/{controllers → requests}/spree/api/config_controller_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/countries_controller_spec.rb +6 -7
- data/spec/{controllers → requests}/spree/api/credit_cards_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/images_controller_spec.rb +19 -16
- data/spec/{controllers → requests}/spree/api/inventory_units_controller_spec.rb +17 -14
- data/spec/{controllers → requests}/spree/api/line_items_controller_spec.rb +32 -32
- data/spec/{controllers → requests}/spree/api/option_types_controller_spec.rb +27 -27
- data/spec/{controllers → requests}/spree/api/option_values_controller_spec.rb +32 -29
- data/spec/{controllers → requests}/spree/api/orders_controller_spec.rb +103 -133
- data/spec/{controllers → requests}/spree/api/payments_controller_spec.rb +30 -44
- data/spec/{controllers → requests}/spree/api/product_properties_controller_spec.rb +15 -17
- data/spec/{controllers → requests}/spree/api/products_controller_spec.rb +44 -43
- data/spec/{controllers → requests}/spree/api/promotion_application_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/promotions_controller_spec.rb +8 -6
- data/spec/{controllers → requests}/spree/api/properties_controller_spec.rb +15 -16
- data/spec/{controllers → requests}/spree/api/return_authorizations_controller_spec.rb +19 -21
- data/spec/requests/spree/api/shipments_controller_spec.rb +394 -88
- data/spec/{controllers → requests}/spree/api/states_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/stock_items_controller_spec.rb +21 -21
- data/spec/{controllers → requests}/spree/api/stock_locations_controller_spec.rb +18 -20
- data/spec/{controllers → requests}/spree/api/stock_movements_controller_spec.rb +9 -12
- data/spec/{controllers → requests}/spree/api/stock_transfers_controller_spec.rb +2 -3
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +57 -0
- data/spec/{controllers → requests}/spree/api/stores_controller_spec.rb +19 -20
- data/spec/{controllers → requests}/spree/api/taxonomies_controller_spec.rb +14 -15
- data/spec/{controllers → requests}/spree/api/taxons_controller_spec.rb +17 -18
- data/spec/{controllers → requests}/spree/api/transfer_items_controller_spec.rb +7 -9
- data/spec/{controllers → requests}/spree/api/unauthenticated_products_controller_spec.rb +2 -3
- data/spec/{controllers → requests}/spree/api/users_controller_spec.rb +18 -19
- data/spec/{controllers → requests}/spree/api/variants_controller_spec.rb +70 -37
- data/spec/{controllers → requests}/spree/api/zones_controller_spec.rb +13 -14
- data/spec/shared_examples/protect_product_actions.rb +3 -3
- data/spec/spec_helper.rb +4 -1
- metadata +70 -72
- data/spec/controllers/spree/api/shipments_controller_spec.rb +0 -301
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -66
@@ -1,16 +1,16 @@
|
|
1
1
|
shared_examples "modifying product actions are restricted" do
|
2
2
|
it "cannot create a new product if not an admin" do
|
3
|
-
|
3
|
+
post spree.api_products_path, params: { product: { name: "Brand new product!" } }
|
4
4
|
assert_unauthorized!
|
5
5
|
end
|
6
6
|
|
7
7
|
it "cannot update a product" do
|
8
|
-
|
8
|
+
put spree.api_product_path(product), params: { product: { name: "I hacked your store!" } }
|
9
9
|
assert_unauthorized!
|
10
10
|
end
|
11
11
|
|
12
12
|
it "cannot delete a product" do
|
13
|
-
|
13
|
+
delete spree.api_product_path(product)
|
14
14
|
assert_unauthorized!
|
15
15
|
end
|
16
16
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -36,7 +36,7 @@ require 'spree/api/testing_support/caching'
|
|
36
36
|
require 'spree/api/testing_support/helpers'
|
37
37
|
require 'spree/api/testing_support/setup'
|
38
38
|
|
39
|
-
ActiveJob::Base.queue_adapter = :
|
39
|
+
ActiveJob::Base.queue_adapter = :test
|
40
40
|
|
41
41
|
RSpec.configure do |config|
|
42
42
|
config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]
|
@@ -50,6 +50,8 @@ RSpec.configure do |config|
|
|
50
50
|
end
|
51
51
|
|
52
52
|
config.include FactoryGirl::Syntax::Methods
|
53
|
+
config.include Spree::Api::TestingSupport::Helpers, type: :request
|
54
|
+
config.extend Spree::Api::TestingSupport::Setup, type: :request
|
53
55
|
config.include Spree::Api::TestingSupport::Helpers, type: :controller
|
54
56
|
config.extend Spree::Api::TestingSupport::Setup, type: :controller
|
55
57
|
config.include Spree::TestingSupport::Preferences
|
@@ -64,6 +66,7 @@ RSpec.configure do |config|
|
|
64
66
|
Spree::Api::Config[:requires_authentication] = true
|
65
67
|
end
|
66
68
|
|
69
|
+
config.include ActiveJob::TestHelper
|
67
70
|
config.include VersionCake::TestHelpers, type: :controller
|
68
71
|
config.before(:each, type: :controller) do
|
69
72
|
set_request_version('', 1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.3.0.beta1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.3.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,49 +210,48 @@ files:
|
|
210
210
|
- lib/spree_api.rb
|
211
211
|
- script/rails
|
212
212
|
- solidus_api.gemspec
|
213
|
-
- spec/controllers/spree/api/addresses_controller_spec.rb
|
214
213
|
- spec/controllers/spree/api/base_controller_spec.rb
|
215
|
-
- spec/controllers/spree/api/checkouts_controller_spec.rb
|
216
|
-
- spec/controllers/spree/api/classifications_controller_spec.rb
|
217
|
-
- spec/controllers/spree/api/config_controller_spec.rb
|
218
|
-
- spec/controllers/spree/api/countries_controller_spec.rb
|
219
|
-
- spec/controllers/spree/api/credit_cards_controller_spec.rb
|
220
|
-
- spec/controllers/spree/api/images_controller_spec.rb
|
221
|
-
- spec/controllers/spree/api/inventory_units_controller_spec.rb
|
222
|
-
- spec/controllers/spree/api/line_items_controller_spec.rb
|
223
|
-
- spec/controllers/spree/api/option_types_controller_spec.rb
|
224
|
-
- spec/controllers/spree/api/option_values_controller_spec.rb
|
225
|
-
- spec/controllers/spree/api/orders_controller_spec.rb
|
226
|
-
- spec/controllers/spree/api/payments_controller_spec.rb
|
227
|
-
- spec/controllers/spree/api/product_properties_controller_spec.rb
|
228
|
-
- spec/controllers/spree/api/products_controller_spec.rb
|
229
|
-
- spec/controllers/spree/api/promotion_application_spec.rb
|
230
|
-
- spec/controllers/spree/api/promotions_controller_spec.rb
|
231
|
-
- spec/controllers/spree/api/properties_controller_spec.rb
|
232
214
|
- spec/controllers/spree/api/resource_controller_spec.rb
|
233
|
-
- spec/controllers/spree/api/return_authorizations_controller_spec.rb
|
234
|
-
- spec/controllers/spree/api/shipments_controller_spec.rb
|
235
|
-
- spec/controllers/spree/api/states_controller_spec.rb
|
236
|
-
- spec/controllers/spree/api/stock_items_controller_spec.rb
|
237
|
-
- spec/controllers/spree/api/stock_locations_controller_spec.rb
|
238
|
-
- spec/controllers/spree/api/stock_movements_controller_spec.rb
|
239
|
-
- spec/controllers/spree/api/stock_transfers_controller_spec.rb
|
240
|
-
- spec/controllers/spree/api/store_credit_events_controller_spec.rb
|
241
|
-
- spec/controllers/spree/api/stores_controller_spec.rb
|
242
|
-
- spec/controllers/spree/api/taxonomies_controller_spec.rb
|
243
|
-
- spec/controllers/spree/api/taxons_controller_spec.rb
|
244
|
-
- spec/controllers/spree/api/transfer_items_controller_spec.rb
|
245
|
-
- spec/controllers/spree/api/unauthenticated_products_controller_spec.rb
|
246
|
-
- spec/controllers/spree/api/users_controller_spec.rb
|
247
|
-
- spec/controllers/spree/api/variants_controller_spec.rb
|
248
|
-
- spec/controllers/spree/api/zones_controller_spec.rb
|
249
215
|
- spec/features/checkout_spec.rb
|
250
216
|
- spec/fixtures/thinking-cat.jpg
|
251
217
|
- spec/models/spree/legacy_user_spec.rb
|
252
218
|
- spec/requests/api/address_books_spec.rb
|
253
219
|
- spec/requests/rabl_cache_spec.rb
|
254
220
|
- spec/requests/ransackable_attributes_spec.rb
|
221
|
+
- spec/requests/spree/api/addresses_controller_spec.rb
|
222
|
+
- spec/requests/spree/api/checkouts_controller_spec.rb
|
223
|
+
- spec/requests/spree/api/classifications_controller_spec.rb
|
224
|
+
- spec/requests/spree/api/config_controller_spec.rb
|
225
|
+
- spec/requests/spree/api/countries_controller_spec.rb
|
226
|
+
- spec/requests/spree/api/credit_cards_controller_spec.rb
|
227
|
+
- spec/requests/spree/api/images_controller_spec.rb
|
228
|
+
- spec/requests/spree/api/inventory_units_controller_spec.rb
|
229
|
+
- spec/requests/spree/api/line_items_controller_spec.rb
|
230
|
+
- spec/requests/spree/api/option_types_controller_spec.rb
|
231
|
+
- spec/requests/spree/api/option_values_controller_spec.rb
|
232
|
+
- spec/requests/spree/api/orders_controller_spec.rb
|
233
|
+
- spec/requests/spree/api/payments_controller_spec.rb
|
234
|
+
- spec/requests/spree/api/product_properties_controller_spec.rb
|
235
|
+
- spec/requests/spree/api/products_controller_spec.rb
|
236
|
+
- spec/requests/spree/api/promotion_application_spec.rb
|
237
|
+
- spec/requests/spree/api/promotions_controller_spec.rb
|
238
|
+
- spec/requests/spree/api/properties_controller_spec.rb
|
239
|
+
- spec/requests/spree/api/return_authorizations_controller_spec.rb
|
255
240
|
- spec/requests/spree/api/shipments_controller_spec.rb
|
241
|
+
- spec/requests/spree/api/states_controller_spec.rb
|
242
|
+
- spec/requests/spree/api/stock_items_controller_spec.rb
|
243
|
+
- spec/requests/spree/api/stock_locations_controller_spec.rb
|
244
|
+
- spec/requests/spree/api/stock_movements_controller_spec.rb
|
245
|
+
- spec/requests/spree/api/stock_transfers_controller_spec.rb
|
246
|
+
- spec/requests/spree/api/store_credit_events_controller_spec.rb
|
247
|
+
- spec/requests/spree/api/stores_controller_spec.rb
|
248
|
+
- spec/requests/spree/api/taxonomies_controller_spec.rb
|
249
|
+
- spec/requests/spree/api/taxons_controller_spec.rb
|
250
|
+
- spec/requests/spree/api/transfer_items_controller_spec.rb
|
251
|
+
- spec/requests/spree/api/unauthenticated_products_controller_spec.rb
|
252
|
+
- spec/requests/spree/api/users_controller_spec.rb
|
253
|
+
- spec/requests/spree/api/variants_controller_spec.rb
|
254
|
+
- spec/requests/spree/api/zones_controller_spec.rb
|
256
255
|
- spec/shared_examples/protect_product_actions.rb
|
257
256
|
- spec/spec_helper.rb
|
258
257
|
- spec/support/controller_hacks.rb
|
@@ -286,49 +285,48 @@ signing_key:
|
|
286
285
|
specification_version: 4
|
287
286
|
summary: REST API for the Solidus e-commerce framework.
|
288
287
|
test_files:
|
289
|
-
- spec/controllers/spree/api/addresses_controller_spec.rb
|
290
288
|
- spec/controllers/spree/api/base_controller_spec.rb
|
291
|
-
- spec/controllers/spree/api/checkouts_controller_spec.rb
|
292
|
-
- spec/controllers/spree/api/classifications_controller_spec.rb
|
293
|
-
- spec/controllers/spree/api/config_controller_spec.rb
|
294
|
-
- spec/controllers/spree/api/countries_controller_spec.rb
|
295
|
-
- spec/controllers/spree/api/credit_cards_controller_spec.rb
|
296
|
-
- spec/controllers/spree/api/images_controller_spec.rb
|
297
|
-
- spec/controllers/spree/api/inventory_units_controller_spec.rb
|
298
|
-
- spec/controllers/spree/api/line_items_controller_spec.rb
|
299
|
-
- spec/controllers/spree/api/option_types_controller_spec.rb
|
300
|
-
- spec/controllers/spree/api/option_values_controller_spec.rb
|
301
|
-
- spec/controllers/spree/api/orders_controller_spec.rb
|
302
|
-
- spec/controllers/spree/api/payments_controller_spec.rb
|
303
|
-
- spec/controllers/spree/api/product_properties_controller_spec.rb
|
304
|
-
- spec/controllers/spree/api/products_controller_spec.rb
|
305
|
-
- spec/controllers/spree/api/promotion_application_spec.rb
|
306
|
-
- spec/controllers/spree/api/promotions_controller_spec.rb
|
307
|
-
- spec/controllers/spree/api/properties_controller_spec.rb
|
308
289
|
- spec/controllers/spree/api/resource_controller_spec.rb
|
309
|
-
- spec/controllers/spree/api/return_authorizations_controller_spec.rb
|
310
|
-
- spec/controllers/spree/api/shipments_controller_spec.rb
|
311
|
-
- spec/controllers/spree/api/states_controller_spec.rb
|
312
|
-
- spec/controllers/spree/api/stock_items_controller_spec.rb
|
313
|
-
- spec/controllers/spree/api/stock_locations_controller_spec.rb
|
314
|
-
- spec/controllers/spree/api/stock_movements_controller_spec.rb
|
315
|
-
- spec/controllers/spree/api/stock_transfers_controller_spec.rb
|
316
|
-
- spec/controllers/spree/api/store_credit_events_controller_spec.rb
|
317
|
-
- spec/controllers/spree/api/stores_controller_spec.rb
|
318
|
-
- spec/controllers/spree/api/taxonomies_controller_spec.rb
|
319
|
-
- spec/controllers/spree/api/taxons_controller_spec.rb
|
320
|
-
- spec/controllers/spree/api/transfer_items_controller_spec.rb
|
321
|
-
- spec/controllers/spree/api/unauthenticated_products_controller_spec.rb
|
322
|
-
- spec/controllers/spree/api/users_controller_spec.rb
|
323
|
-
- spec/controllers/spree/api/variants_controller_spec.rb
|
324
|
-
- spec/controllers/spree/api/zones_controller_spec.rb
|
325
290
|
- spec/features/checkout_spec.rb
|
326
291
|
- spec/fixtures/thinking-cat.jpg
|
327
292
|
- spec/models/spree/legacy_user_spec.rb
|
328
293
|
- spec/requests/api/address_books_spec.rb
|
329
294
|
- spec/requests/rabl_cache_spec.rb
|
330
295
|
- spec/requests/ransackable_attributes_spec.rb
|
296
|
+
- spec/requests/spree/api/addresses_controller_spec.rb
|
297
|
+
- spec/requests/spree/api/checkouts_controller_spec.rb
|
298
|
+
- spec/requests/spree/api/classifications_controller_spec.rb
|
299
|
+
- spec/requests/spree/api/config_controller_spec.rb
|
300
|
+
- spec/requests/spree/api/countries_controller_spec.rb
|
301
|
+
- spec/requests/spree/api/credit_cards_controller_spec.rb
|
302
|
+
- spec/requests/spree/api/images_controller_spec.rb
|
303
|
+
- spec/requests/spree/api/inventory_units_controller_spec.rb
|
304
|
+
- spec/requests/spree/api/line_items_controller_spec.rb
|
305
|
+
- spec/requests/spree/api/option_types_controller_spec.rb
|
306
|
+
- spec/requests/spree/api/option_values_controller_spec.rb
|
307
|
+
- spec/requests/spree/api/orders_controller_spec.rb
|
308
|
+
- spec/requests/spree/api/payments_controller_spec.rb
|
309
|
+
- spec/requests/spree/api/product_properties_controller_spec.rb
|
310
|
+
- spec/requests/spree/api/products_controller_spec.rb
|
311
|
+
- spec/requests/spree/api/promotion_application_spec.rb
|
312
|
+
- spec/requests/spree/api/promotions_controller_spec.rb
|
313
|
+
- spec/requests/spree/api/properties_controller_spec.rb
|
314
|
+
- spec/requests/spree/api/return_authorizations_controller_spec.rb
|
331
315
|
- spec/requests/spree/api/shipments_controller_spec.rb
|
316
|
+
- spec/requests/spree/api/states_controller_spec.rb
|
317
|
+
- spec/requests/spree/api/stock_items_controller_spec.rb
|
318
|
+
- spec/requests/spree/api/stock_locations_controller_spec.rb
|
319
|
+
- spec/requests/spree/api/stock_movements_controller_spec.rb
|
320
|
+
- spec/requests/spree/api/stock_transfers_controller_spec.rb
|
321
|
+
- spec/requests/spree/api/store_credit_events_controller_spec.rb
|
322
|
+
- spec/requests/spree/api/stores_controller_spec.rb
|
323
|
+
- spec/requests/spree/api/taxonomies_controller_spec.rb
|
324
|
+
- spec/requests/spree/api/taxons_controller_spec.rb
|
325
|
+
- spec/requests/spree/api/transfer_items_controller_spec.rb
|
326
|
+
- spec/requests/spree/api/unauthenticated_products_controller_spec.rb
|
327
|
+
- spec/requests/spree/api/users_controller_spec.rb
|
328
|
+
- spec/requests/spree/api/variants_controller_spec.rb
|
329
|
+
- spec/requests/spree/api/zones_controller_spec.rb
|
332
330
|
- spec/shared_examples/protect_product_actions.rb
|
333
331
|
- spec/spec_helper.rb
|
334
332
|
- spec/support/controller_hacks.rb
|
@@ -1,301 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Api::ShipmentsController, type: :controller do
|
4
|
-
render_views
|
5
|
-
let!(:shipment) { create(:shipment, inventory_units: [build(:inventory_unit, shipment: nil)]) }
|
6
|
-
let!(:attributes) { [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
|
7
|
-
|
8
|
-
before do
|
9
|
-
stub_authentication!
|
10
|
-
end
|
11
|
-
|
12
|
-
let!(:resource_scoping) { { id: shipment.to_param, shipment: { order_id: shipment.order.to_param } } }
|
13
|
-
|
14
|
-
context "as a non-admin" do
|
15
|
-
it "cannot make a shipment ready" do
|
16
|
-
api_put :ready
|
17
|
-
assert_unauthorized!
|
18
|
-
end
|
19
|
-
|
20
|
-
it "cannot make a shipment shipped" do
|
21
|
-
api_put :ship
|
22
|
-
assert_unauthorized!
|
23
|
-
end
|
24
|
-
|
25
|
-
it "cannot remove order contents from shipment" do
|
26
|
-
api_put :remove
|
27
|
-
assert_unauthorized!
|
28
|
-
end
|
29
|
-
|
30
|
-
it "cannot add contents to the shipment" do
|
31
|
-
api_put :add
|
32
|
-
assert_unauthorized!
|
33
|
-
end
|
34
|
-
|
35
|
-
it "cannot update the shipment" do
|
36
|
-
api_put :update
|
37
|
-
assert_unauthorized!
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "as an admin" do
|
42
|
-
let!(:order) { shipment.order }
|
43
|
-
let!(:stock_location) { create(:stock_location_with_items) }
|
44
|
-
let!(:variant) { create(:variant) }
|
45
|
-
|
46
|
-
sign_in_as_admin!
|
47
|
-
|
48
|
-
# Start writing this spec a bit differently than before....
|
49
|
-
describe 'POST #create' do
|
50
|
-
let(:params) do
|
51
|
-
{
|
52
|
-
variant_id: stock_location.stock_items.first.variant.to_param,
|
53
|
-
shipment: { order_id: order.number },
|
54
|
-
stock_location_id: stock_location.to_param
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
subject do
|
59
|
-
api_post :create, params
|
60
|
-
end
|
61
|
-
|
62
|
-
[:variant_id, :stock_location_id].each do |field|
|
63
|
-
context "when #{field} is missing" do
|
64
|
-
before do
|
65
|
-
params.delete(field)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should return proper error' do
|
69
|
-
subject
|
70
|
-
expect(response.status).to eq(422)
|
71
|
-
expect(json_response['exception']).to eq("param is missing or the value is empty: #{field}")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should create a new shipment' do
|
77
|
-
expect(subject).to be_ok
|
78
|
-
expect(json_response).to have_attributes(attributes)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'can update a shipment' do
|
83
|
-
params = {
|
84
|
-
shipment: {
|
85
|
-
stock_location_id: stock_location.to_param
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
api_put :update, params
|
90
|
-
expect(response.status).to eq(200)
|
91
|
-
expect(json_response['stock_location_name']).to eq(stock_location.name)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "can make a shipment ready" do
|
95
|
-
allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true)
|
96
|
-
api_put :ready
|
97
|
-
expect(json_response).to have_attributes(attributes)
|
98
|
-
expect(json_response["state"]).to eq("ready")
|
99
|
-
expect(shipment.reload.state).to eq("ready")
|
100
|
-
end
|
101
|
-
|
102
|
-
it "cannot make a shipment ready if the order is unpaid" do
|
103
|
-
allow_any_instance_of(Spree::Order).to receive_messages(paid?: false)
|
104
|
-
api_put :ready
|
105
|
-
expect(json_response["error"]).to eq("Cannot ready shipment.")
|
106
|
-
expect(response.status).to eq(422)
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'for completed orders' do
|
110
|
-
let(:order) { create :completed_order_with_totals }
|
111
|
-
let!(:resource_scoping) { { id: order.shipments.first.to_param, shipment: { order_id: order.to_param } } }
|
112
|
-
|
113
|
-
it 'adds a variant to a shipment' do
|
114
|
-
api_put :add, { variant_id: variant.to_param, quantity: 2 }
|
115
|
-
expect(response.status).to eq(200)
|
116
|
-
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(2)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'removes a variant from a shipment' do
|
120
|
-
order.contents.add(variant, 2)
|
121
|
-
|
122
|
-
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
123
|
-
expect(response.status).to eq(200)
|
124
|
-
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'removes a destroyed variant from a shipment' do
|
128
|
-
order.contents.add(variant, 2)
|
129
|
-
variant.destroy
|
130
|
-
|
131
|
-
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
132
|
-
expect(response.status).to eq(200)
|
133
|
-
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "for shipped shipments" do
|
138
|
-
let(:order) { create :shipped_order }
|
139
|
-
let!(:resource_scoping) { { id: order.shipments.first.to_param, shipment: { order_id: order.to_param } } }
|
140
|
-
|
141
|
-
it 'adds a variant to a shipment' do
|
142
|
-
api_put :add, { variant_id: variant.to_param, quantity: 2 }
|
143
|
-
expect(response.status).to eq(200)
|
144
|
-
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(2)
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'cannot remove a variant from a shipment' do
|
148
|
-
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
149
|
-
expect(response.status).to eq(422)
|
150
|
-
expect(json_response['errors']['base'].join).to match /Cannot remove items/
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#mine' do
|
155
|
-
subject do
|
156
|
-
api_get :mine, params
|
157
|
-
end
|
158
|
-
|
159
|
-
let(:params) { {} }
|
160
|
-
|
161
|
-
context "the current api user is authenticated and has orders" do
|
162
|
-
let(:current_api_user) { shipped_order.user }
|
163
|
-
let(:shipped_order) { create(:shipped_order) }
|
164
|
-
|
165
|
-
it 'succeeds' do
|
166
|
-
subject
|
167
|
-
expect(response.status).to eq 200
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'json output' do
|
171
|
-
render_views
|
172
|
-
|
173
|
-
let(:rendered_shipment_ids) { json_response['shipments'].map { |s| s['id'] } }
|
174
|
-
|
175
|
-
it 'contains the shipments' do
|
176
|
-
subject
|
177
|
-
expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)
|
178
|
-
end
|
179
|
-
|
180
|
-
context "credit card payment" do
|
181
|
-
before { subject }
|
182
|
-
|
183
|
-
it 'contains the id and cc_type of the credit card' do
|
184
|
-
expect(json_response['shipments'][0]['order']['payments'][0]['source'].keys).to match_array ["id", "cc_type"]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context "store credit payment" do
|
189
|
-
let(:current_api_user) { shipped_order.user }
|
190
|
-
let(:shipped_order) { create(:shipped_order, payment_type: :store_credit_payment) }
|
191
|
-
|
192
|
-
before { subject }
|
193
|
-
|
194
|
-
it 'only contains the id of the payment source' do
|
195
|
-
expect(json_response['shipments'][0]['order']['payments'][0]['source'].keys).to match_array ["id"]
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'with filtering' do
|
201
|
-
let(:params) { { q: { order_completed_at_not_null: 1 } } }
|
202
|
-
|
203
|
-
let!(:incomplete_order) { create(:order_with_line_items, user: current_api_user) }
|
204
|
-
|
205
|
-
it 'filters' do
|
206
|
-
subject
|
207
|
-
expect(assigns(:shipments).map(&:id)).to match_array current_api_user.orders.complete.flat_map(&:shipments).map(&:id)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context "the current api user does not exist" do
|
213
|
-
let(:current_api_user) { nil }
|
214
|
-
|
215
|
-
it "returns a 401" do
|
216
|
-
subject
|
217
|
-
expect(response.status).to eq(401)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "#ship" do
|
224
|
-
let(:shipment) { create(:order_ready_to_ship).shipments.first }
|
225
|
-
|
226
|
-
let(:send_mailer) { nil }
|
227
|
-
subject { api_put :ship, id: shipment.to_param, send_mailer: send_mailer }
|
228
|
-
|
229
|
-
context "the user is allowed to ship the shipment" do
|
230
|
-
sign_in_as_admin!
|
231
|
-
it "ships the shipment" do
|
232
|
-
Timecop.freeze do
|
233
|
-
subject
|
234
|
-
shipment.reload
|
235
|
-
expect(shipment.state).to eq 'shipped'
|
236
|
-
expect(shipment.shipped_at.to_i).to eq Time.current.to_i
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context "send_mailer not present" do
|
241
|
-
it "sends the shipped shipments mailer" do
|
242
|
-
expect { subject }.to change { ActionMailer::Base.deliveries.size }.by(1)
|
243
|
-
expect(ActionMailer::Base.deliveries.last.subject).to match /Shipment Notification/
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "send_mailer set to false" do
|
248
|
-
let(:send_mailer) { 'false' }
|
249
|
-
it "does not send the shipped shipments mailer" do
|
250
|
-
expect { subject }.to_not change { ActionMailer::Base.deliveries.size }
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
context "send_mailer set to true" do
|
255
|
-
let(:send_mailer) { 'true' }
|
256
|
-
it "sends the shipped shipments mailer" do
|
257
|
-
expect { subject }.to change { ActionMailer::Base.deliveries.size }.by(1)
|
258
|
-
expect(ActionMailer::Base.deliveries.last.subject).to match /Shipment Notification/
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "the user is not allowed to ship the shipment" do
|
264
|
-
sign_in_as_admin!
|
265
|
-
|
266
|
-
before do
|
267
|
-
ability = Spree::Ability.new(current_api_user)
|
268
|
-
ability.cannot :ship, Spree::Shipment
|
269
|
-
allow(controller).to receive(:current_ability) { ability }
|
270
|
-
end
|
271
|
-
|
272
|
-
it "does nothing" do
|
273
|
-
expect {
|
274
|
-
expect {
|
275
|
-
subject
|
276
|
-
}.not_to change(shipment, :state)
|
277
|
-
}.not_to change(shipment, :shipped_at)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "responds with a 401" do
|
281
|
-
subject
|
282
|
-
expect(response.status).to eq 401
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "the user is not allowed to view the shipment" do
|
287
|
-
it "does nothing" do
|
288
|
-
expect {
|
289
|
-
expect {
|
290
|
-
subject
|
291
|
-
}.not_to change(shipment, :state)
|
292
|
-
}.not_to change(shipment, :shipped_at)
|
293
|
-
end
|
294
|
-
|
295
|
-
it "responds with a 401" do
|
296
|
-
subject
|
297
|
-
expect(response).to be_unauthorized
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|