solidus_api 1.2.3 → 1.3.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +3 -2
- data/app/controllers/spree/api/base_controller.rb +10 -15
- data/app/controllers/spree/api/checkouts_controller.rb +56 -55
- data/app/controllers/spree/api/classifications_controller.rb +4 -4
- data/app/controllers/spree/api/config_controller.rb +6 -1
- data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
- data/app/controllers/spree/api/images_controller.rb +13 -13
- data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
- data/app/controllers/spree/api/line_items_controller.rb +27 -23
- data/app/controllers/spree/api/option_types_controller.rb +6 -5
- data/app/controllers/spree/api/option_values_controller.rb +12 -12
- data/app/controllers/spree/api/orders_controller.rb +6 -17
- data/app/controllers/spree/api/payments_controller.rb +15 -17
- data/app/controllers/spree/api/product_properties_controller.rb +13 -14
- data/app/controllers/spree/api/products_controller.rb +31 -28
- data/app/controllers/spree/api/promotions_controller.rb +9 -8
- data/app/controllers/spree/api/properties_controller.rb +9 -10
- data/app/controllers/spree/api/resource_controller.rb +9 -1
- data/app/controllers/spree/api/shipments_controller.rb +18 -18
- data/app/controllers/spree/api/states_controller.rb +8 -7
- data/app/controllers/spree/api/stock_items_controller.rb +2 -1
- data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
- data/app/controllers/spree/api/stores_controller.rb +0 -1
- data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
- data/app/controllers/spree/api/taxons_controller.rb +20 -19
- data/app/controllers/spree/api/users_controller.rb +1 -4
- data/app/controllers/spree/api/variants_controller.rb +19 -18
- data/app/controllers/spree/api/zones_controller.rb +3 -4
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/api_configuration.rb +1 -1
- data/app/views/spree/api/config/show.v1.rabl +2 -1
- data/app/views/spree/api/products/show.v1.rabl +1 -1
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
- data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
- data/lib/spree/api/engine.rb +8 -8
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/caching.rb +4 -4
- data/script/rails +0 -1
- data/solidus_api.gemspec +3 -3
- data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
- data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
- data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
- data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
- data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
- data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
- data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
- data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
- data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
- data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
- data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
- data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
- data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
- data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
- data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
- data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
- data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
- data/spec/features/checkout_spec.rb +2 -2
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/api/address_books_spec.rb +10 -11
- data/spec/requests/rabl_cache_spec.rb +7 -7
- data/spec/requests/ransackable_attributes_spec.rb +5 -7
- data/spec/shared_examples/protect_product_actions.rb +3 -4
- data/spec/spec_helper.rb +8 -4
- data/spec/support/controller_hacks.rb +5 -5
- data/spec/support/have_attributes_matcher.rb +0 -4
- data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
- metadata +9 -10
- data/app/models/spree/option_value_decorator.rb +0 -9
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
require 'shared_examples/protect_product_actions'
|
|
3
3
|
|
|
4
4
|
module Spree
|
|
5
|
-
describe Spree::Api::ProductsController, :
|
|
5
|
+
describe Spree::Api::ProductsController, type: :controller do
|
|
6
6
|
render_views
|
|
7
7
|
|
|
8
8
|
let!(:product) { create(:product) }
|
|
@@ -59,7 +59,7 @@ module Spree
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "retrieves a list of products by id" do
|
|
62
|
-
api_get :index, :
|
|
62
|
+
api_get :index, ids: [product.id]
|
|
63
63
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
|
64
64
|
expect(json_response["total_count"]).to eq(1)
|
|
65
65
|
expect(json_response["current_page"]).to eq(1)
|
|
@@ -78,7 +78,7 @@ module Spree
|
|
|
78
78
|
|
|
79
79
|
it "retrieves a list of products by ids string" do
|
|
80
80
|
second_product = create(:product)
|
|
81
|
-
api_get :index, :
|
|
81
|
+
api_get :index, ids: [product.id, second_product.id].join(",")
|
|
82
82
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
|
83
83
|
expect(json_response["products"][1]).to have_attributes(show_attributes)
|
|
84
84
|
expect(json_response["total_count"]).to eq(2)
|
|
@@ -88,7 +88,7 @@ module Spree
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "does not return inactive products when queried by ids" do
|
|
91
|
-
api_get :index, :
|
|
91
|
+
api_get :index, ids: [inactive_product.id]
|
|
92
92
|
expect(json_response["count"]).to eq(0)
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -99,8 +99,8 @@ module Spree
|
|
|
99
99
|
|
|
100
100
|
context "pagination" do
|
|
101
101
|
it "can select the next page of products" do
|
|
102
|
-
|
|
103
|
-
api_get :index, :
|
|
102
|
+
create(:product)
|
|
103
|
+
api_get :index, page: 2, per_page: 1
|
|
104
104
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
|
105
105
|
expect(json_response["total_count"]).to eq(2)
|
|
106
106
|
expect(json_response["current_page"]).to eq(2)
|
|
@@ -109,7 +109,7 @@ module Spree
|
|
|
109
109
|
|
|
110
110
|
it 'can control the page size through a parameter' do
|
|
111
111
|
create(:product)
|
|
112
|
-
api_get :index, :
|
|
112
|
+
api_get :index, per_page: 1
|
|
113
113
|
expect(json_response['count']).to eq(1)
|
|
114
114
|
expect(json_response['total_count']).to eq(2)
|
|
115
115
|
expect(json_response['current_page']).to eq(1)
|
|
@@ -118,40 +118,40 @@ module Spree
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "can search for products" do
|
|
121
|
-
create(:product, :
|
|
122
|
-
api_get :index, :
|
|
121
|
+
create(:product, name: "The best product in the world")
|
|
122
|
+
api_get :index, q: { name_cont: "best" }
|
|
123
123
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
|
124
124
|
expect(json_response["count"]).to eq(1)
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
it "gets a single product" do
|
|
128
|
-
product.master.images.create!(:
|
|
128
|
+
product.master.images.create!(attachment: image("thinking-cat.jpg"))
|
|
129
129
|
product.variants.create!
|
|
130
|
-
product.variants.first.images.create!(:
|
|
130
|
+
product.variants.first.images.create!(attachment: image("thinking-cat.jpg"))
|
|
131
131
|
product.set_property("spree", "rocks")
|
|
132
132
|
product.taxons << create(:taxon)
|
|
133
133
|
|
|
134
|
-
api_get :show, :
|
|
134
|
+
api_get :show, id: product.to_param
|
|
135
135
|
|
|
136
136
|
expect(json_response).to have_attributes(show_attributes)
|
|
137
137
|
expect(json_response['variants'].first).to have_attributes([:name,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
:is_master,
|
|
139
|
+
:price,
|
|
140
|
+
:images,
|
|
141
|
+
:in_stock])
|
|
142
142
|
|
|
143
143
|
expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
:attachment_width,
|
|
145
|
+
:attachment_height,
|
|
146
|
+
:attachment_content_type,
|
|
147
|
+
:mini_url,
|
|
148
|
+
:small_url,
|
|
149
|
+
:product_url,
|
|
150
|
+
:large_url])
|
|
151
151
|
|
|
152
152
|
expect(json_response["product_properties"].first).to have_attributes([:value,
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
:product_id,
|
|
154
|
+
:property_name])
|
|
155
155
|
|
|
156
156
|
expect(json_response["classifications"].first).to have_attributes([:taxon_id, :position, :taxon])
|
|
157
157
|
expect(json_response["classifications"].first['taxon']).to have_attributes([:id, :name, :pretty_name, :permalink, :taxonomy_id, :parent_id])
|
|
@@ -161,7 +161,7 @@ module Spree
|
|
|
161
161
|
before { Config.track_inventory_levels = false }
|
|
162
162
|
|
|
163
163
|
it "still displays valid json with total_on_hand Float::INFINITY" do
|
|
164
|
-
api_get :show, :
|
|
164
|
+
api_get :show, id: product.to_param
|
|
165
165
|
expect(response).to be_ok
|
|
166
166
|
expect(json_response[:total_on_hand]).to eq nil
|
|
167
167
|
end
|
|
@@ -170,29 +170,29 @@ module Spree
|
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
context "finds a product by slug first then by id" do
|
|
173
|
-
let!(:other_product) { create(:product, :
|
|
173
|
+
let!(:other_product) { create(:product, slug: "these-are-not-the-droids-you-are-looking-for") }
|
|
174
174
|
|
|
175
175
|
before do
|
|
176
176
|
product.update_column(:slug, "#{other_product.id}-and-1-ways")
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
specify do
|
|
180
|
-
api_get :show, :
|
|
180
|
+
api_get :show, id: product.to_param
|
|
181
181
|
expect(json_response["slug"]).to match(/and-1-ways/)
|
|
182
182
|
product.destroy
|
|
183
183
|
|
|
184
|
-
api_get :show, :
|
|
184
|
+
api_get :show, id: other_product.id
|
|
185
185
|
expect(json_response["slug"]).to match(/droids/)
|
|
186
186
|
end
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
it "cannot see inactive products" do
|
|
190
|
-
api_get :show, :
|
|
190
|
+
api_get :show, id: inactive_product.to_param
|
|
191
191
|
assert_not_found!
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
it "returns a 404 error when it cannot find a product" do
|
|
195
|
-
api_get :show, :
|
|
195
|
+
api_get :show, id: "non-existant"
|
|
196
196
|
assert_not_found!
|
|
197
197
|
end
|
|
198
198
|
|
|
@@ -225,7 +225,7 @@ module Spree
|
|
|
225
225
|
# Regression test for https://github.com/spree/spree/issues/1626
|
|
226
226
|
context "deleted products" do
|
|
227
227
|
before do
|
|
228
|
-
create(:product, :
|
|
228
|
+
create(:product, deleted_at: 1.day.ago)
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
it "does not include deleted products" do
|
|
@@ -234,26 +234,24 @@ module Spree
|
|
|
234
234
|
end
|
|
235
235
|
|
|
236
236
|
it "can include deleted products" do
|
|
237
|
-
api_get :index, :
|
|
237
|
+
api_get :index, show_deleted: 1
|
|
238
238
|
expect(json_response["products"].count).to eq(3)
|
|
239
239
|
end
|
|
240
240
|
end
|
|
241
241
|
|
|
242
242
|
describe "creating a product" do
|
|
243
243
|
it "can create a new product" do
|
|
244
|
-
api_post :create, :
|
|
245
|
-
:
|
|
246
|
-
:
|
|
244
|
+
api_post :create, product: { name: "The Other Product",
|
|
245
|
+
price: 19.99,
|
|
246
|
+
shipping_category_id: create(:shipping_category).id }
|
|
247
247
|
expect(json_response).to have_attributes(base_attributes)
|
|
248
248
|
expect(response.status).to eq(201)
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
it "creates with embedded variants" do
|
|
252
|
-
product_data
|
|
253
|
-
variants: [attributes_for_variant, attributes_for_variant]
|
|
254
|
-
})
|
|
252
|
+
product_data[:variants] = [attributes_for_variant, attributes_for_variant]
|
|
255
253
|
|
|
256
|
-
api_post :create, :
|
|
254
|
+
api_post :create, product: product_data
|
|
257
255
|
expect(response.status).to eq 201
|
|
258
256
|
|
|
259
257
|
variants = json_response['variants']
|
|
@@ -265,34 +263,30 @@ module Spree
|
|
|
265
263
|
end
|
|
266
264
|
|
|
267
265
|
it "can create a new product with embedded product_properties" do
|
|
268
|
-
product_data
|
|
269
|
-
product_properties_attributes: [{
|
|
266
|
+
product_data[:product_properties_attributes] = [{
|
|
270
267
|
property_name: "fabric",
|
|
271
268
|
value: "cotton"
|
|
272
269
|
}]
|
|
273
|
-
})
|
|
274
270
|
|
|
275
|
-
api_post :create, :
|
|
271
|
+
api_post :create, product: product_data
|
|
276
272
|
|
|
277
273
|
expect(json_response['product_properties'][0]['property_name']).to eq('fabric')
|
|
278
274
|
expect(json_response['product_properties'][0]['value']).to eq('cotton')
|
|
279
275
|
end
|
|
280
276
|
|
|
281
277
|
it "can create a new product with option_types" do
|
|
282
|
-
product_data
|
|
283
|
-
option_types: ['size', 'color']
|
|
284
|
-
})
|
|
278
|
+
product_data[:option_types] = ['size', 'color']
|
|
285
279
|
|
|
286
|
-
api_post :create, :
|
|
280
|
+
api_post :create, product: product_data
|
|
287
281
|
expect(json_response['option_types'].count).to eq(2)
|
|
288
282
|
end
|
|
289
283
|
|
|
290
284
|
it "creates with shipping categories" do
|
|
291
|
-
hash = { :
|
|
292
|
-
:
|
|
293
|
-
:
|
|
285
|
+
hash = { name: "The Other Product",
|
|
286
|
+
price: 19.99,
|
|
287
|
+
shipping_category: "Free Ships" }
|
|
294
288
|
|
|
295
|
-
api_post :create, :
|
|
289
|
+
api_post :create, product: hash
|
|
296
290
|
expect(response.status).to eq 201
|
|
297
291
|
|
|
298
292
|
shipping_id = ShippingCategory.find_by_name("Free Ships").id
|
|
@@ -301,14 +295,14 @@ module Spree
|
|
|
301
295
|
|
|
302
296
|
it "puts the created product in the given taxon" do
|
|
303
297
|
product_data[:taxon_ids] = taxon_1.id.to_s
|
|
304
|
-
api_post :create, :
|
|
305
|
-
expect(json_response["taxon_ids"]).to eq([taxon_1.id
|
|
298
|
+
api_post :create, product: product_data
|
|
299
|
+
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
|
|
306
300
|
end
|
|
307
301
|
|
|
308
302
|
# Regression test for https://github.com/spree/spree/issues/4123
|
|
309
303
|
it "puts the created product in the given taxons" do
|
|
310
304
|
product_data[:taxon_ids] = [taxon_1.id, taxon_2.id].join(',')
|
|
311
|
-
api_post :create, :
|
|
305
|
+
api_post :create, product: product_data
|
|
312
306
|
expect(json_response["taxon_ids"]).to eq([taxon_1.id, taxon_2.id])
|
|
313
307
|
end
|
|
314
308
|
|
|
@@ -323,7 +317,7 @@ module Spree
|
|
|
323
317
|
end
|
|
324
318
|
|
|
325
319
|
it "can still create a product" do
|
|
326
|
-
api_post :create, :
|
|
320
|
+
api_post :create, product: product_data, token: "fake"
|
|
327
321
|
expect(json_response).to have_attributes(show_attributes)
|
|
328
322
|
expect(response.status).to eq(201)
|
|
329
323
|
end
|
|
@@ -340,22 +334,22 @@ module Spree
|
|
|
340
334
|
|
|
341
335
|
context 'updating a product' do
|
|
342
336
|
it "can update a product" do
|
|
343
|
-
api_put :update, :
|
|
337
|
+
api_put :update, id: product.to_param, product: { name: "New and Improved Product!" }
|
|
344
338
|
expect(response.status).to eq(200)
|
|
345
339
|
end
|
|
346
340
|
|
|
347
341
|
it "can create new option types on a product" do
|
|
348
|
-
api_put :update, :
|
|
342
|
+
api_put :update, id: product.to_param, product: { option_types: ['shape', 'color'] }
|
|
349
343
|
expect(json_response['option_types'].count).to eq(2)
|
|
350
344
|
end
|
|
351
345
|
|
|
352
346
|
it "can create new variants on a product" do
|
|
353
|
-
api_put :update, :
|
|
347
|
+
api_put :update, id: product.to_param, product: { variants: [attributes_for_variant, attributes_for_variant.merge(sku: "ABC-#{Kernel.rand(9999)}")] }
|
|
354
348
|
expect(response.status).to eq 200
|
|
355
349
|
expect(json_response['variants'].count).to eq(2) # 2 variants
|
|
356
350
|
|
|
357
351
|
variants = json_response['variants'].select { |v| !v['is_master'] }
|
|
358
|
-
size_option_value = variants.last['option_values'].detect{|x| x['option_type_name'] == 'size' }
|
|
352
|
+
size_option_value = variants.last['option_values'].detect{ |x| x['option_type_name'] == 'size' }
|
|
359
353
|
expect(size_option_value['name']).to eq('small')
|
|
360
354
|
|
|
361
355
|
expect(json_response['option_types'].count).to eq(2) # size, color
|
|
@@ -363,16 +357,16 @@ module Spree
|
|
|
363
357
|
|
|
364
358
|
it "can update an existing variant on a product" do
|
|
365
359
|
variant_hash = {
|
|
366
|
-
:
|
|
360
|
+
sku: '123', price: 19.99, options: [{ name: "size", value: "small" }]
|
|
367
361
|
}
|
|
368
362
|
variant_id = product.variants.create!({ product: product }.merge(variant_hash)).id
|
|
369
363
|
|
|
370
|
-
api_put :update, :
|
|
371
|
-
:
|
|
364
|
+
api_put :update, id: product.to_param, product: {
|
|
365
|
+
variants: [
|
|
372
366
|
variant_hash.merge(
|
|
373
|
-
:
|
|
374
|
-
:
|
|
375
|
-
:
|
|
367
|
+
id: variant_id.to_s,
|
|
368
|
+
sku: '456',
|
|
369
|
+
options: [{ name: "size", value: "large" }]
|
|
376
370
|
)
|
|
377
371
|
]
|
|
378
372
|
}
|
|
@@ -385,7 +379,7 @@ module Spree
|
|
|
385
379
|
end
|
|
386
380
|
|
|
387
381
|
it "cannot update a product with an invalid attribute" do
|
|
388
|
-
api_put :update, :
|
|
382
|
+
api_put :update, id: product.to_param, product: { name: "" }
|
|
389
383
|
expect(response.status).to eq(422)
|
|
390
384
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
|
391
385
|
expect(json_response["errors"]["name"]).to eq(["can't be blank"])
|
|
@@ -393,20 +387,20 @@ module Spree
|
|
|
393
387
|
|
|
394
388
|
# Regression test for https://github.com/spree/spree/issues/4123
|
|
395
389
|
it "puts the created product in the given taxon" do
|
|
396
|
-
api_put :update, :
|
|
390
|
+
api_put :update, id: product.to_param, product: { taxon_ids: taxon_1.id.to_s }
|
|
397
391
|
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
|
|
398
392
|
end
|
|
399
393
|
|
|
400
394
|
# Regression test for https://github.com/spree/spree/issues/4123
|
|
401
395
|
it "puts the created product in the given taxons" do
|
|
402
|
-
api_put :update, :
|
|
396
|
+
api_put :update, id: product.to_param, product: { taxon_ids: [taxon_1.id, taxon_2.id].join(',') }
|
|
403
397
|
expect(json_response["taxon_ids"]).to match_array([taxon_1.id, taxon_2.id])
|
|
404
398
|
end
|
|
405
399
|
end
|
|
406
400
|
|
|
407
401
|
it "can delete a product" do
|
|
408
402
|
expect(product.deleted_at).to be_nil
|
|
409
|
-
api_delete :destroy, :
|
|
403
|
+
api_delete :destroy, id: product.to_param
|
|
410
404
|
expect(response.status).to eq(204)
|
|
411
405
|
expect(product.reload.deleted_at).not_to be_nil
|
|
412
406
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Spree::Api
|
|
4
|
-
describe OrdersController, :
|
|
4
|
+
describe OrdersController, type: :controller do
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
7
|
before do
|
|
@@ -9,7 +9,7 @@ module Spree::Api
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
context "with an available promotion" do
|
|
12
|
-
let!(:order) { create(:order_with_line_items, :
|
|
12
|
+
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
|
|
13
13
|
let!(:promotion) do
|
|
14
14
|
promotion = create(:promotion, name: "10% off", code: "10off")
|
|
15
15
|
calculator = Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10")
|
|
@@ -20,7 +20,7 @@ module Spree::Api
|
|
|
20
20
|
|
|
21
21
|
it "can apply a coupon code to the order" do
|
|
22
22
|
expect(order.total).to eq(110.00)
|
|
23
|
-
api_put :apply_coupon_code, :
|
|
23
|
+
api_put :apply_coupon_code, id: order.to_param, coupon_code: "10off", order_token: order.guest_token
|
|
24
24
|
expect(response.status).to eq(200)
|
|
25
25
|
expect(order.reload.total).to eq(109.00)
|
|
26
26
|
expect(json_response["success"]).to eq("The coupon code was successfully applied to your order.")
|
|
@@ -37,7 +37,7 @@ module Spree::Api
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "fails to apply" do
|
|
40
|
-
api_put :apply_coupon_code, :
|
|
40
|
+
api_put :apply_coupon_code, id: order.to_param, coupon_code: "10off", order_token: order.guest_token
|
|
41
41
|
expect(response.status).to eq(422)
|
|
42
42
|
expect(json_response["success"]).to be_blank
|
|
43
43
|
expect(json_response["error"]).to eq("The coupon code is expired")
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
module Spree
|
|
3
|
-
describe Spree::Api::PropertiesController, :
|
|
3
|
+
describe Spree::Api::PropertiesController, type: :controller do
|
|
4
4
|
render_views
|
|
5
5
|
|
|
6
|
-
let!(:property_1) { Property.create!(:
|
|
7
|
-
let!(:property_2) { Property.create!(:
|
|
6
|
+
let!(:property_1) { Property.create!(name: "foo", presentation: "Foo") }
|
|
7
|
+
let!(:property_2) { Property.create!(name: "bar", presentation: "Bar") }
|
|
8
8
|
|
|
9
9
|
let(:attributes) { [:id, :name, :presentation] }
|
|
10
10
|
|
|
@@ -19,38 +19,38 @@ module Spree
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "can control the page size through a parameter" do
|
|
22
|
-
api_get :index, :
|
|
22
|
+
api_get :index, per_page: 1
|
|
23
23
|
expect(json_response['properties'].count).to eq(1)
|
|
24
24
|
expect(json_response['current_page']).to eq(1)
|
|
25
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
|
-
api_get :index, :
|
|
29
|
+
api_get :index, q: { name_cont: 'ba' }
|
|
30
30
|
expect(json_response['count']).to eq(1)
|
|
31
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
|
-
api_get :index, :
|
|
35
|
+
api_get :index, ids: [property_1.id]
|
|
36
36
|
expect(json_response["properties"].first).to have_attributes(attributes)
|
|
37
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
|
-
api_get :index, :
|
|
41
|
+
api_get :index, ids: [property_1.id, property_2.id].join(",")
|
|
42
42
|
expect(json_response["properties"].first).to have_attributes(attributes)
|
|
43
43
|
expect(json_response["properties"][1]).to have_attributes(attributes)
|
|
44
44
|
expect(json_response["count"]).to eq(2)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "can see a single property" do
|
|
48
|
-
api_get :show, :
|
|
48
|
+
api_get :show, id: property_1.id
|
|
49
49
|
expect(json_response).to have_attributes(attributes)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "can see a property by name" do
|
|
53
|
-
api_get :show, :
|
|
53
|
+
api_get :show, id: property_1.name
|
|
54
54
|
expect(json_response).to have_attributes(attributes)
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -61,17 +61,17 @@ module Spree
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "cannot create a new property if not an admin" do
|
|
64
|
-
api_post :create, :
|
|
64
|
+
api_post :create, property: { name: "My Property 3" }
|
|
65
65
|
assert_unauthorized!
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it "cannot update a property" do
|
|
69
|
-
api_put :update, :
|
|
69
|
+
api_put :update, id: property_1.name, property: { presentation: "my value 456" }
|
|
70
70
|
assert_unauthorized!
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "cannot delete a property" do
|
|
74
|
-
api_delete :destroy, :
|
|
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
|
|
@@ -81,19 +81,19 @@ module Spree
|
|
|
81
81
|
|
|
82
82
|
it "can create a new property" do
|
|
83
83
|
expect(Spree::Property.count).to eq(2)
|
|
84
|
-
api_post :create, :
|
|
84
|
+
api_post :create, property: { name: "My Property 3", presentation: "my value 3" }
|
|
85
85
|
expect(json_response).to have_attributes(attributes)
|
|
86
86
|
expect(response.status).to eq(201)
|
|
87
87
|
expect(Spree::Property.count).to eq(3)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "can update a property" do
|
|
91
|
-
api_put :update, :
|
|
91
|
+
api_put :update, id: property_1.name, property: { presentation: "my value 456" }
|
|
92
92
|
expect(response.status).to eq(200)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it "can delete a property" do
|
|
96
|
-
api_delete :destroy, :
|
|
96
|
+
api_delete :destroy, id: property_1.name
|
|
97
97
|
expect(response.status).to eq(204)
|
|
98
98
|
expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
99
99
|
end
|
|
@@ -59,10 +59,39 @@ module Spree
|
|
|
59
59
|
it "returns widgets" do
|
|
60
60
|
api_get :index, token: admin_user.spree_api_key
|
|
61
61
|
expect(response).to be_success
|
|
62
|
-
expect(json_response['widgets']).to include(
|
|
62
|
+
expect(json_response['widgets']).to include(hash_including(
|
|
63
63
|
'name' => 'a widget',
|
|
64
64
|
'position' => 1
|
|
65
|
-
)
|
|
65
|
+
))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "specifying ids" do
|
|
69
|
+
let!(:widget2) { Widget.create!(name: "a widget") }
|
|
70
|
+
|
|
71
|
+
it "returns both widgets from comma separated string" do
|
|
72
|
+
api_get :index, ids: [widget.id, widget2.id].join(','), token: admin_user.spree_api_key
|
|
73
|
+
expect(response).to be_success
|
|
74
|
+
expect(json_response['widgets'].size).to eq 2
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "returns both widgets from multiple arguments" do
|
|
78
|
+
api_get :index, ids: [widget.id, widget2.id], token: admin_user.spree_api_key
|
|
79
|
+
expect(response).to be_success
|
|
80
|
+
expect(json_response['widgets'].size).to eq 2
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "returns one requested widgets" do
|
|
84
|
+
api_get :index, ids: widget2.id.to_s, token: admin_user.spree_api_key
|
|
85
|
+
expect(response).to be_success
|
|
86
|
+
expect(json_response['widgets'].size).to eq 1
|
|
87
|
+
expect(json_response['widgets'][0]['id']).to eq widget2.id
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "returns no widgets if empty" do
|
|
91
|
+
api_get :index, ids: '', token: admin_user.spree_api_key
|
|
92
|
+
expect(response).to be_success
|
|
93
|
+
expect(json_response['widgets']).to be_empty
|
|
94
|
+
end
|
|
66
95
|
end
|
|
67
96
|
end
|
|
68
97
|
end
|