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,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ClassificationsController, type: :
|
4
|
+
describe Api::ClassificationsController, type: :request do
|
5
5
|
let(:taxon) do
|
6
6
|
taxon = create(:taxon)
|
7
7
|
|
@@ -18,7 +18,7 @@ module Spree
|
|
18
18
|
|
19
19
|
context "as a user" do
|
20
20
|
it "cannot change the order of a product" do
|
21
|
-
|
21
|
+
put spree.api_classifications_path, params: { taxon_id: taxon, product_id: taxon.products.first, position: 1 }
|
22
22
|
expect(response.status).to eq(401)
|
23
23
|
end
|
24
24
|
end
|
@@ -31,7 +31,7 @@ module Spree
|
|
31
31
|
it "can change the order a product" do
|
32
32
|
classification = taxon.classifications.find_by(product_id: last_product.id)
|
33
33
|
expect(classification.position).to eq(3)
|
34
|
-
|
34
|
+
put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
|
35
35
|
expect(response.status).to eq(200)
|
36
36
|
expect(classification.reload.position).to eq(1)
|
37
37
|
end
|
@@ -39,7 +39,7 @@ module Spree
|
|
39
39
|
it "should touch the taxon" do
|
40
40
|
taxon.update_attributes(updated_at: Time.current - 10.seconds)
|
41
41
|
taxon_last_updated_at = taxon.updated_at
|
42
|
-
|
42
|
+
put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
|
43
43
|
taxon.reload
|
44
44
|
expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
|
45
45
|
end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ConfigController, type: :
|
4
|
+
describe Api::ConfigController, type: :request do
|
5
5
|
let!(:default_country) { create :country, iso: "US"}
|
6
|
-
render_views
|
7
6
|
|
8
7
|
before do
|
9
8
|
stub_authentication!
|
10
9
|
end
|
11
10
|
|
12
11
|
it "returns Spree::Money settings" do
|
13
|
-
|
12
|
+
get '/api/config/money'
|
14
13
|
expect(response).to be_success
|
15
14
|
expect(json_response["symbol"]).to eq("$")
|
16
15
|
end
|
17
16
|
|
18
17
|
it "returns some configuration settings" do
|
19
|
-
|
18
|
+
get '/api/config'
|
20
19
|
expect(response).to be_success
|
21
20
|
expect(json_response["default_country_iso"]).to eq("US")
|
22
21
|
expect(json_response["default_country_id"]).to eq(default_country.id)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CountriesController, type: :
|
5
|
-
render_views
|
4
|
+
describe Api::CountriesController, type: :request do
|
6
5
|
|
7
6
|
before do
|
8
7
|
stub_authentication!
|
@@ -11,7 +10,7 @@ module Spree
|
|
11
10
|
end
|
12
11
|
|
13
12
|
it "gets all countries" do
|
14
|
-
|
13
|
+
get spree.api_countries_path
|
15
14
|
expect(json_response['countries'].first['iso3']).to eq @country.iso3
|
16
15
|
end
|
17
16
|
|
@@ -19,20 +18,20 @@ module Spree
|
|
19
18
|
before { @zambia = create(:country, name: "Zambia") }
|
20
19
|
|
21
20
|
it "can view all countries" do
|
22
|
-
|
21
|
+
get spree.api_countries_path
|
23
22
|
expect(json_response['count']).to eq(2)
|
24
23
|
expect(json_response['current_page']).to eq(1)
|
25
24
|
expect(json_response['pages']).to eq(1)
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'can query the results through a paramter' do
|
29
|
-
|
28
|
+
get spree.api_countries_path, params: { q: { name_cont: 'zam' } }
|
30
29
|
expect(json_response['count']).to eq(1)
|
31
30
|
expect(json_response['countries'].first['name']).to eq @zambia.name
|
32
31
|
end
|
33
32
|
|
34
33
|
it 'can control the page size through a parameter' do
|
35
|
-
|
34
|
+
get spree.api_countries_path, params: { per_page: 1 }
|
36
35
|
expect(json_response['count']).to eq(1)
|
37
36
|
expect(json_response['current_page']).to eq(1)
|
38
37
|
expect(json_response['pages']).to eq(2)
|
@@ -40,7 +39,7 @@ module Spree
|
|
40
39
|
end
|
41
40
|
|
42
41
|
it "includes states" do
|
43
|
-
|
42
|
+
get spree.api_country_path(@country.id)
|
44
43
|
states = json_response['states']
|
45
44
|
expect(states.first['name']).to eq @state.name
|
46
45
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CreditCardsController, type: :
|
4
|
+
describe Api::CreditCardsController, type: :request do
|
5
5
|
describe '#index' do
|
6
|
-
render_views
|
7
6
|
|
8
7
|
let!(:admin_user) do
|
9
8
|
create(:admin_user)
|
@@ -20,7 +19,7 @@ module Spree
|
|
20
19
|
end
|
21
20
|
|
22
21
|
it "the user id doesn't exist" do
|
23
|
-
|
22
|
+
get spree.api_user_credit_cards_path(1000)
|
24
23
|
expect(response.status).to eq(404)
|
25
24
|
end
|
26
25
|
|
@@ -30,14 +29,14 @@ module Spree
|
|
30
29
|
end
|
31
30
|
|
32
31
|
it "no credit cards exist for user" do
|
33
|
-
|
32
|
+
get spree.api_user_credit_cards_path(normal_user)
|
34
33
|
|
35
34
|
expect(response.status).to eq(200)
|
36
35
|
expect(json_response["pages"]).to eq(0)
|
37
36
|
end
|
38
37
|
|
39
38
|
it "can view all credit cards for user" do
|
40
|
-
|
39
|
+
get spree.api_user_credit_cards_path(current_api_user.id)
|
41
40
|
|
42
41
|
expect(response.status).to eq(200)
|
43
42
|
expect(json_response["pages"]).to eq(1)
|
@@ -55,13 +54,13 @@ module Spree
|
|
55
54
|
let!(:card) { create(:credit_card, user_id: normal_user.id, gateway_customer_profile_id: "random") }
|
56
55
|
|
57
56
|
it "can not view user" do
|
58
|
-
|
57
|
+
get spree.api_user_credit_cards_path(admin_user.id)
|
59
58
|
|
60
59
|
expect(response.status).to eq(404)
|
61
60
|
end
|
62
61
|
|
63
62
|
it "can view own credit cards" do
|
64
|
-
|
63
|
+
get spree.api_user_credit_cards_path(normal_user.id)
|
65
64
|
|
66
65
|
expect(response.status).to eq(200)
|
67
66
|
expect(json_response["pages"]).to eq(1)
|
@@ -85,7 +84,7 @@ module Spree
|
|
85
84
|
|
86
85
|
it 'updates the credit card' do
|
87
86
|
expect {
|
88
|
-
|
87
|
+
put spree.api_credit_card_path(credit_card.to_param), params: { credit_card: { name: 'Jordan Brough' } }
|
89
88
|
}.to change {
|
90
89
|
credit_card.reload.name
|
91
90
|
}.from('Joe Shmoe').to('Jordan Brough')
|
@@ -96,7 +95,7 @@ module Spree
|
|
96
95
|
let(:current_api_user) { create(:user) }
|
97
96
|
|
98
97
|
it 'rejects the request' do
|
99
|
-
|
98
|
+
put spree.api_credit_card_path(credit_card.to_param), params: { credit_card: { name: 'Jordan Brough' } }
|
100
99
|
expect(response.status).to eq(401)
|
101
100
|
end
|
102
101
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Spree::Api::ImagesController, type: :
|
5
|
-
render_views
|
4
|
+
describe Spree::Api::ImagesController, type: :request do
|
6
5
|
|
7
6
|
let!(:product) { create(:product) }
|
8
7
|
let!(:attributes) {
|
@@ -20,11 +19,13 @@ module Spree
|
|
20
19
|
|
21
20
|
it "can upload a new image for a variant" do
|
22
21
|
expect do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
post spree.api_product_images_path(product.id), params: {
|
23
|
+
image: {
|
24
|
+
attachment: upload_image('thinking-cat.jpg'),
|
25
|
+
viewable_type: 'Spree::Variant',
|
26
|
+
viewable_id: product.master.to_param
|
27
|
+
},
|
28
|
+
}
|
28
29
|
expect(response.status).to eq(201)
|
29
30
|
expect(json_response).to have_attributes(attributes)
|
30
31
|
end.to change(Image, :count).by(1)
|
@@ -34,26 +35,26 @@ module Spree
|
|
34
35
|
let!(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
|
35
36
|
|
36
37
|
it "can get a single product image" do
|
37
|
-
|
38
|
+
get spree.api_product_image_path(product.id, product_image)
|
38
39
|
expect(response.status).to eq(200)
|
39
40
|
expect(json_response).to have_attributes(attributes)
|
40
41
|
end
|
41
42
|
|
42
43
|
it "can get a single variant image" do
|
43
|
-
|
44
|
+
get spree.api_variant_image_path(product.master.id, product_image)
|
44
45
|
expect(response.status).to eq(200)
|
45
46
|
expect(json_response).to have_attributes(attributes)
|
46
47
|
end
|
47
48
|
|
48
49
|
it "can get a list of product images" do
|
49
|
-
|
50
|
+
get spree.api_product_images_path(product.id)
|
50
51
|
expect(response.status).to eq(200)
|
51
52
|
expect(json_response).to have_key("images")
|
52
53
|
expect(json_response["images"].first).to have_attributes(attributes)
|
53
54
|
end
|
54
55
|
|
55
56
|
it "can get a list of variant images" do
|
56
|
-
|
57
|
+
get spree.api_variant_images_path(product.master.id)
|
57
58
|
expect(response.status).to eq(200)
|
58
59
|
expect(json_response).to have_key("images")
|
59
60
|
expect(json_response["images"].first).to have_attributes(attributes)
|
@@ -61,14 +62,14 @@ module Spree
|
|
61
62
|
|
62
63
|
it "can update image data" do
|
63
64
|
expect(product_image.position).to eq(1)
|
64
|
-
|
65
|
+
put spree.api_variant_image_path(product.id, product_image), params: { image: { position: 2 } }
|
65
66
|
expect(response.status).to eq(200)
|
66
67
|
expect(json_response).to have_attributes(attributes)
|
67
68
|
expect(product_image.reload.position).to eq(2)
|
68
69
|
end
|
69
70
|
|
70
71
|
it "can delete an image" do
|
71
|
-
|
72
|
+
delete spree.api_variant_image_path(product.id, product_image)
|
72
73
|
expect(response.status).to eq(204)
|
73
74
|
expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
74
75
|
end
|
@@ -76,18 +77,20 @@ module Spree
|
|
76
77
|
end
|
77
78
|
|
78
79
|
context "as a non-admin" do
|
80
|
+
let(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
|
81
|
+
|
79
82
|
it "cannot create an image" do
|
80
|
-
|
83
|
+
post spree.api_product_images_path(product.id)
|
81
84
|
assert_unauthorized!
|
82
85
|
end
|
83
86
|
|
84
87
|
it "cannot update an image" do
|
85
|
-
|
88
|
+
put spree.api_product_image_path(product.id, product_image)
|
86
89
|
assert_not_found!
|
87
90
|
end
|
88
91
|
|
89
92
|
it "cannot delete an image" do
|
90
|
-
|
93
|
+
delete spree.api_product_image_path(product.id, product_image)
|
91
94
|
assert_not_found!
|
92
95
|
end
|
93
96
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::InventoryUnitsController, type: :
|
5
|
-
|
4
|
+
describe Api::InventoryUnitsController, type: :request do
|
5
|
+
let!(:inventory_unit) { create(:inventory_unit) }
|
6
6
|
|
7
7
|
before do
|
8
8
|
stub_authentication!
|
9
|
-
@inventory_unit = create(:inventory_unit)
|
10
9
|
end
|
11
10
|
|
12
11
|
context "as an admin" do
|
@@ -14,34 +13,38 @@ module Spree
|
|
14
13
|
let(:variant) { create(:variant) }
|
15
14
|
|
16
15
|
it "gets an inventory unit" do
|
17
|
-
|
18
|
-
expect(json_response['state']).to eq
|
16
|
+
get spree.api_inventory_unit_path(inventory_unit)
|
17
|
+
expect(json_response['state']).to eq inventory_unit.state
|
19
18
|
end
|
20
19
|
|
21
20
|
it "updates an inventory unit" do
|
22
|
-
|
23
|
-
|
21
|
+
put spree.api_inventory_unit_path(inventory_unit), params: {
|
22
|
+
inventory_unit: { variant_id: variant.id }
|
23
|
+
}
|
24
24
|
expect(json_response['variant_id']).to eq variant.id
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'fires state event' do
|
28
28
|
it 'if supplied with :fire param' do
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
put spree.api_inventory_unit_path(inventory_unit), params: {
|
30
|
+
fire: 'ship',
|
31
|
+
inventory_unit: { variant_id: variant.id }
|
32
|
+
}
|
32
33
|
|
33
34
|
expect(json_response['state']).to eq 'shipped'
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'and returns exception if cannot fire' do
|
37
|
-
|
38
|
-
|
38
|
+
put spree.api_inventory_unit_path(inventory_unit), params: {
|
39
|
+
fire: 'return'
|
40
|
+
}
|
39
41
|
expect(json_response['exception']).to match /cannot transition to return/
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'and returns exception bad state' do
|
43
|
-
|
44
|
-
|
45
|
+
put spree.api_inventory_unit_path(inventory_unit), params: {
|
46
|
+
fire: 'bad'
|
47
|
+
}
|
45
48
|
expect(json_response['exception']).to match /cannot transition to bad/
|
46
49
|
end
|
47
50
|
end
|
@@ -5,15 +5,11 @@ module Spree
|
|
5
5
|
mattr_writer :line_item_attributes
|
6
6
|
end
|
7
7
|
|
8
|
-
unless PermittedAttributes.line_item_attributes.include? :
|
9
|
-
PermittedAttributes.line_item_attributes
|
8
|
+
unless PermittedAttributes.line_item_attributes.include? :options
|
9
|
+
PermittedAttributes.line_item_attributes << { options: [:some_option] }
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
Spree::Api::LineItemsController.line_item_options += [:some_option]
|
14
|
-
|
15
|
-
describe Api::LineItemsController, type: :controller do
|
16
|
-
render_views
|
12
|
+
describe Api::LineItemsController, type: :request do
|
17
13
|
|
18
14
|
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
|
19
15
|
|
@@ -26,7 +22,7 @@ module Spree
|
|
26
22
|
end
|
27
23
|
|
28
24
|
it "can learn how to create a new line item" do
|
29
|
-
|
25
|
+
get spree.new_api_order_line_item_path(order)
|
30
26
|
expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
|
31
27
|
required_attributes = json_response["required_attributes"]
|
32
28
|
expect(required_attributes).to include("quantity", "variant_id")
|
@@ -34,15 +30,16 @@ module Spree
|
|
34
30
|
|
35
31
|
context "authenticating with a token" do
|
36
32
|
it "can add a new line item to an existing order" do
|
37
|
-
|
33
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 }, order_token: order.guest_token }
|
38
34
|
expect(response.status).to eq(201)
|
39
35
|
expect(json_response).to have_attributes(attributes)
|
40
36
|
expect(json_response["variant"]["name"]).not_to be_blank
|
41
37
|
end
|
42
38
|
|
43
39
|
it "can add a new line item to an existing order with token in header" do
|
44
|
-
|
45
|
-
|
40
|
+
post spree.api_order_line_items_path(order),
|
41
|
+
params: { line_item: { variant_id: product.master.to_param, quantity: 1 } },
|
42
|
+
headers: { 'X-Spree-Order-Token' => order.guest_token }
|
46
43
|
expect(response.status).to eq(201)
|
47
44
|
expect(json_response).to have_attributes(attributes)
|
48
45
|
expect(json_response["variant"]["name"]).not_to be_blank
|
@@ -55,7 +52,7 @@ module Spree
|
|
55
52
|
end
|
56
53
|
|
57
54
|
it "can add a new line item to an existing order" do
|
58
|
-
|
55
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
59
56
|
expect(response.status).to eq(201)
|
60
57
|
expect(json_response).to have_attributes(attributes)
|
61
58
|
expect(json_response["variant"]["name"]).not_to be_blank
|
@@ -63,17 +60,19 @@ module Spree
|
|
63
60
|
|
64
61
|
it "can add a new line item to an existing order with options" do
|
65
62
|
expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
post spree.api_order_line_items_path(order),
|
64
|
+
params: {
|
65
|
+
line_item: {
|
66
|
+
variant_id: product.master.to_param,
|
67
|
+
quantity: 1,
|
68
|
+
options: { some_option: "foobar" }
|
69
|
+
}
|
70
|
+
}
|
72
71
|
expect(response.status).to eq(201)
|
73
72
|
end
|
74
73
|
|
75
74
|
it "default quantity to 1 if none is given" do
|
76
|
-
|
75
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param } }
|
77
76
|
expect(response.status).to eq(201)
|
78
77
|
expect(json_response).to have_attributes(attributes)
|
79
78
|
expect(json_response[:quantity]).to eq 1
|
@@ -81,7 +80,7 @@ module Spree
|
|
81
80
|
|
82
81
|
it "increases a line item's quantity if it exists already" do
|
83
82
|
order.line_items.create(variant_id: product.master.id, quantity: 10)
|
84
|
-
|
83
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
85
84
|
expect(response.status).to eq(201)
|
86
85
|
order.reload
|
87
86
|
expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test
|
@@ -91,7 +90,7 @@ module Spree
|
|
91
90
|
|
92
91
|
it "can update a line item on the order" do
|
93
92
|
line_item = order.line_items.first
|
94
|
-
|
93
|
+
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 101 } }
|
95
94
|
expect(response.status).to eq(200)
|
96
95
|
order.reload
|
97
96
|
expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
|
@@ -102,15 +101,16 @@ module Spree
|
|
102
101
|
it "can update a line item's options on the order" do
|
103
102
|
expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
|
104
103
|
line_item = order.line_items.first
|
105
|
-
|
106
|
-
|
107
|
-
|
104
|
+
put spree.api_order_line_item_path(order, line_item),
|
105
|
+
params: {
|
106
|
+
line_item: { quantity: 1, options: { some_option: "foobar" } }
|
107
|
+
}
|
108
108
|
expect(response.status).to eq(200)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "can delete a line item on the order" do
|
112
112
|
line_item = order.line_items.first
|
113
|
-
|
113
|
+
delete spree.api_order_line_item_path(order, line_item)
|
114
114
|
expect(response.status).to eq(204)
|
115
115
|
order.reload
|
116
116
|
expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test
|
@@ -126,19 +126,19 @@ module Spree
|
|
126
126
|
|
127
127
|
it "clear out shipments on create" do
|
128
128
|
expect(order.reload.shipments).not_to be_empty
|
129
|
-
|
129
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
130
130
|
expect(order.reload.shipments).to be_empty
|
131
131
|
end
|
132
132
|
|
133
133
|
it "clear out shipments on update" do
|
134
134
|
expect(order.reload.shipments).not_to be_empty
|
135
|
-
|
135
|
+
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 1000 } }
|
136
136
|
expect(order.reload.shipments).to be_empty
|
137
137
|
end
|
138
138
|
|
139
139
|
it "clear out shipments on delete" do
|
140
140
|
expect(order.reload.shipments).not_to be_empty
|
141
|
-
|
141
|
+
delete spree.api_order_line_item_path(order, line_item)
|
142
142
|
expect(order.reload.shipments).to be_empty
|
143
143
|
end
|
144
144
|
|
@@ -150,7 +150,7 @@ module Spree
|
|
150
150
|
|
151
151
|
it "doesn't destroy shipments or restart checkout flow" do
|
152
152
|
expect(order.reload.shipments).not_to be_empty
|
153
|
-
|
153
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
154
154
|
expect(order.reload.shipments).not_to be_empty
|
155
155
|
end
|
156
156
|
end
|
@@ -165,20 +165,20 @@ module Spree
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "cannot add a new line item to the order" do
|
168
|
-
|
168
|
+
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
169
169
|
assert_unauthorized!
|
170
170
|
end
|
171
171
|
|
172
172
|
it "cannot update a line item on the order" do
|
173
173
|
line_item = order.line_items.first
|
174
|
-
|
174
|
+
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 1000 } }
|
175
175
|
assert_unauthorized!
|
176
176
|
expect(line_item.reload.quantity).not_to eq(1000)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "cannot delete a line item on the order" do
|
180
180
|
line_item = order.line_items.first
|
181
|
-
|
181
|
+
delete spree.api_order_line_item_path(order, line_item)
|
182
182
|
assert_unauthorized!
|
183
183
|
expect { line_item.reload }.not_to raise_error
|
184
184
|
end
|