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::Api
|
4
|
-
describe OrdersController do
|
4
|
+
describe OrdersController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -19,13 +19,13 @@ module Spree::Api
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can apply a coupon code to the order" do
|
22
|
-
order.total.
|
22
|
+
expect(order.total).to eq(110.00)
|
23
23
|
api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.guest_token
|
24
|
-
response.status.
|
25
|
-
order.reload.total.
|
26
|
-
json_response["success"].
|
27
|
-
json_response["error"].
|
28
|
-
json_response["successful"].
|
24
|
+
expect(response.status).to eq(200)
|
25
|
+
expect(order.reload.total).to eq(109.00)
|
26
|
+
expect(json_response["success"]).to eq("The coupon code was successfully applied to your order.")
|
27
|
+
expect(json_response["error"]).to be_blank
|
28
|
+
expect(json_response["successful"]).to be true
|
29
29
|
end
|
30
30
|
|
31
31
|
context "with an expired promotion" do
|
@@ -37,10 +37,10 @@ module Spree::Api
|
|
37
37
|
|
38
38
|
it "fails to apply" do
|
39
39
|
api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.guest_token
|
40
|
-
response.status.
|
41
|
-
json_response["success"].
|
42
|
-
json_response["error"].
|
43
|
-
json_response["successful"].
|
40
|
+
expect(response.status).to eq(422)
|
41
|
+
expect(json_response["success"]).to be_blank
|
42
|
+
expect(json_response["error"]).to eq("The coupon code is expired")
|
43
|
+
expect(json_response["successful"]).to be false
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Spree
|
3
|
-
describe Spree::Api::PropertiesController do
|
3
|
+
describe Spree::Api::PropertiesController, :type => :controller do
|
4
4
|
render_views
|
5
5
|
|
6
6
|
let!(:property_1) { Property.create!(:name => "foo", :presentation => "Foo") }
|
@@ -14,50 +14,50 @@ module Spree
|
|
14
14
|
|
15
15
|
it "can see a list of all properties" do
|
16
16
|
api_get :index
|
17
|
-
json_response["properties"].count.
|
18
|
-
json_response["properties"].first.
|
17
|
+
expect(json_response["properties"].count).to eq(2)
|
18
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can control the page size through a parameter" do
|
22
22
|
api_get :index, :per_page => 1
|
23
|
-
json_response['properties'].count.
|
24
|
-
json_response['current_page'].
|
25
|
-
json_response['pages'].
|
23
|
+
expect(json_response['properties'].count).to eq(1)
|
24
|
+
expect(json_response['current_page']).to eq(1)
|
25
|
+
expect(json_response['pages']).to eq(2)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can query the results through a parameter' do
|
29
29
|
api_get :index, :q => { :name_cont => 'ba' }
|
30
|
-
json_response['count'].
|
31
|
-
json_response['properties'].first['presentation'].
|
30
|
+
expect(json_response['count']).to eq(1)
|
31
|
+
expect(json_response['properties'].first['presentation']).to eq property_2.presentation
|
32
32
|
end
|
33
33
|
|
34
34
|
it "retrieves a list of properties by id" do
|
35
35
|
api_get :index, :ids => [property_1.id]
|
36
|
-
json_response["properties"].first.
|
37
|
-
json_response["count"].
|
36
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
37
|
+
expect(json_response["count"]).to eq(1)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "retrieves a list of properties by ids string" do
|
41
41
|
api_get :index, :ids => [property_1.id, property_2.id].join(",")
|
42
|
-
json_response["properties"].first.
|
43
|
-
json_response["properties"][1].
|
44
|
-
json_response["count"].
|
42
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
43
|
+
expect(json_response["properties"][1]).to have_attributes(attributes)
|
44
|
+
expect(json_response["count"]).to eq(2)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "can see a single property" do
|
48
48
|
api_get :show, :id => property_1.id
|
49
|
-
json_response.
|
49
|
+
expect(json_response).to have_attributes(attributes)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "can see a property by name" do
|
53
53
|
api_get :show, :id => property_1.name
|
54
|
-
json_response.
|
54
|
+
expect(json_response).to have_attributes(attributes)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can learn how to create a new property" do
|
58
58
|
api_get :new
|
59
|
-
json_response["attributes"].
|
60
|
-
json_response["required_attributes"].
|
59
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
60
|
+
expect(json_response["required_attributes"]).to be_empty
|
61
61
|
end
|
62
62
|
|
63
63
|
it "cannot create a new property if not an admin" do
|
@@ -73,29 +73,29 @@ module Spree
|
|
73
73
|
it "cannot delete a property" do
|
74
74
|
api_delete :destroy, :id => property_1.id
|
75
75
|
assert_unauthorized!
|
76
|
-
|
76
|
+
expect { property_1.reload }.not_to raise_error
|
77
77
|
end
|
78
78
|
|
79
79
|
context "as an admin" do
|
80
80
|
sign_in_as_admin!
|
81
81
|
|
82
82
|
it "can create a new property" do
|
83
|
-
Spree::Property.count.
|
83
|
+
expect(Spree::Property.count).to eq(2)
|
84
84
|
api_post :create, :property => { :name => "My Property 3", :presentation => "my value 3" }
|
85
|
-
json_response.
|
86
|
-
response.status.
|
87
|
-
Spree::Property.count.
|
85
|
+
expect(json_response).to have_attributes(attributes)
|
86
|
+
expect(response.status).to eq(201)
|
87
|
+
expect(Spree::Property.count).to eq(3)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "can update a property" do
|
91
91
|
api_put :update, :id => property_1.name, :property => { :presentation => "my value 456" }
|
92
|
-
response.status.
|
92
|
+
expect(response.status).to eq(200)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "can delete a property" do
|
96
96
|
api_delete :destroy, :id => property_1.name
|
97
|
-
response.status.
|
98
|
-
|
97
|
+
expect(response.status).to eq(204)
|
98
|
+
expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ReturnAuthorizationsController do
|
4
|
+
describe Api::ReturnAuthorizationsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:order) { create(:shipped_order) }
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
|
17
17
|
context "as the order owner" do
|
18
18
|
before do
|
19
|
-
Order.
|
19
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
20
20
|
end
|
21
21
|
|
22
22
|
it "cannot see any return authorizations" do
|
@@ -57,28 +57,28 @@ module Spree
|
|
57
57
|
FactoryGirl.create(:return_authorization, :order => order)
|
58
58
|
return_authorization = order.return_authorizations.first
|
59
59
|
api_get :show, :order_id => order.number, :id => return_authorization.id
|
60
|
-
response.status.
|
61
|
-
json_response.
|
62
|
-
json_response["state"].
|
60
|
+
expect(response.status).to eq(200)
|
61
|
+
expect(json_response).to have_attributes(attributes)
|
62
|
+
expect(json_response["state"]).not_to be_blank
|
63
63
|
end
|
64
64
|
|
65
65
|
it "can get a list of return authorizations" do
|
66
66
|
FactoryGirl.create(:return_authorization, :order => order)
|
67
67
|
FactoryGirl.create(:return_authorization, :order => order)
|
68
68
|
api_get :index, { :order_id => order.number }
|
69
|
-
response.status.
|
69
|
+
expect(response.status).to eq(200)
|
70
70
|
return_authorizations = json_response["return_authorizations"]
|
71
|
-
return_authorizations.first.
|
72
|
-
return_authorizations.first.
|
71
|
+
expect(return_authorizations.first).to have_attributes(attributes)
|
72
|
+
expect(return_authorizations.first).not_to eq(return_authorizations.last)
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'can control the page size through a parameter' do
|
76
76
|
FactoryGirl.create(:return_authorization, :order => order)
|
77
77
|
FactoryGirl.create(:return_authorization, :order => order)
|
78
78
|
api_get :index, :order_id => order.number, :per_page => 1
|
79
|
-
json_response['count'].
|
80
|
-
json_response['current_page'].
|
81
|
-
json_response['pages'].
|
79
|
+
expect(json_response['count']).to eq(1)
|
80
|
+
expect(json_response['current_page']).to eq(1)
|
81
|
+
expect(json_response['pages']).to eq(2)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'can query the results through a paramter' do
|
@@ -86,85 +86,85 @@ module Spree
|
|
86
86
|
expected_result = create(:return_authorization, :reason => 'damaged')
|
87
87
|
order.return_authorizations << expected_result
|
88
88
|
api_get :index, :q => { :reason_cont => 'damage' }
|
89
|
-
json_response['count'].
|
90
|
-
json_response['return_authorizations'].first['reason'].
|
89
|
+
expect(json_response['count']).to eq(1)
|
90
|
+
expect(json_response['return_authorizations'].first['reason']).to eq expected_result.reason
|
91
91
|
end
|
92
92
|
|
93
93
|
it "can learn how to create a new return authorization" do
|
94
94
|
api_get :new
|
95
|
-
json_response["attributes"].
|
95
|
+
expect(json_response["attributes"]).to eq(["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"])
|
96
96
|
required_attributes = json_response["required_attributes"]
|
97
|
-
required_attributes.
|
97
|
+
expect(required_attributes).to include("order")
|
98
98
|
end
|
99
99
|
|
100
100
|
it "can update a return authorization on the order" do
|
101
101
|
FactoryGirl.create(:return_authorization, :order => order)
|
102
102
|
return_authorization = order.return_authorizations.first
|
103
103
|
api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
|
104
|
-
response.status.
|
105
|
-
json_response.
|
104
|
+
expect(response.status).to eq(200)
|
105
|
+
expect(json_response).to have_attributes(attributes)
|
106
106
|
end
|
107
107
|
|
108
108
|
it "can add an inventory unit to a return authorization on the order" do
|
109
109
|
FactoryGirl.create(:return_authorization, :order => order)
|
110
110
|
return_authorization = order.return_authorizations.first
|
111
111
|
inventory_unit = return_authorization.returnable_inventory.first
|
112
|
-
inventory_unit.
|
113
|
-
return_authorization.inventory_units.
|
112
|
+
expect(inventory_unit).to be
|
113
|
+
expect(return_authorization.inventory_units).to be_empty
|
114
114
|
api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
|
115
|
-
response.status.
|
116
|
-
json_response.
|
117
|
-
return_authorization.reload.inventory_units.
|
115
|
+
expect(response.status).to eq(200)
|
116
|
+
expect(json_response).to have_attributes(attributes)
|
117
|
+
expect(return_authorization.reload.inventory_units).not_to be_empty
|
118
118
|
end
|
119
119
|
|
120
120
|
it "can mark a return authorization as received on the order with an inventory unit" do
|
121
121
|
FactoryGirl.create(:new_return_authorization, :order => order, :stock_location_id => order.shipments.first.stock_location.id)
|
122
122
|
return_authorization = order.return_authorizations.first
|
123
|
-
return_authorization.state.
|
123
|
+
expect(return_authorization.state).to eq("authorized")
|
124
124
|
|
125
125
|
# prep (use a rspec context or a factory instead?)
|
126
126
|
inventory_unit = return_authorization.returnable_inventory.first
|
127
|
-
inventory_unit.
|
128
|
-
return_authorization.inventory_units.
|
127
|
+
expect(inventory_unit).to be
|
128
|
+
expect(return_authorization.inventory_units).to be_empty
|
129
129
|
api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
|
130
130
|
# end prep
|
131
131
|
|
132
132
|
api_delete :receive, :id => return_authorization.id
|
133
|
-
response.status.
|
134
|
-
return_authorization.reload.state.
|
133
|
+
expect(response.status).to eq(200)
|
134
|
+
expect(return_authorization.reload.state).to eq("received")
|
135
135
|
end
|
136
136
|
|
137
137
|
it "cannot mark a return authorization as received on the order with no inventory units" do
|
138
138
|
FactoryGirl.create(:new_return_authorization, :order => order)
|
139
139
|
return_authorization = order.return_authorizations.first
|
140
|
-
return_authorization.state.
|
140
|
+
expect(return_authorization.state).to eq("authorized")
|
141
141
|
api_delete :receive, :id => return_authorization.id
|
142
|
-
response.status.
|
143
|
-
return_authorization.reload.state.
|
142
|
+
expect(response.status).to eq(422)
|
143
|
+
expect(return_authorization.reload.state).to eq("authorized")
|
144
144
|
end
|
145
145
|
|
146
146
|
it "can cancel a return authorization on the order" do
|
147
147
|
FactoryGirl.create(:new_return_authorization, :order => order)
|
148
148
|
return_authorization = order.return_authorizations.first
|
149
|
-
return_authorization.state.
|
149
|
+
expect(return_authorization.state).to eq("authorized")
|
150
150
|
api_delete :cancel, :id => return_authorization.id
|
151
|
-
response.status.
|
152
|
-
return_authorization.reload.state.
|
151
|
+
expect(response.status).to eq(200)
|
152
|
+
expect(return_authorization.reload.state).to eq("canceled")
|
153
153
|
end
|
154
154
|
|
155
155
|
it "can delete a return authorization on the order" do
|
156
156
|
FactoryGirl.create(:return_authorization, :order => order)
|
157
157
|
return_authorization = order.return_authorizations.first
|
158
158
|
api_delete :destroy, :id => return_authorization.id
|
159
|
-
response.status.
|
160
|
-
|
159
|
+
expect(response.status).to eq(204)
|
160
|
+
expect { return_authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "can add a new return authorization to an existing order" do
|
164
164
|
api_post :create, :order_id => order.number, :return_authorization => { :amount => 14.22, :reason => "Defective" }
|
165
|
-
response.status.
|
166
|
-
json_response.
|
167
|
-
json_response["state"].
|
165
|
+
expect(response.status).to eq(201)
|
166
|
+
expect(json_response).to have_attributes(attributes)
|
167
|
+
expect(json_response["state"]).not_to be_blank
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -179,7 +179,7 @@ module Spree
|
|
179
179
|
return_authorization = order.return_authorizations.first
|
180
180
|
api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
|
181
181
|
assert_unauthorized!
|
182
|
-
return_authorization.reload.amount.
|
182
|
+
expect(return_authorization.reload.amount).not_to eq(19.99)
|
183
183
|
end
|
184
184
|
|
185
185
|
it "cannot delete a return authorization on the order" do
|
@@ -187,7 +187,7 @@ module Spree
|
|
187
187
|
return_authorization = order.return_authorizations.first
|
188
188
|
api_delete :destroy, :id => return_authorization.id
|
189
189
|
assert_unauthorized!
|
190
|
-
|
190
|
+
expect { return_authorization.reload }.not_to raise_error
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Spree::Api::ShipmentsController do
|
3
|
+
describe Spree::Api::ShipmentsController, :type => :controller do
|
4
4
|
render_views
|
5
5
|
let!(:shipment) { create(:shipment) }
|
6
6
|
let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
|
@@ -27,18 +27,41 @@ describe Spree::Api::ShipmentsController do
|
|
27
27
|
let!(:order) { shipment.order }
|
28
28
|
let!(:stock_location) { create(:stock_location_with_items) }
|
29
29
|
let!(:variant) { create(:variant) }
|
30
|
+
|
30
31
|
sign_in_as_admin!
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
# Start writing this spec a bit differently than before....
|
34
|
+
describe 'POST #create' do
|
35
|
+
let(:params) do
|
36
|
+
{
|
37
|
+
variant_id: stock_location.stock_items.first.variant.to_param,
|
38
|
+
shipment: { order_id: order.number },
|
39
|
+
stock_location_id: stock_location.to_param
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
subject do
|
44
|
+
api_post :create, params
|
45
|
+
end
|
46
|
+
|
47
|
+
[:variant_id, :stock_location_id].each do |field|
|
48
|
+
context "when #{field} is missing" do
|
49
|
+
before do
|
50
|
+
params.delete(field)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should return proper error' do
|
54
|
+
subject
|
55
|
+
expect(response.status).to eq(422)
|
56
|
+
expect(json_response['exception']).to eq("param is missing or the value is empty: #{field.to_s}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
38
60
|
|
39
|
-
|
40
|
-
|
41
|
-
|
61
|
+
it 'should create a new shipment' do
|
62
|
+
expect(subject).to be_ok
|
63
|
+
expect(json_response).to have_attributes(attributes)
|
64
|
+
end
|
42
65
|
end
|
43
66
|
|
44
67
|
it 'can update a shipment' do
|
@@ -49,23 +72,23 @@ describe Spree::Api::ShipmentsController do
|
|
49
72
|
}
|
50
73
|
|
51
74
|
api_put :update, params
|
52
|
-
response.status.
|
53
|
-
json_response['stock_location_name'].
|
75
|
+
expect(response.status).to eq(200)
|
76
|
+
expect(json_response['stock_location_name']).to eq(stock_location.name)
|
54
77
|
end
|
55
78
|
|
56
79
|
it "can make a shipment ready" do
|
57
|
-
Spree::Order.
|
80
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
|
58
81
|
api_put :ready
|
59
|
-
json_response.
|
60
|
-
json_response["state"].
|
61
|
-
shipment.reload.state.
|
82
|
+
expect(json_response).to have_attributes(attributes)
|
83
|
+
expect(json_response["state"]).to eq("ready")
|
84
|
+
expect(shipment.reload.state).to eq("ready")
|
62
85
|
end
|
63
86
|
|
64
87
|
it "cannot make a shipment ready if the order is unpaid" do
|
65
|
-
Spree::Order.
|
88
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => false)
|
66
89
|
api_put :ready
|
67
|
-
json_response["error"].
|
68
|
-
response.status.
|
90
|
+
expect(json_response["error"]).to eq("Cannot ready shipment.")
|
91
|
+
expect(response.status).to eq(422)
|
69
92
|
end
|
70
93
|
|
71
94
|
context 'for completed shipments' do
|
@@ -74,16 +97,16 @@ describe Spree::Api::ShipmentsController do
|
|
74
97
|
|
75
98
|
it 'adds a variant to a shipment' do
|
76
99
|
api_put :add, { variant_id: variant.to_param, quantity: 2 }
|
77
|
-
response.status.
|
78
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
100
|
+
expect(response.status).to eq(200)
|
101
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(2)
|
79
102
|
end
|
80
103
|
|
81
104
|
it 'removes a variant from a shipment' do
|
82
105
|
order.contents.add(variant, 2)
|
83
106
|
|
84
107
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
85
|
-
response.status.
|
86
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
108
|
+
expect(response.status).to eq(200)
|
109
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
87
110
|
end
|
88
111
|
|
89
112
|
it 'removes a destroyed variant from a shipment' do
|
@@ -91,27 +114,27 @@ describe Spree::Api::ShipmentsController do
|
|
91
114
|
variant.destroy
|
92
115
|
|
93
116
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
94
|
-
response.status.
|
95
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
117
|
+
expect(response.status).to eq(200)
|
118
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
96
119
|
end
|
97
120
|
end
|
98
121
|
|
99
122
|
context "can transition a shipment from ready to ship" do
|
100
123
|
before do
|
101
|
-
Spree::Order.
|
124
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
|
102
125
|
# For the shipment notification email
|
103
126
|
Spree::Config[:mails_from] = "spree@example.com"
|
104
127
|
|
105
128
|
shipment.update!(shipment.order)
|
106
|
-
shipment.state.
|
107
|
-
Spree::ShippingRate.
|
129
|
+
expect(shipment.state).to eq("ready")
|
130
|
+
allow_any_instance_of(Spree::ShippingRate).to receive_messages(:cost => 5)
|
108
131
|
end
|
109
132
|
|
110
133
|
it "can transition a shipment from ready to ship" do
|
111
134
|
shipment.reload
|
112
135
|
api_put :ship, id: shipment.to_param, shipment: { tracking: "123123", order_id: shipment.order.to_param }
|
113
|
-
json_response.
|
114
|
-
json_response["state"].
|
136
|
+
expect(json_response).to have_attributes(attributes)
|
137
|
+
expect(json_response["state"]).to eq("shipped")
|
115
138
|
end
|
116
139
|
|
117
140
|
end
|