solidus_api 2.10.1 → 2.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +11 -3
- data/app/controllers/spree/api/checkouts_controller.rb +18 -15
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +2 -2
- data/app/controllers/spree/api/customer_returns_controller.rb +67 -0
- data/app/controllers/spree/api/images_controller.rb +4 -4
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/option_types_controller.rb +3 -3
- data/app/controllers/spree/api/option_values_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +8 -2
- data/app/controllers/spree/api/payments_controller.rb +1 -1
- data/app/controllers/spree/api/product_properties_controller.rb +9 -14
- data/app/controllers/spree/api/promotions_controller.rb +3 -12
- data/app/controllers/spree/api/properties_controller.rb +3 -3
- data/app/controllers/spree/api/resource_controller.rb +2 -2
- data/app/controllers/spree/api/return_authorizations_controller.rb +3 -3
- data/app/controllers/spree/api/shipments_controller.rb +1 -1
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +2 -2
- data/app/controllers/spree/api/stock_locations_controller.rb +3 -3
- data/app/controllers/spree/api/stock_movements_controller.rb +3 -3
- data/app/controllers/spree/api/stores_controller.rb +3 -3
- data/app/controllers/spree/api/taxonomies_controller.rb +2 -2
- data/app/controllers/spree/api/taxons_controller.rb +4 -4
- data/app/controllers/spree/api/users_controller.rb +13 -0
- data/app/controllers/spree/api/variants_controller.rb +3 -3
- data/app/controllers/spree/api/zones_controller.rb +2 -2
- data/app/helpers/spree/api/api_helpers.rb +18 -5
- data/app/views/spree/api/customer_returns/index.json.jbuilder +6 -0
- data/app/views/spree/api/customer_returns/new.json.jbuilder +4 -0
- data/app/views/spree/api/customer_returns/show.json.jbuilder +3 -0
- data/app/views/spree/api/errors/could_not_transition.json.jbuilder +4 -0
- data/app/views/spree/api/orders/could_not_transition.json.jbuilder +5 -0
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +6 -3
- data/lib/spree/api/testing_support/helpers.rb +11 -2
- data/openapi/authentication.md +9 -1
- data/openapi/checkout-flow.md +17 -4
- data/openapi/main.hub.yml +1 -1
- data/openapi/solidus-api.oas.yml +6753 -0
- data/solidus_api.gemspec +19 -19
- metadata +17 -117
- data/openapi/api.oas2.yml +0 -6105
- data/script/rails +0 -10
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -118
- data/spec/controllers/spree/api/resource_controller_spec.rb +0 -190
- data/spec/features/checkout_spec.rb +0 -192
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/lib/spree_api_responders_spec.rb +0 -10
- data/spec/models/spree/legacy_user_spec.rb +0 -103
- data/spec/requests/api/address_books_spec.rb +0 -240
- data/spec/requests/jbuilder_cache_spec.rb +0 -34
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
- data/spec/requests/spree/api/addresses_controller_spec.rb +0 -57
- data/spec/requests/spree/api/checkouts_controller_spec.rb +0 -456
- data/spec/requests/spree/api/classifications_controller_spec.rb +0 -50
- data/spec/requests/spree/api/config_controller_spec.rb +0 -26
- data/spec/requests/spree/api/countries_controller_spec.rb +0 -48
- data/spec/requests/spree/api/coupon_codes_controller_spec.rb +0 -105
- data/spec/requests/spree/api/credit_cards_controller_spec.rb +0 -105
- data/spec/requests/spree/api/images_controller_spec.rb +0 -99
- data/spec/requests/spree/api/inventory_units_controller_spec.rb +0 -55
- data/spec/requests/spree/api/line_items_controller_spec.rb +0 -213
- data/spec/requests/spree/api/option_types_controller_spec.rb +0 -116
- data/spec/requests/spree/api/option_values_controller_spec.rb +0 -138
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -931
- data/spec/requests/spree/api/payments_controller_spec.rb +0 -259
- data/spec/requests/spree/api/product_properties_controller_spec.rb +0 -114
- data/spec/requests/spree/api/products_controller_spec.rb +0 -422
- data/spec/requests/spree/api/promotion_application_spec.rb +0 -50
- data/spec/requests/spree/api/promotions_controller_spec.rb +0 -67
- data/spec/requests/spree/api/properties_controller_spec.rb +0 -102
- data/spec/requests/spree/api/return_authorizations_controller_spec.rb +0 -180
- data/spec/requests/spree/api/shipments_controller_spec.rb +0 -532
- data/spec/requests/spree/api/states_controller_spec.rb +0 -69
- data/spec/requests/spree/api/stock_items_controller_spec.rb +0 -311
- data/spec/requests/spree/api/stock_locations_controller_spec.rb +0 -170
- data/spec/requests/spree/api/stock_movements_controller_spec.rb +0 -81
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +0 -59
- data/spec/requests/spree/api/stores_controller_spec.rb +0 -134
- data/spec/requests/spree/api/taxonomies_controller_spec.rb +0 -114
- data/spec/requests/spree/api/taxons_controller_spec.rb +0 -217
- data/spec/requests/spree/api/unauthenticated_products_controller_spec.rb +0 -27
- data/spec/requests/spree/api/users_controller_spec.rb +0 -151
- data/spec/requests/spree/api/variants_controller_spec.rb +0 -340
- data/spec/requests/spree/api/zones_controller_spec.rb +0 -89
- data/spec/shared_examples/protect_product_actions.rb +0 -18
- data/spec/spec_helper.rb +0 -73
- data/spec/support/be_paginated_matcher.rb +0 -9
- data/spec/support/controller_hacks.rb +0 -43
- data/spec/support/database_cleaner.rb +0 -16
- data/spec/support/have_attributes_matcher.rb +0 -11
- data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +0 -3
- data/spec/test_views/spree/api/widgets/index.json.jbuilder +0 -9
- data/spec/test_views/spree/api/widgets/new.json.jbuilder +0 -3
- data/spec/test_views/spree/api/widgets/show.json.jbuilder +0 -3
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::StatesController, type: :request do
|
7
|
-
let!(:state) { create(:state, name: "Victoria") }
|
8
|
-
let(:attributes) { [:id, :name, :abbr, :country_id] }
|
9
|
-
|
10
|
-
before do
|
11
|
-
stub_authentication!
|
12
|
-
end
|
13
|
-
|
14
|
-
it "gets all states" do
|
15
|
-
get spree.api_states_path
|
16
|
-
expect(json_response["states"].first).to have_attributes(attributes)
|
17
|
-
expect(json_response['states'].first['name']).to eq(state.name)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "gets all the states for a particular country" do
|
21
|
-
get spree.api_country_states_path(state.country)
|
22
|
-
expect(json_response["states"].first).to have_attributes(attributes)
|
23
|
-
expect(json_response['states'].first['name']).to eq(state.name)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "pagination" do
|
27
|
-
it "can select the next page and control page size" do
|
28
|
-
create(:state)
|
29
|
-
get spree.api_states_path, params: { page: 2, per_page: 1 }
|
30
|
-
|
31
|
-
expect(json_response).to be_paginated
|
32
|
-
expect(json_response["states"].size).to eq(1)
|
33
|
-
expect(json_response["pages"]).to eq(2)
|
34
|
-
expect(json_response["current_page"]).to eq(2)
|
35
|
-
expect(json_response["count"]).to eq(1)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with two states" do
|
40
|
-
before { create(:state, name: "New South Wales") }
|
41
|
-
|
42
|
-
it "gets all states for a country" do
|
43
|
-
country = create(:country, states_required: true)
|
44
|
-
state.country = country
|
45
|
-
state.save
|
46
|
-
|
47
|
-
get spree.api_country_states_path(country)
|
48
|
-
expect(json_response["states"].first).to have_attributes(attributes)
|
49
|
-
expect(json_response["states"].count).to eq(1)
|
50
|
-
json_response["states_required"] = true
|
51
|
-
end
|
52
|
-
|
53
|
-
it "can view all states" do
|
54
|
-
get spree.api_states_path
|
55
|
-
expect(json_response["states"].first).to have_attributes(attributes)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'can query the results through a paramter' do
|
59
|
-
get spree.api_states_path, params: { q: { name_cont: 'Vic' } }
|
60
|
-
expect(json_response['states'].first['name']).to eq("Victoria")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can view a state" do
|
65
|
-
get spree.api_state_path(state)
|
66
|
-
expect(json_response).to have_attributes(attributes)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,311 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::StockItemsController, type: :request do
|
7
|
-
let!(:stock_location) { create(:stock_location_with_items) }
|
8
|
-
let!(:stock_item) { stock_location.stock_items.order(:id).first }
|
9
|
-
let!(:attributes) {
|
10
|
-
[:id, :count_on_hand, :backorderable,
|
11
|
-
:stock_location_id, :variant_id]
|
12
|
-
}
|
13
|
-
|
14
|
-
before do
|
15
|
-
stub_authentication!
|
16
|
-
end
|
17
|
-
|
18
|
-
context "as a normal user" do
|
19
|
-
describe "#index" do
|
20
|
-
it "can list stock items for an active stock location" do
|
21
|
-
get spree.api_stock_location_stock_items_path(stock_location)
|
22
|
-
expect(response).to be_successful
|
23
|
-
expect(json_response['stock_items'].first).to have_attributes(attributes)
|
24
|
-
expect(json_response['stock_items'].first['variant']['sku']).to match /\ASKU-\d+\z/
|
25
|
-
end
|
26
|
-
|
27
|
-
it "cannot list stock items for an inactive stock location" do
|
28
|
-
stock_location.update!(active: false)
|
29
|
-
get spree.api_stock_location_stock_items_path(stock_location)
|
30
|
-
expect(response).to be_not_found
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#show" do
|
35
|
-
it "can see a stock item for an active stock location" do
|
36
|
-
get spree.api_stock_location_stock_item_path(stock_location, stock_item)
|
37
|
-
expect(json_response).to have_attributes(attributes)
|
38
|
-
expect(json_response['count_on_hand']).to eq stock_item.count_on_hand
|
39
|
-
end
|
40
|
-
|
41
|
-
it "cannot see a stock item for an inactive stock location" do
|
42
|
-
stock_location.update!(active: false)
|
43
|
-
get spree.api_stock_location_stock_item_path(stock_location, stock_item)
|
44
|
-
expect(response.status).to eq(404)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#create" do
|
49
|
-
it "cannot create a stock item" do
|
50
|
-
variant = create(:variant)
|
51
|
-
params = {
|
52
|
-
stock_item: {
|
53
|
-
variant_id: variant.id,
|
54
|
-
count_on_hand: '20'
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
post spree.api_stock_location_stock_items_path(stock_location), params: params
|
59
|
-
expect(response.status).to eq(401)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#update" do
|
64
|
-
it "cannot update a stock item" do
|
65
|
-
put spree.api_stock_location_stock_item_path(stock_location, stock_item)
|
66
|
-
expect(response.status).to eq(404)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#destroy" do
|
71
|
-
it "cannot destroy a stock item" do
|
72
|
-
delete spree.api_stock_location_stock_item_path(stock_location, stock_item)
|
73
|
-
expect(response.status).to eq(404)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "as an admin" do
|
79
|
-
sign_in_as_admin!
|
80
|
-
|
81
|
-
it 'can list stock items' do
|
82
|
-
get spree.api_stock_location_stock_items_path(stock_location)
|
83
|
-
expect(json_response['stock_items'].first).to have_attributes(attributes)
|
84
|
-
expect(json_response['stock_items'].first['variant']['sku']).to include 'SKU'
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'requires a stock_location_id to be passed as a parameter' do
|
88
|
-
get spree.api_stock_items_path
|
89
|
-
expect(json_response['exception']).to eq('param is missing or the value is empty: stock_location_id')
|
90
|
-
expect(response.status).to eq(422)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'can control the page size through a parameter' do
|
94
|
-
get spree.api_stock_location_stock_items_path(stock_location), params: { per_page: 1 }
|
95
|
-
expect(json_response['count']).to eq(1)
|
96
|
-
expect(json_response['current_page']).to eq(1)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'can query the results through a paramter' do
|
100
|
-
stock_item.update_column(:count_on_hand, 30)
|
101
|
-
get spree.api_stock_location_stock_items_path(stock_location), params: { q: { count_on_hand_eq: '30' } }
|
102
|
-
expect(json_response['count']).to eq(1)
|
103
|
-
expect(json_response['stock_items'].first['count_on_hand']).to eq 30
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'gets a stock item' do
|
107
|
-
get spree.api_stock_location_stock_item_path(stock_location, stock_item)
|
108
|
-
expect(json_response).to have_attributes(attributes)
|
109
|
-
expect(json_response['count_on_hand']).to eq stock_item.count_on_hand
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'creating a stock item' do
|
113
|
-
let!(:variant) do
|
114
|
-
variant = create(:variant)
|
115
|
-
# Creating a variant also creates stock items.
|
116
|
-
# We don't want any to exist (as they would conflict with what we're about to create)
|
117
|
-
StockItem.delete_all
|
118
|
-
variant
|
119
|
-
end
|
120
|
-
let(:count_on_hand) { '20' }
|
121
|
-
let(:params) do
|
122
|
-
{
|
123
|
-
stock_item: {
|
124
|
-
variant_id: variant.id,
|
125
|
-
count_on_hand: count_on_hand
|
126
|
-
}
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
subject do
|
131
|
-
post spree.api_stock_location_stock_items_path(stock_location), params: params
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'can create a new stock item' do
|
135
|
-
subject
|
136
|
-
expect(response.status).to eq 201
|
137
|
-
expect(json_response).to have_attributes(attributes)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'creates a stock movement' do
|
141
|
-
expect { subject }.to change { Spree::StockMovement.count }.by(1)
|
142
|
-
expect(assigns(:stock_movement).quantity).to eq 20
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'variant tracks inventory' do
|
146
|
-
before do
|
147
|
-
expect(variant.track_inventory).to eq true
|
148
|
-
end
|
149
|
-
|
150
|
-
it "sets the stock item's count_on_hand" do
|
151
|
-
subject
|
152
|
-
expect(assigns(:stock_item).count_on_hand).to eq 20
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'variant does not track inventory' do
|
157
|
-
before do
|
158
|
-
variant.update(track_inventory: false)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "doesn't set the stock item's count_on_hand" do
|
162
|
-
subject
|
163
|
-
expect(assigns(:stock_item).count_on_hand).to eq 0
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "attempting to set negative inventory" do
|
168
|
-
let(:count_on_hand) { '-1' }
|
169
|
-
|
170
|
-
it "does not allow negative inventory for the stock item" do
|
171
|
-
subject
|
172
|
-
expect(response.status).to eq 422
|
173
|
-
expect(response.body).to match I18n.t('spree.api.stock_not_below_zero')
|
174
|
-
expect(assigns(:stock_item).count_on_hand).to eq 0
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'updating a stock item' do
|
180
|
-
before do
|
181
|
-
expect(stock_item.count_on_hand).to eq 10
|
182
|
-
end
|
183
|
-
|
184
|
-
subject do
|
185
|
-
put spree.api_stock_item_path(stock_item), params: params
|
186
|
-
end
|
187
|
-
|
188
|
-
context 'adjusting count_on_hand' do
|
189
|
-
let(:count_on_hand) { 40 }
|
190
|
-
let(:params) do
|
191
|
-
{
|
192
|
-
stock_item: {
|
193
|
-
count_on_hand: count_on_hand,
|
194
|
-
backorderable: true
|
195
|
-
}
|
196
|
-
}
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'can update a stock item to add new inventory' do
|
200
|
-
subject
|
201
|
-
expect(response.status).to eq 200
|
202
|
-
expect(json_response['count_on_hand']).to eq 50
|
203
|
-
expect(json_response['backorderable']).to eq true
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'creates a stock movement for the adjusted quantity' do
|
207
|
-
expect { subject }.to change { Spree::StockMovement.count }.by(1)
|
208
|
-
expect(Spree::StockMovement.last.quantity).to eq 40
|
209
|
-
end
|
210
|
-
|
211
|
-
context 'tracking inventory' do
|
212
|
-
before do
|
213
|
-
expect(stock_item.should_track_inventory?).to eq true
|
214
|
-
end
|
215
|
-
|
216
|
-
it "sets the stock item's count_on_hand" do
|
217
|
-
subject
|
218
|
-
expect(assigns(:stock_item).count_on_hand).to eq 50
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context 'not tracking inventory' do
|
223
|
-
before do
|
224
|
-
stock_item.variant.update(track_inventory: false)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "doesn't set the stock item's count_on_hand" do
|
228
|
-
subject
|
229
|
-
expect(assigns(:stock_item).count_on_hand).to eq 10
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context "attempting to set negative inventory" do
|
234
|
-
let(:count_on_hand) { '-11' }
|
235
|
-
|
236
|
-
it "does not allow negative inventory for the stock item" do
|
237
|
-
subject
|
238
|
-
expect(response.status).to eq 422
|
239
|
-
expect(response.body).to match I18n.t('spree.api.stock_not_below_zero')
|
240
|
-
expect(assigns(:stock_item).count_on_hand).to eq 10
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'setting count_on_hand' do
|
246
|
-
let(:count_on_hand) { 40 }
|
247
|
-
let(:params) do
|
248
|
-
{
|
249
|
-
id: stock_item.to_param,
|
250
|
-
stock_item: {
|
251
|
-
count_on_hand: count_on_hand,
|
252
|
-
backorderable: true,
|
253
|
-
force: true
|
254
|
-
}
|
255
|
-
}
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'can set a stock item to modify the current inventory' do
|
259
|
-
subject
|
260
|
-
expect(response.status).to eq 200
|
261
|
-
expect(json_response['count_on_hand']).to eq 40
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'creates a stock movement for the adjusted quantity' do
|
265
|
-
expect { subject }.to change { Spree::StockMovement.count }.by(1)
|
266
|
-
expect(assigns(:stock_movement).quantity).to eq 30
|
267
|
-
end
|
268
|
-
|
269
|
-
context 'tracking inventory' do
|
270
|
-
before do
|
271
|
-
expect(stock_item.should_track_inventory?).to eq true
|
272
|
-
end
|
273
|
-
|
274
|
-
it "updates the stock item's count_on_hand" do
|
275
|
-
subject
|
276
|
-
expect(assigns(:stock_item).count_on_hand).to eq 40
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context 'not tracking inventory' do
|
281
|
-
before do
|
282
|
-
stock_item.variant.update(track_inventory: false)
|
283
|
-
end
|
284
|
-
|
285
|
-
it "doesn't update the stock item's count_on_hand" do
|
286
|
-
subject
|
287
|
-
expect(assigns(:stock_item).count_on_hand).to eq 10
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
context "attempting to set negative inventory" do
|
292
|
-
let(:count_on_hand) { '-1' }
|
293
|
-
|
294
|
-
it "does not allow negative inventory for the stock item" do
|
295
|
-
subject
|
296
|
-
expect(response.status).to eq 422
|
297
|
-
expect(response.body).to match I18n.t('spree.api.stock_not_below_zero')
|
298
|
-
expect(assigns(:stock_item).count_on_hand).to eq 10
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'can delete a stock item' do
|
305
|
-
delete spree.api_stock_item_path(stock_item)
|
306
|
-
expect(response.status).to eq(204)
|
307
|
-
expect { Spree::StockItem.find(stock_item.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::StockLocationsController, type: :request do
|
7
|
-
let!(:stock_location) { create(:stock_location) }
|
8
|
-
let!(:attributes) { [:id, :name, :address1, :address2, :city, :state_id, :state_name, :country_id, :zipcode, :phone, :active] }
|
9
|
-
|
10
|
-
before do
|
11
|
-
stub_authentication!
|
12
|
-
end
|
13
|
-
|
14
|
-
context "as a user" do
|
15
|
-
describe "#index" do
|
16
|
-
it "can see active stock locations" do
|
17
|
-
get spree.api_stock_locations_path
|
18
|
-
expect(response).to be_successful
|
19
|
-
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
20
|
-
expect(stock_locations).to include stock_location.name
|
21
|
-
end
|
22
|
-
|
23
|
-
it "cannot see inactive stock locations" do
|
24
|
-
stock_location.update!(active: false)
|
25
|
-
get spree.api_stock_locations_path
|
26
|
-
expect(response).to be_successful
|
27
|
-
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
28
|
-
expect(stock_locations).not_to include stock_location.name
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#show" do
|
33
|
-
it "can see active stock locations" do
|
34
|
-
get spree.api_stock_location_path(stock_location)
|
35
|
-
expect(response).to be_successful
|
36
|
-
expect(json_response['name']).to eq stock_location.name
|
37
|
-
end
|
38
|
-
|
39
|
-
it "cannot see inactive stock locations" do
|
40
|
-
stock_location.update!(active: false)
|
41
|
-
get spree.api_stock_location_path(stock_location)
|
42
|
-
expect(response).to be_not_found
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#create" do
|
47
|
-
it "cannot create a new stock location" do
|
48
|
-
params = {
|
49
|
-
stock_location: {
|
50
|
-
name: "North Pole",
|
51
|
-
active: true
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
post spree.api_stock_locations_path, params: params
|
56
|
-
expect(response.status).to eq(401)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#update" do
|
61
|
-
it "cannot update a stock location" do
|
62
|
-
put spree.api_stock_location_path(stock_location), params: { stock_location: { name: "South Pole" } }
|
63
|
-
expect(response.status).to eq(401)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#destroy" do
|
68
|
-
it "cannot delete a stock location" do
|
69
|
-
delete spree.api_stock_location_path(stock_location)
|
70
|
-
expect(response.status).to eq(401)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "as an admin" do
|
76
|
-
sign_in_as_admin!
|
77
|
-
|
78
|
-
describe "#index" do
|
79
|
-
it "can see active stock locations" do
|
80
|
-
get spree.api_stock_locations_path
|
81
|
-
expect(response).to be_successful
|
82
|
-
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
83
|
-
expect(stock_locations).to include stock_location.name
|
84
|
-
end
|
85
|
-
|
86
|
-
it "can see inactive stock locations" do
|
87
|
-
stock_location.update!(active: false)
|
88
|
-
get spree.api_stock_locations_path
|
89
|
-
expect(response).to be_successful
|
90
|
-
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
|
91
|
-
expect(stock_locations).to include stock_location.name
|
92
|
-
end
|
93
|
-
|
94
|
-
it "gets stock location information" do
|
95
|
-
get spree.api_stock_locations_path
|
96
|
-
expect(json_response['stock_locations'].first).to have_attributes(attributes)
|
97
|
-
expect(json_response['stock_locations'].first['country']).not_to be_nil
|
98
|
-
expect(json_response['stock_locations'].first['state']).not_to be_nil
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'can control the page size through a parameter' do
|
102
|
-
create(:stock_location)
|
103
|
-
get spree.api_stock_locations_path, params: { per_page: 1 }
|
104
|
-
expect(json_response['count']).to eq(1)
|
105
|
-
expect(json_response['current_page']).to eq(1)
|
106
|
-
expect(json_response['pages']).to eq(2)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'can query the results through a paramter' do
|
110
|
-
expected_result = create(:stock_location, name: 'South America')
|
111
|
-
get spree.api_stock_locations_path, params: { q: { name_cont: 'south' } }
|
112
|
-
expect(json_response['count']).to eq(1)
|
113
|
-
expect(json_response['stock_locations'].first['name']).to eq expected_result.name
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#show" do
|
118
|
-
it "can see active stock locations" do
|
119
|
-
get spree.api_stock_location_path(stock_location)
|
120
|
-
expect(response).to be_successful
|
121
|
-
expect(json_response['name']).to eq stock_location.name
|
122
|
-
end
|
123
|
-
|
124
|
-
it "can see inactive stock locations" do
|
125
|
-
stock_location.update!(active: false)
|
126
|
-
get spree.api_stock_location_path(stock_location)
|
127
|
-
expect(response).to be_successful
|
128
|
-
expect(json_response['name']).to eq stock_location.name
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "#create" do
|
133
|
-
it "can create a new stock location" do
|
134
|
-
params = {
|
135
|
-
stock_location: {
|
136
|
-
name: "North Pole",
|
137
|
-
active: true
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
post spree.api_stock_locations_path, params: params
|
142
|
-
expect(response.status).to eq(201)
|
143
|
-
expect(json_response).to have_attributes(attributes)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#update" do
|
148
|
-
it "can update a stock location" do
|
149
|
-
params = {
|
150
|
-
stock_location: {
|
151
|
-
name: "South Pole"
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
put spree.api_stock_location_path(stock_location), params: params
|
156
|
-
expect(response.status).to eq(200)
|
157
|
-
expect(json_response['name']).to eq 'South Pole'
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe "#destroy" do
|
162
|
-
it "can delete a stock location" do
|
163
|
-
delete spree.api_stock_location_path(stock_location)
|
164
|
-
expect(response.status).to eq(204)
|
165
|
-
expect { stock_location.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|