spree_api 2.3.13 → 2.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -43
- data/Gemfile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +22 -9
- data/app/controllers/spree/api/checkouts_controller.rb +2 -2
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
- data/app/controllers/spree/api/images_controller.rb +5 -0
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/line_items_controller.rb +7 -7
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +17 -6
- data/app/controllers/spree/api/payments_controller.rb +3 -11
- data/app/controllers/spree/api/product_properties_controller.rb +2 -2
- data/app/controllers/spree/api/promotions_controller.rb +26 -0
- data/app/controllers/spree/api/properties_controller.rb +1 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
- data/app/controllers/spree/api/shipments_controller.rb +71 -4
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +1 -2
- data/app/helpers/spree/api/api_helpers.rb +19 -5
- data/app/views/spree/api/images/index.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -1
- data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
- data/app/views/spree/api/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/shipments/small.v1.rabl +1 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/variants/big.v1.rabl +6 -1
- data/app/views/spree/api/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/variants/small.v1.rabl +2 -3
- data/config/routes.rb +9 -0
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- 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 +66 -19
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
- 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 +37 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
- 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 +177 -161
- data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
- data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
- data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
- data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
- 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 +41 -41
- data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -0
- metadata +14 -9
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ReturnAuthorizationsController
|
4
|
+
describe Api::ReturnAuthorizationsController do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:order) { create(:shipped_order) }
|
8
8
|
|
9
9
|
let(:product) { create(:product) }
|
10
|
-
let(:attributes) { [:id, :
|
10
|
+
let(:attributes) { [:id, :memo, :state] }
|
11
11
|
let(:resource_scoping) { { :order_id => order.to_param } }
|
12
12
|
|
13
13
|
before do
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
|
17
17
|
context "as the order owner" do
|
18
18
|
before do
|
19
|
-
|
19
|
+
Order.any_instance.stub :user => current_api_user
|
20
20
|
end
|
21
21
|
|
22
22
|
it "cannot see any return authorizations" do
|
@@ -57,129 +57,105 @@ 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
|
-
|
61
|
-
|
62
|
-
|
60
|
+
response.status.should == 200
|
61
|
+
json_response.should have_attributes(attributes)
|
62
|
+
json_response["state"].should_not 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
|
-
|
69
|
+
response.status.should == 200
|
70
70
|
return_authorizations = json_response["return_authorizations"]
|
71
|
-
|
72
|
-
|
71
|
+
return_authorizations.first.should have_attributes(attributes)
|
72
|
+
return_authorizations.first.should_not == 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
|
-
|
80
|
-
|
81
|
-
|
79
|
+
json_response['count'].should == 1
|
80
|
+
json_response['current_page'].should == 1
|
81
|
+
json_response['pages'].should == 2
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'can query the results through a paramter' do
|
85
85
|
FactoryGirl.create(:return_authorization, :order => order)
|
86
|
-
expected_result = create(:return_authorization, :
|
86
|
+
expected_result = create(:return_authorization, :memo => 'damaged')
|
87
87
|
order.return_authorizations << expected_result
|
88
|
-
api_get :index, :q => { :
|
89
|
-
|
90
|
-
|
88
|
+
api_get :index, :q => { :memo_cont => 'damaged' }
|
89
|
+
json_response['count'].should == 1
|
90
|
+
json_response['return_authorizations'].first['memo'].should eq expected_result.memo
|
91
91
|
end
|
92
92
|
|
93
93
|
it "can learn how to create a new return authorization" do
|
94
94
|
api_get :new
|
95
|
-
|
95
|
+
json_response["attributes"].should == ["id", "number", "state", "order_id", "memo", "created_at", "updated_at"]
|
96
96
|
required_attributes = json_response["required_attributes"]
|
97
|
-
|
97
|
+
required_attributes.should 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
|
-
api_put :update, :id => return_authorization.id, :return_authorization => { :
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
it "can add an inventory unit to a return authorization on the order" do
|
109
|
-
FactoryGirl.create(:return_authorization, :order => order)
|
110
|
-
return_authorization = order.return_authorizations.first
|
111
|
-
inventory_unit = return_authorization.returnable_inventory.first
|
112
|
-
expect(inventory_unit).to be
|
113
|
-
expect(return_authorization.inventory_units).to be_empty
|
114
|
-
api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
|
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
|
-
end
|
119
|
-
|
120
|
-
it "can mark a return authorization as received on the order with an inventory unit" do
|
121
|
-
FactoryGirl.create(:new_return_authorization, :order => order, :stock_location_id => order.shipments.first.stock_location.id)
|
122
|
-
return_authorization = order.return_authorizations.first
|
123
|
-
expect(return_authorization.state).to eq("authorized")
|
124
|
-
|
125
|
-
# prep (use a rspec context or a factory instead?)
|
126
|
-
inventory_unit = return_authorization.returnable_inventory.first
|
127
|
-
expect(inventory_unit).to be
|
128
|
-
expect(return_authorization.inventory_units).to be_empty
|
129
|
-
api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
|
130
|
-
# end prep
|
131
|
-
|
132
|
-
api_delete :receive, :id => return_authorization.id
|
133
|
-
expect(response.status).to eq(200)
|
134
|
-
expect(return_authorization.reload.state).to eq("received")
|
103
|
+
api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
|
104
|
+
response.status.should == 200
|
105
|
+
json_response.should have_attributes(attributes)
|
135
106
|
end
|
136
107
|
|
137
108
|
it "cannot mark a return authorization as received on the order with no inventory units" do
|
138
109
|
FactoryGirl.create(:new_return_authorization, :order => order)
|
139
110
|
return_authorization = order.return_authorizations.first
|
140
|
-
|
111
|
+
return_authorization.state.should == "authorized"
|
141
112
|
api_delete :receive, :id => return_authorization.id
|
142
|
-
|
143
|
-
|
113
|
+
response.status.should == 422
|
114
|
+
return_authorization.reload.state.should == "authorized"
|
144
115
|
end
|
145
116
|
|
146
117
|
it "can cancel a return authorization on the order" do
|
147
118
|
FactoryGirl.create(:new_return_authorization, :order => order)
|
148
119
|
return_authorization = order.return_authorizations.first
|
149
|
-
|
120
|
+
return_authorization.state.should == "authorized"
|
150
121
|
api_delete :cancel, :id => return_authorization.id
|
151
|
-
|
152
|
-
|
122
|
+
response.status.should == 200
|
123
|
+
return_authorization.reload.state.should == "canceled"
|
153
124
|
end
|
154
125
|
|
155
126
|
it "can delete a return authorization on the order" do
|
156
127
|
FactoryGirl.create(:return_authorization, :order => order)
|
157
128
|
return_authorization = order.return_authorizations.first
|
158
129
|
api_delete :destroy, :id => return_authorization.id
|
159
|
-
|
160
|
-
|
130
|
+
response.status.should == 204
|
131
|
+
lambda { return_authorization.reload }.should raise_error(ActiveRecord::RecordNotFound)
|
161
132
|
end
|
162
133
|
|
163
134
|
it "can add a new return authorization to an existing order" do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
135
|
+
stock_location = FactoryGirl.create(:stock_location)
|
136
|
+
reason = FactoryGirl.create(:return_authorization_reason)
|
137
|
+
rma_params = { :stock_location_id => stock_location.id,
|
138
|
+
:return_authorization_reason_id => reason.id,
|
139
|
+
:memo => "Defective" }
|
140
|
+
api_post :create, :order_id => order.number, :return_authorization => rma_params
|
141
|
+
response.status.should == 201
|
142
|
+
json_response.should have_attributes(attributes)
|
143
|
+
json_response["state"].should_not be_blank
|
168
144
|
end
|
169
145
|
end
|
170
146
|
|
171
147
|
context "as just another user" do
|
172
148
|
it "cannot add a return authorization to the order" do
|
173
|
-
api_post :create, :return_autorization => { :order_id => order.number, :
|
149
|
+
api_post :create, :return_autorization => { :order_id => order.number, :memo => "Defective" }
|
174
150
|
assert_unauthorized!
|
175
151
|
end
|
176
152
|
|
177
153
|
it "cannot update a return authorization on the order" do
|
178
154
|
FactoryGirl.create(:return_authorization, :order => order)
|
179
155
|
return_authorization = order.return_authorizations.first
|
180
|
-
api_put :update, :id => return_authorization.id, :return_authorization => { :
|
156
|
+
api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
|
181
157
|
assert_unauthorized!
|
182
|
-
|
158
|
+
return_authorization.reload.memo.should_not == "ABC"
|
183
159
|
end
|
184
160
|
|
185
161
|
it "cannot delete a return authorization on the order" do
|
@@ -187,7 +163,7 @@ module Spree
|
|
187
163
|
return_authorization = order.return_authorizations.first
|
188
164
|
api_delete :destroy, :id => return_authorization.id
|
189
165
|
assert_unauthorized!
|
190
|
-
|
166
|
+
lambda { return_authorization.reload }.should_not raise_error
|
191
167
|
end
|
192
168
|
end
|
193
169
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Spree::Api::ShipmentsController
|
3
|
+
describe Spree::Api::ShipmentsController 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] }
|
@@ -72,23 +72,23 @@ describe Spree::Api::ShipmentsController, :type => :controller do
|
|
72
72
|
}
|
73
73
|
|
74
74
|
api_put :update, params
|
75
|
-
|
76
|
-
|
75
|
+
response.status.should == 200
|
76
|
+
json_response['stock_location_name'].should == stock_location.name
|
77
77
|
end
|
78
78
|
|
79
79
|
it "can make a shipment ready" do
|
80
|
-
|
80
|
+
Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
|
81
81
|
api_put :ready
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
json_response.should have_attributes(attributes)
|
83
|
+
json_response["state"].should == "ready"
|
84
|
+
shipment.reload.state.should == "ready"
|
85
85
|
end
|
86
86
|
|
87
87
|
it "cannot make a shipment ready if the order is unpaid" do
|
88
|
-
|
88
|
+
Spree::Order.any_instance.stub(:paid? => false)
|
89
89
|
api_put :ready
|
90
|
-
|
91
|
-
|
90
|
+
json_response["error"].should == "Cannot ready shipment."
|
91
|
+
response.status.should == 422
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'for completed shipments' do
|
@@ -97,16 +97,16 @@ describe Spree::Api::ShipmentsController, :type => :controller do
|
|
97
97
|
|
98
98
|
it 'adds a variant to a shipment' do
|
99
99
|
api_put :add, { variant_id: variant.to_param, quantity: 2 }
|
100
|
-
|
101
|
-
|
100
|
+
response.status.should == 200
|
101
|
+
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 2
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'removes a variant from a shipment' do
|
105
105
|
order.contents.add(variant, 2)
|
106
106
|
|
107
107
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
108
|
-
|
109
|
-
|
108
|
+
response.status.should == 200
|
109
|
+
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'removes a destroyed variant from a shipment' do
|
@@ -114,29 +114,77 @@ describe Spree::Api::ShipmentsController, :type => :controller do
|
|
114
114
|
variant.destroy
|
115
115
|
|
116
116
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
117
|
-
|
118
|
-
|
117
|
+
response.status.should == 200
|
118
|
+
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
context "can transition a shipment from ready to ship" do
|
123
123
|
before do
|
124
|
-
|
124
|
+
Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
|
125
125
|
# For the shipment notification email
|
126
126
|
Spree::Config[:mails_from] = "spree@example.com"
|
127
127
|
|
128
128
|
shipment.update!(shipment.order)
|
129
|
-
|
130
|
-
|
129
|
+
shipment.state.should == "ready"
|
130
|
+
Spree::ShippingRate.any_instance.stub(:cost => 5)
|
131
131
|
end
|
132
132
|
|
133
133
|
it "can transition a shipment from ready to ship" do
|
134
134
|
shipment.reload
|
135
135
|
api_put :ship, id: shipment.to_param, shipment: { tracking: "123123", order_id: shipment.order.to_param }
|
136
|
-
|
137
|
-
|
136
|
+
json_response.should have_attributes(attributes)
|
137
|
+
json_response["state"].should == "shipped"
|
138
138
|
end
|
139
139
|
|
140
140
|
end
|
141
|
+
|
142
|
+
describe '#mine' do
|
143
|
+
subject do
|
144
|
+
api_get :mine, format: 'json', params: params
|
145
|
+
end
|
146
|
+
|
147
|
+
let(:params) { {} }
|
148
|
+
|
149
|
+
before { subject }
|
150
|
+
|
151
|
+
context "the current api user is authenticated and has orders" do
|
152
|
+
let(:current_api_user) { shipped_order.user }
|
153
|
+
let(:shipped_order) { create(:shipped_order) }
|
154
|
+
|
155
|
+
it 'succeeds' do
|
156
|
+
expect(response.status).to eq 200
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'json output' do
|
160
|
+
render_views
|
161
|
+
|
162
|
+
let(:rendered_shipment_ids) { json_response['shipments'].map { |s| s['id'] } }
|
163
|
+
|
164
|
+
it 'contains the shipments' do
|
165
|
+
expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'with filtering' do
|
170
|
+
let(:params) { {q: {order_completed_at_not_null: 1}} }
|
171
|
+
|
172
|
+
let!(:incomplete_order) { create(:order, user: current_api_user) }
|
173
|
+
|
174
|
+
it 'filters' do
|
175
|
+
expect(assigns(:shipments).map(&:id)).to match_array current_api_user.orders.complete.flat_map(&:shipments).map(&:id)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "the current api user is not persisted" do
|
181
|
+
let(:current_api_user) { Spree.user_class.new }
|
182
|
+
|
183
|
+
it "returns a 401" do
|
184
|
+
response.status.should == 401
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
141
189
|
end
|
142
190
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::StatesController
|
4
|
+
describe Api::StatesController do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:state) { create(:state, :name => "Victoria") }
|
@@ -13,37 +13,37 @@ module Spree
|
|
13
13
|
|
14
14
|
it "gets all states" do
|
15
15
|
api_get :index
|
16
|
-
|
17
|
-
|
16
|
+
json_response["states"].first.should have_attributes(attributes)
|
17
|
+
json_response['states'].first['name'].should eq(state.name)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "gets all the states for a particular country" do
|
21
21
|
api_get :index, :country_id => state.country.id
|
22
|
-
|
23
|
-
|
22
|
+
json_response["states"].first.should have_attributes(attributes)
|
23
|
+
json_response['states'].first['name'].should eq(state.name)
|
24
24
|
end
|
25
25
|
|
26
26
|
context "pagination" do
|
27
27
|
before do
|
28
|
-
|
29
|
-
|
28
|
+
State.should_receive(:accessible_by).and_return(@scope = double)
|
29
|
+
@scope.stub_chain(:ransack, :result, :includes, :order).and_return(@scope)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "does not paginate states results when asked not to do so" do
|
33
|
-
|
34
|
-
|
33
|
+
@scope.should_not_receive(:page)
|
34
|
+
@scope.should_not_receive(:per)
|
35
35
|
api_get :index
|
36
36
|
end
|
37
37
|
|
38
38
|
it "paginates when page parameter is passed through" do
|
39
|
-
|
40
|
-
|
39
|
+
@scope.should_receive(:page).with(1).and_return(@scope)
|
40
|
+
@scope.should_receive(:per).with(nil)
|
41
41
|
api_get :index, :page => 1
|
42
42
|
end
|
43
43
|
|
44
44
|
it "paginates when per_page parameter is passed through" do
|
45
|
-
|
46
|
-
|
45
|
+
@scope.should_receive(:page).with(nil).and_return(@scope)
|
46
|
+
@scope.should_receive(:per).with(25)
|
47
47
|
api_get :index, :per_page => 25
|
48
48
|
end
|
49
49
|
end
|
@@ -58,25 +58,25 @@ module Spree
|
|
58
58
|
state.save
|
59
59
|
|
60
60
|
api_get :index, :country_id => country.id
|
61
|
-
|
62
|
-
|
61
|
+
json_response["states"].first.should have_attributes(attributes)
|
62
|
+
json_response["states"].count.should == 1
|
63
63
|
json_response["states_required"] = true
|
64
64
|
end
|
65
65
|
|
66
66
|
it "can view all states" do
|
67
67
|
api_get :index
|
68
|
-
|
68
|
+
json_response["states"].first.should have_attributes(attributes)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'can query the results through a paramter' do
|
72
72
|
api_get :index, :q => { :name_cont => 'Vic' }
|
73
|
-
|
73
|
+
json_response['states'].first['name'].should eq("Victoria")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "can view a state" do
|
78
78
|
api_get :show, :id => state.id
|
79
|
-
|
79
|
+
json_response.should have_attributes(attributes)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::StockItemsController
|
4
|
+
describe Api::StockItemsController do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:stock_location) { create(:stock_location_with_items) }
|
@@ -16,12 +16,12 @@ module Spree
|
|
16
16
|
context "as a normal user" do
|
17
17
|
it "cannot list stock items for a stock location" do
|
18
18
|
api_get :index, stock_location_id: stock_location.to_param
|
19
|
-
|
19
|
+
response.status.should == 404
|
20
20
|
end
|
21
21
|
|
22
22
|
it "cannot see a stock item" do
|
23
23
|
api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
|
24
|
-
|
24
|
+
response.status.should == 404
|
25
25
|
end
|
26
26
|
|
27
27
|
it "cannot create a stock item" do
|
@@ -35,17 +35,17 @@ module Spree
|
|
35
35
|
}
|
36
36
|
|
37
37
|
api_post :create, params
|
38
|
-
|
38
|
+
response.status.should == 404
|
39
39
|
end
|
40
40
|
|
41
41
|
it "cannot update a stock item" do
|
42
42
|
api_put :update, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
|
43
|
-
|
43
|
+
response.status.should == 404
|
44
44
|
end
|
45
45
|
|
46
46
|
it "cannot destroy a stock item" do
|
47
47
|
api_delete :destroy, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
|
48
|
-
|
48
|
+
response.status.should == 404
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -54,33 +54,33 @@ module Spree
|
|
54
54
|
|
55
55
|
it 'cannot list of stock items' do
|
56
56
|
api_get :index, stock_location_id: stock_location.to_param
|
57
|
-
|
58
|
-
|
57
|
+
json_response['stock_items'].first.should have_attributes(attributes)
|
58
|
+
json_response['stock_items'].first['variant']['sku'].should include 'SKU'
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'requires a stock_location_id to be passed as a parameter' do
|
62
62
|
api_get :index
|
63
|
-
|
64
|
-
|
63
|
+
json_response['error'].should =~ /stock_location_id parameter must be provided/
|
64
|
+
response.status.should == 422
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'can control the page size through a parameter' do
|
68
68
|
api_get :index, stock_location_id: stock_location.to_param, per_page: 1
|
69
|
-
|
70
|
-
|
69
|
+
json_response['count'].should == 1
|
70
|
+
json_response['current_page'].should == 1
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'can query the results through a paramter' do
|
74
74
|
stock_item.update_column(:count_on_hand, 30)
|
75
75
|
api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }
|
76
|
-
|
77
|
-
|
76
|
+
json_response['count'].should == 1
|
77
|
+
json_response['stock_items'].first['count_on_hand'].should eq 30
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'gets a stock item' do
|
81
81
|
api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
|
82
|
-
|
83
|
-
|
82
|
+
json_response.should have_attributes(attributes)
|
83
|
+
json_response['count_on_hand'].should eq stock_item.count_on_hand
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'can create a new stock item' do
|
@@ -97,12 +97,12 @@ module Spree
|
|
97
97
|
}
|
98
98
|
|
99
99
|
api_post :create, params
|
100
|
-
|
101
|
-
|
100
|
+
response.status.should == 201
|
101
|
+
json_response.should have_attributes(attributes)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'can update a stock item to add new inventory' do
|
105
|
-
|
105
|
+
stock_item.count_on_hand.should == 10
|
106
106
|
params = {
|
107
107
|
id: stock_item.to_param,
|
108
108
|
stock_item: {
|
@@ -111,12 +111,12 @@ module Spree
|
|
111
111
|
}
|
112
112
|
|
113
113
|
api_put :update, params
|
114
|
-
|
115
|
-
|
114
|
+
response.status.should == 200
|
115
|
+
json_response['count_on_hand'].should eq 50
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'can set a stock item to modify the current inventory' do
|
119
|
-
|
119
|
+
stock_item.count_on_hand.should == 10
|
120
120
|
|
121
121
|
params = {
|
122
122
|
id: stock_item.to_param,
|
@@ -127,14 +127,14 @@ module Spree
|
|
127
127
|
}
|
128
128
|
|
129
129
|
api_put :update, params
|
130
|
-
|
131
|
-
|
130
|
+
response.status.should == 200
|
131
|
+
json_response['count_on_hand'].should eq 40
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'can delete a stock item' do
|
135
135
|
api_delete :destroy, id: stock_item.to_param
|
136
|
-
|
137
|
-
|
136
|
+
response.status.should == 204
|
137
|
+
lambda { Spree::StockItem.find(stock_item.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|