spree_api 3.3.0.rc1 → 3.3.0.rc2
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/v1/users_controller.rb +9 -1
- data/config/routes.rb +7 -1
- data/spree_api.gemspec +1 -2
- metadata +6 -94
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -84
- data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +0 -56
- data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +0 -361
- data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +0 -48
- data/spec/controllers/spree/api/v1/countries_controller_spec.rb +0 -48
- data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +0 -80
- data/spec/controllers/spree/api/v1/customer_returns_controller_spec.rb +0 -27
- data/spec/controllers/spree/api/v1/images_controller_spec.rb +0 -114
- data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +0 -48
- data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +0 -210
- data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +0 -122
- data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +0 -141
- data/spec/controllers/spree/api/v1/orders_controller_spec.rb +0 -735
- data/spec/controllers/spree/api/v1/payments_controller_spec.rb +0 -234
- data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +0 -156
- data/spec/controllers/spree/api/v1/products_controller_spec.rb +0 -409
- data/spec/controllers/spree/api/v1/promotion_application_spec.rb +0 -50
- data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +0 -64
- data/spec/controllers/spree/api/v1/properties_controller_spec.rb +0 -102
- data/spec/controllers/spree/api/v1/reimbursements_controller_spec.rb +0 -24
- data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +0 -161
- data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +0 -187
- data/spec/controllers/spree/api/v1/states_controller_spec.rb +0 -86
- data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +0 -151
- data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +0 -113
- data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +0 -84
- data/spec/controllers/spree/api/v1/stores_controller_spec.rb +0 -133
- data/spec/controllers/spree/api/v1/tags_controller_spec.rb +0 -102
- data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +0 -114
- data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +0 -177
- data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +0 -26
- data/spec/controllers/spree/api/v1/users_controller_spec.rb +0 -153
- data/spec/controllers/spree/api/v1/variants_controller_spec.rb +0 -205
- data/spec/controllers/spree/api/v1/zones_controller_spec.rb +0 -91
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/legacy_user_spec.rb +0 -19
- data/spec/requests/rabl_cache_spec.rb +0 -32
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
- data/spec/requests/version_spec.rb +0 -19
- data/spec/shared_examples/protect_product_actions.rb +0 -17
- data/spec/spec_helper.rb +0 -63
- data/spec/support/controller_hacks.rb +0 -40
- data/spec/support/database_cleaner.rb +0 -14
- data/spec/support/have_attributes_matcher.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23d326e39ca317d532c54546890bd3983f95c502
|
4
|
+
data.tar.gz: e75a525d378f3a1448040ee11f1220737a2db6f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 032b7f4f3abcbab1843cd5bf1992e5c2fc60993f02a79dcef12881d252bace12e764cade45734a32e691a36f1658f00c1e45f47c76252ed7ee1bf60b25a8b8ce
|
7
|
+
data.tar.gz: 6219755053eb139c06e9601360adadb7c0f8f96e326c78e4a66b961577dc2e3bd63d50f51c46e306f2820148704dadf652c72197f0ce2643fd9785c9dabb9645
|
@@ -6,7 +6,15 @@ module Spree
|
|
6
6
|
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
7
7
|
|
8
8
|
def index
|
9
|
-
@users = Spree.user_class.accessible_by(current_ability
|
9
|
+
@users = Spree.user_class.accessible_by(current_ability, :read)
|
10
|
+
|
11
|
+
@users = if params[:ids]
|
12
|
+
@users.ransack(id_in: params[:ids].split(','))
|
13
|
+
else
|
14
|
+
@users.ransack(params[:q])
|
15
|
+
end
|
16
|
+
|
17
|
+
@users = @users.result.page(params[:page]).per(params[:per_page])
|
10
18
|
expires_in 15.minutes, public: true
|
11
19
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
12
20
|
respond_with(@users)
|
data/config/routes.rb
CHANGED
@@ -121,7 +121,13 @@ Spree::Core::Engine.add_routes do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
spree_path = Rails.application.routes.url_helpers.try(:spree_path, trailing_slash: true) || '/'
|
124
|
-
|
124
|
+
|
125
|
+
match 'v:api/*path', to: redirect{ |params, request|
|
126
|
+
format = ".#{params[:format]}" unless params[:format].blank?
|
127
|
+
query = "?#{request.query_string}" unless request.query_string.blank?
|
128
|
+
|
129
|
+
"#{spree_path}api/v1/#{params[:path]}#{format}#{query}"
|
130
|
+
}, via: [:get, :post, :put, :patch, :delete]
|
125
131
|
|
126
132
|
match '*path', to: redirect{ |params, request|
|
127
133
|
format = ".#{params[:format]}" unless params[:format].blank?
|
data/spree_api.gemspec
CHANGED
@@ -11,9 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
|
12
12
|
s.required_ruby_version = '>= 2.2.7'
|
13
13
|
|
14
|
-
s.files = `git ls-files`.split($\)
|
14
|
+
s.files = `git ls-files`.split($\).reject { |f| f.match(/^spec/) }
|
15
15
|
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
16
|
s.name = "spree_api"
|
18
17
|
s.require_paths = ["lib"]
|
19
18
|
s.version = Spree.version
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.0.
|
4
|
+
version: 3.3.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.3.0.
|
19
|
+
version: 3.3.0.rc2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.3.0.
|
26
|
+
version: 3.3.0.rc2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,50 +213,6 @@ files:
|
|
213
213
|
- lib/spree/api/testing_support/setup.rb
|
214
214
|
- lib/spree_api.rb
|
215
215
|
- script/rails
|
216
|
-
- spec/controllers/spree/api/base_controller_spec.rb
|
217
|
-
- spec/controllers/spree/api/v1/addresses_controller_spec.rb
|
218
|
-
- spec/controllers/spree/api/v1/checkouts_controller_spec.rb
|
219
|
-
- spec/controllers/spree/api/v1/classifications_controller_spec.rb
|
220
|
-
- spec/controllers/spree/api/v1/countries_controller_spec.rb
|
221
|
-
- spec/controllers/spree/api/v1/credit_cards_controller_spec.rb
|
222
|
-
- spec/controllers/spree/api/v1/customer_returns_controller_spec.rb
|
223
|
-
- spec/controllers/spree/api/v1/images_controller_spec.rb
|
224
|
-
- spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
|
225
|
-
- spec/controllers/spree/api/v1/line_items_controller_spec.rb
|
226
|
-
- spec/controllers/spree/api/v1/option_types_controller_spec.rb
|
227
|
-
- spec/controllers/spree/api/v1/option_values_controller_spec.rb
|
228
|
-
- spec/controllers/spree/api/v1/orders_controller_spec.rb
|
229
|
-
- spec/controllers/spree/api/v1/payments_controller_spec.rb
|
230
|
-
- spec/controllers/spree/api/v1/product_properties_controller_spec.rb
|
231
|
-
- spec/controllers/spree/api/v1/products_controller_spec.rb
|
232
|
-
- spec/controllers/spree/api/v1/promotion_application_spec.rb
|
233
|
-
- spec/controllers/spree/api/v1/promotions_controller_spec.rb
|
234
|
-
- spec/controllers/spree/api/v1/properties_controller_spec.rb
|
235
|
-
- spec/controllers/spree/api/v1/reimbursements_controller_spec.rb
|
236
|
-
- spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
|
237
|
-
- spec/controllers/spree/api/v1/shipments_controller_spec.rb
|
238
|
-
- spec/controllers/spree/api/v1/states_controller_spec.rb
|
239
|
-
- spec/controllers/spree/api/v1/stock_items_controller_spec.rb
|
240
|
-
- spec/controllers/spree/api/v1/stock_locations_controller_spec.rb
|
241
|
-
- spec/controllers/spree/api/v1/stock_movements_controller_spec.rb
|
242
|
-
- spec/controllers/spree/api/v1/stores_controller_spec.rb
|
243
|
-
- spec/controllers/spree/api/v1/tags_controller_spec.rb
|
244
|
-
- spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
|
245
|
-
- spec/controllers/spree/api/v1/taxons_controller_spec.rb
|
246
|
-
- spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
|
247
|
-
- spec/controllers/spree/api/v1/users_controller_spec.rb
|
248
|
-
- spec/controllers/spree/api/v1/variants_controller_spec.rb
|
249
|
-
- spec/controllers/spree/api/v1/zones_controller_spec.rb
|
250
|
-
- spec/fixtures/thinking-cat.jpg
|
251
|
-
- spec/models/spree/legacy_user_spec.rb
|
252
|
-
- spec/requests/rabl_cache_spec.rb
|
253
|
-
- spec/requests/ransackable_attributes_spec.rb
|
254
|
-
- spec/requests/version_spec.rb
|
255
|
-
- spec/shared_examples/protect_product_actions.rb
|
256
|
-
- spec/spec_helper.rb
|
257
|
-
- spec/support/controller_hacks.rb
|
258
|
-
- spec/support/database_cleaner.rb
|
259
|
-
- spec/support/have_attributes_matcher.rb
|
260
216
|
- spree_api.gemspec
|
261
217
|
homepage: https://spreecommerce.com
|
262
218
|
licenses:
|
@@ -278,52 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
234
|
version: 1.3.1
|
279
235
|
requirements: []
|
280
236
|
rubyforge_project:
|
281
|
-
rubygems_version: 2.6.
|
237
|
+
rubygems_version: 2.6.10
|
282
238
|
signing_key:
|
283
239
|
specification_version: 4
|
284
240
|
summary: Spree's API
|
285
|
-
test_files:
|
286
|
-
- spec/controllers/spree/api/base_controller_spec.rb
|
287
|
-
- spec/controllers/spree/api/v1/addresses_controller_spec.rb
|
288
|
-
- spec/controllers/spree/api/v1/checkouts_controller_spec.rb
|
289
|
-
- spec/controllers/spree/api/v1/classifications_controller_spec.rb
|
290
|
-
- spec/controllers/spree/api/v1/countries_controller_spec.rb
|
291
|
-
- spec/controllers/spree/api/v1/credit_cards_controller_spec.rb
|
292
|
-
- spec/controllers/spree/api/v1/customer_returns_controller_spec.rb
|
293
|
-
- spec/controllers/spree/api/v1/images_controller_spec.rb
|
294
|
-
- spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
|
295
|
-
- spec/controllers/spree/api/v1/line_items_controller_spec.rb
|
296
|
-
- spec/controllers/spree/api/v1/option_types_controller_spec.rb
|
297
|
-
- spec/controllers/spree/api/v1/option_values_controller_spec.rb
|
298
|
-
- spec/controllers/spree/api/v1/orders_controller_spec.rb
|
299
|
-
- spec/controllers/spree/api/v1/payments_controller_spec.rb
|
300
|
-
- spec/controllers/spree/api/v1/product_properties_controller_spec.rb
|
301
|
-
- spec/controllers/spree/api/v1/products_controller_spec.rb
|
302
|
-
- spec/controllers/spree/api/v1/promotion_application_spec.rb
|
303
|
-
- spec/controllers/spree/api/v1/promotions_controller_spec.rb
|
304
|
-
- spec/controllers/spree/api/v1/properties_controller_spec.rb
|
305
|
-
- spec/controllers/spree/api/v1/reimbursements_controller_spec.rb
|
306
|
-
- spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
|
307
|
-
- spec/controllers/spree/api/v1/shipments_controller_spec.rb
|
308
|
-
- spec/controllers/spree/api/v1/states_controller_spec.rb
|
309
|
-
- spec/controllers/spree/api/v1/stock_items_controller_spec.rb
|
310
|
-
- spec/controllers/spree/api/v1/stock_locations_controller_spec.rb
|
311
|
-
- spec/controllers/spree/api/v1/stock_movements_controller_spec.rb
|
312
|
-
- spec/controllers/spree/api/v1/stores_controller_spec.rb
|
313
|
-
- spec/controllers/spree/api/v1/tags_controller_spec.rb
|
314
|
-
- spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
|
315
|
-
- spec/controllers/spree/api/v1/taxons_controller_spec.rb
|
316
|
-
- spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
|
317
|
-
- spec/controllers/spree/api/v1/users_controller_spec.rb
|
318
|
-
- spec/controllers/spree/api/v1/variants_controller_spec.rb
|
319
|
-
- spec/controllers/spree/api/v1/zones_controller_spec.rb
|
320
|
-
- spec/fixtures/thinking-cat.jpg
|
321
|
-
- spec/models/spree/legacy_user_spec.rb
|
322
|
-
- spec/requests/rabl_cache_spec.rb
|
323
|
-
- spec/requests/ransackable_attributes_spec.rb
|
324
|
-
- spec/requests/version_spec.rb
|
325
|
-
- spec/shared_examples/protect_product_actions.rb
|
326
|
-
- spec/spec_helper.rb
|
327
|
-
- spec/support/controller_hacks.rb
|
328
|
-
- spec/support/database_cleaner.rb
|
329
|
-
- spec/support/have_attributes_matcher.rb
|
241
|
+
test_files: []
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class FakesController < Spree::Api::BaseController
|
4
|
-
end
|
5
|
-
|
6
|
-
describe Spree::Api::BaseController, type: :controller do
|
7
|
-
render_views
|
8
|
-
controller(Spree::Api::BaseController) do
|
9
|
-
def index
|
10
|
-
render plain: { "products" => [] }.to_json
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
16
|
-
r.draw { get 'index', to: 'spree/api/base#index' }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when validating based on an order token" do
|
21
|
-
let!(:order) { create :order }
|
22
|
-
|
23
|
-
context "with a correct order token" do
|
24
|
-
it "succeeds" do
|
25
|
-
api_get :index, order_token: order.guest_token, order_id: order.number
|
26
|
-
expect(response.status).to eq(200)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "succeeds with an order_number parameter" do
|
30
|
-
api_get :index, order_token: order.guest_token, order_number: order.number
|
31
|
-
expect(response.status).to eq(200)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with an incorrect order token" do
|
36
|
-
it "returns unauthorized" do
|
37
|
-
api_get :index, order_token: "NOT_A_TOKEN", order_id: order.number
|
38
|
-
expect(response.status).to eq(401)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "cannot make a request to the API" do
|
44
|
-
it "without an API key" do
|
45
|
-
api_get :index
|
46
|
-
expect(json_response).to eq({ "error" => "You must specify an API key." })
|
47
|
-
expect(response.status).to eq(401)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "with an invalid API key" do
|
51
|
-
request.headers["X-Spree-Token"] = "fake_key"
|
52
|
-
get :index
|
53
|
-
expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
|
54
|
-
expect(response.status).to eq(401)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "using an invalid token param" do
|
58
|
-
get :index, params: { token: "fake_key" }
|
59
|
-
expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'handles parameter missing exceptions' do
|
64
|
-
expect(subject).to receive(:authenticate_user).and_return(true)
|
65
|
-
expect(subject).to receive(:load_user_roles).and_return(true)
|
66
|
-
expect(subject).to receive(:index).and_raise(ActionController::ParameterMissing.new('foo'))
|
67
|
-
get :index, params: { token: 'exception-message' }
|
68
|
-
expect(json_response).to eql('exception' => 'param is missing or the value is empty: foo')
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'handles record invalid exceptions' do
|
72
|
-
expect(subject).to receive(:authenticate_user).and_return(true)
|
73
|
-
expect(subject).to receive(:load_user_roles).and_return(true)
|
74
|
-
resource = Spree::Product.new
|
75
|
-
resource.valid? # get some errors
|
76
|
-
expect(subject).to receive(:index).and_raise(ActiveRecord::RecordInvalid.new(resource))
|
77
|
-
get :index, params: { token: 'exception-message' }
|
78
|
-
expect(json_response).to eql('exception' => "Validation failed: Name can't be blank, Shipping Category can't be blank, Price can't be blank")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "lets a subclass override the product associations that are eager-loaded" do
|
82
|
-
expect(controller.respond_to?(:product_includes, true)).to be
|
83
|
-
end
|
84
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
describe Api::V1::AddressesController, type: :controller do
|
5
|
-
render_views
|
6
|
-
|
7
|
-
before do
|
8
|
-
stub_authentication!
|
9
|
-
@address = create(:address)
|
10
|
-
@order = create(:order, bill_address: @address)
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with their own address" do
|
14
|
-
before do
|
15
|
-
allow_any_instance_of(Order).to receive_messages user: current_api_user
|
16
|
-
end
|
17
|
-
|
18
|
-
it "gets an address" do
|
19
|
-
api_get :show, id: @address.id, order_id: @order.number
|
20
|
-
expect(json_response['address1']).to eq @address.address1
|
21
|
-
end
|
22
|
-
|
23
|
-
it "updates an address" do
|
24
|
-
api_put :update, id: @address.id, order_id: @order.number,
|
25
|
-
address: { address1: "123 Test Lane" }
|
26
|
-
expect(json_response['address1']).to eq '123 Test Lane'
|
27
|
-
end
|
28
|
-
|
29
|
-
it "receives the errors object if address is invalid" do
|
30
|
-
api_put :update, id: @address.id, order_id: @order.number,
|
31
|
-
address: { address1: "" }
|
32
|
-
|
33
|
-
expect(json_response['error']).not_to be_nil
|
34
|
-
expect(json_response['errors']).not_to be_nil
|
35
|
-
expect(json_response['errors']['address1'].first).to eq "can't be blank"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "on an address that does not belong to this order" do
|
40
|
-
before do
|
41
|
-
@order.bill_address_id = nil
|
42
|
-
@order.ship_address = nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it "cannot retrieve address information" do
|
46
|
-
api_get :show, id: @address.id, order_id: @order.number
|
47
|
-
assert_unauthorized!
|
48
|
-
end
|
49
|
-
|
50
|
-
it "cannot update address information" do
|
51
|
-
api_get :update, id: @address.id, order_id: @order.number
|
52
|
-
assert_unauthorized!
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,361 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
describe Api::V1::CheckoutsController, type: :controller do
|
5
|
-
render_views
|
6
|
-
|
7
|
-
shared_examples_for 'action which loads order using load_order_with_lock' do
|
8
|
-
before do
|
9
|
-
allow(controller).to receive(:load_order).with(true).and_return(true)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should invoke load_order_with_lock' do
|
13
|
-
expect(controller).to receive(:load_order_with_lock).exactly(1).times
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should invoke load_order' do
|
17
|
-
expect(controller).to receive(:load_order).with(true).exactly(1).times.and_return(true)
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'ensure no double_render_error' do
|
21
|
-
before do
|
22
|
-
def controller.load_order(*)
|
23
|
-
respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should not generate double_render_error' do
|
28
|
-
expect(response).to be_success
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
after do
|
33
|
-
send_request
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
before(:each) do
|
38
|
-
stub_authentication!
|
39
|
-
Spree::Config[:track_inventory_levels] = false
|
40
|
-
country_zone = create(:zone, name: 'CountryZone')
|
41
|
-
@state = create(:state)
|
42
|
-
@country = @state.country
|
43
|
-
country_zone.members.create(zoneable: @country)
|
44
|
-
create(:stock_location)
|
45
|
-
|
46
|
-
@shipping_method = create(:shipping_method, zones: [country_zone])
|
47
|
-
@payment_method = create(:credit_card_payment_method)
|
48
|
-
end
|
49
|
-
|
50
|
-
after do
|
51
|
-
Spree::Config[:track_inventory_levels] = true
|
52
|
-
end
|
53
|
-
|
54
|
-
context "PUT 'update'" do
|
55
|
-
let(:order) do
|
56
|
-
order = create(:order_with_line_items)
|
57
|
-
# Order should be in a pristine state
|
58
|
-
# Without doing this, the order may transition from 'cart' straight to 'delivery'
|
59
|
-
order.shipments.delete_all
|
60
|
-
order
|
61
|
-
end
|
62
|
-
|
63
|
-
before(:each) do
|
64
|
-
allow_any_instance_of(Order).to receive_messages(confirmation_required?: true)
|
65
|
-
allow_any_instance_of(Order).to receive_messages(payment_required?: true)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should transition a recently created order from cart to address" do
|
69
|
-
expect(order.state).to eq "cart"
|
70
|
-
expect(order.email).not_to be_nil
|
71
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
72
|
-
expect(order.reload.state).to eq "address"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should transition a recently created order from cart to address with order token in header" do
|
76
|
-
expect(order.state).to eq "cart"
|
77
|
-
expect(order.email).not_to be_nil
|
78
|
-
request.headers["X-Spree-Order-Token"] = order.guest_token
|
79
|
-
api_put :update, id: order.to_param
|
80
|
-
expect(order.reload.state).to eq "address"
|
81
|
-
end
|
82
|
-
|
83
|
-
it "can take line_items_attributes as a parameter" do
|
84
|
-
line_item = order.line_items.first
|
85
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
86
|
-
order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } }
|
87
|
-
expect(response.status).to eq(200)
|
88
|
-
expect(order.reload.state).to eq "address"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "can take line_items as a parameter" do
|
92
|
-
line_item = order.line_items.first
|
93
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
94
|
-
order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } }
|
95
|
-
expect(response.status).to eq(200)
|
96
|
-
expect(order.reload.state).to eq "address"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "will return an error if the order cannot transition" do
|
100
|
-
skip "not sure if this test is valid"
|
101
|
-
order.bill_address = nil
|
102
|
-
order.save
|
103
|
-
order.update_column(:state, "address")
|
104
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
105
|
-
# Order has not transitioned
|
106
|
-
expect(response.status).to eq(422)
|
107
|
-
end
|
108
|
-
|
109
|
-
context "transitioning to delivery" do
|
110
|
-
before do
|
111
|
-
order.update_column(:state, "address")
|
112
|
-
end
|
113
|
-
|
114
|
-
let(:address) do
|
115
|
-
{
|
116
|
-
firstname: 'John',
|
117
|
-
lastname: 'Doe',
|
118
|
-
address1: '7735 Old Georgetown Road',
|
119
|
-
city: 'Bethesda',
|
120
|
-
phone: '3014445002',
|
121
|
-
zipcode: '20814',
|
122
|
-
state_id: @state.id,
|
123
|
-
country_id: @country.id
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
it "can update addresses and transition from address to delivery" do
|
128
|
-
api_put :update,
|
129
|
-
id: order.to_param, order_token: order.guest_token,
|
130
|
-
order: {
|
131
|
-
bill_address_attributes: address,
|
132
|
-
ship_address_attributes: address
|
133
|
-
}
|
134
|
-
expect(json_response['state']).to eq('delivery')
|
135
|
-
expect(json_response['bill_address']['firstname']).to eq('John')
|
136
|
-
expect(json_response['ship_address']['firstname']).to eq('John')
|
137
|
-
expect(response.status).to eq(200)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Regression Spec for #5389 & #5880
|
141
|
-
it "can update addresses but not transition to delivery w/o shipping setup" do
|
142
|
-
Spree::ShippingMethod.destroy_all
|
143
|
-
api_put :update,
|
144
|
-
id: order.to_param, order_token: order.guest_token,
|
145
|
-
order: {
|
146
|
-
bill_address_attributes: address,
|
147
|
-
ship_address_attributes: address
|
148
|
-
}
|
149
|
-
expect(json_response['error']).to eq(I18n.t(:could_not_transition, scope: "spree.api.order"))
|
150
|
-
expect(response.status).to eq(422)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Regression test for #4498
|
154
|
-
it "does not contain duplicate variant data in delivery return" do
|
155
|
-
api_put :update,
|
156
|
-
id: order.to_param, order_token: order.guest_token,
|
157
|
-
order: {
|
158
|
-
bill_address_attributes: address,
|
159
|
-
ship_address_attributes: address
|
160
|
-
}
|
161
|
-
# Shipments manifests should not return the ENTIRE variant
|
162
|
-
# This information is already present within the order's line items
|
163
|
-
expect(json_response['shipments'].first['manifest'].first['variant']).to be_nil
|
164
|
-
expect(json_response['shipments'].first['manifest'].first['variant_id']).to_not be_nil
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
it "can update shipping method and transition from delivery to payment" do
|
169
|
-
order.update_column(:state, "delivery")
|
170
|
-
shipment = create(:shipment, order: order)
|
171
|
-
shipment.refresh_rates
|
172
|
-
shipping_rate = shipment.shipping_rates.where(selected: false).first
|
173
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
174
|
-
order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } }
|
175
|
-
expect(response.status).to eq(200)
|
176
|
-
# Find the correct shipment...
|
177
|
-
json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
|
178
|
-
# Find the correct shipping rate for that shipment...
|
179
|
-
json_shipping_rate = json_shipment['shipping_rates'].detect { |sr| sr["id"] == shipping_rate.id }
|
180
|
-
# ... And finally ensure that it's selected
|
181
|
-
expect(json_shipping_rate['selected']).to be true
|
182
|
-
# Order should automatically transfer to payment because all criteria are met
|
183
|
-
expect(json_response['state']).to eq('payment')
|
184
|
-
end
|
185
|
-
|
186
|
-
it "can update payment method and transition from payment to confirm" do
|
187
|
-
order.update_column(:state, "payment")
|
188
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
189
|
-
order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
190
|
-
expect(json_response['state']).to eq('confirm')
|
191
|
-
expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
|
192
|
-
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
193
|
-
expect(response.status).to eq(200)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "can update payment method with source and transition from payment to confirm" do
|
197
|
-
order.update_column(:state, "payment")
|
198
|
-
source_attributes = {
|
199
|
-
number: "4111111111111111",
|
200
|
-
month: 1.month.from_now.month,
|
201
|
-
year: 1.month.from_now.year,
|
202
|
-
verification_value: "123",
|
203
|
-
name: "Spree Commerce"
|
204
|
-
}
|
205
|
-
|
206
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
207
|
-
order: { payments_attributes: [{ payment_method_id: @payment_method.id.to_s }],
|
208
|
-
payment_source: { @payment_method.id.to_s => source_attributes } }
|
209
|
-
expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
|
210
|
-
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
211
|
-
expect(response.status).to eq(200)
|
212
|
-
end
|
213
|
-
|
214
|
-
it "returns errors when source is missing attributes" do
|
215
|
-
order.update_column(:state, "payment")
|
216
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
217
|
-
order: {
|
218
|
-
payments_attributes: [{ payment_method_id: @payment_method.id }]
|
219
|
-
},
|
220
|
-
payment_source: {
|
221
|
-
@payment_method.id.to_s => { name: "Spree" }
|
222
|
-
}
|
223
|
-
|
224
|
-
expect(response.status).to eq(422)
|
225
|
-
cc_errors = json_response['errors']['payments.Credit Card']
|
226
|
-
expect(cc_errors).to include("Number can't be blank")
|
227
|
-
expect(cc_errors).to include("Month is not a number")
|
228
|
-
expect(cc_errors).to include("Year is not a number")
|
229
|
-
expect(cc_errors).to include("Verification Value can't be blank")
|
230
|
-
end
|
231
|
-
|
232
|
-
it "allow users to reuse a credit card" do
|
233
|
-
order.update_column(:state, "payment")
|
234
|
-
credit_card = create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)
|
235
|
-
|
236
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
237
|
-
order: { existing_card: credit_card.id }
|
238
|
-
|
239
|
-
expect(response.status).to eq 200
|
240
|
-
expect(order.credit_cards).to match_array [credit_card]
|
241
|
-
end
|
242
|
-
|
243
|
-
it "can transition from confirm to complete" do
|
244
|
-
order.update_columns(state: 'confirm')
|
245
|
-
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
246
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
247
|
-
expect(json_response['state']).to eq('complete')
|
248
|
-
expect(response.status).to eq(200)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "returns the order if the order is already complete" do
|
252
|
-
order.update_columns(completed_at: Time.current, state: 'complete')
|
253
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
254
|
-
expect(json_response['number']).to eq(order.number)
|
255
|
-
expect(response.status).to eq(200)
|
256
|
-
end
|
257
|
-
|
258
|
-
# Regression test for #3784
|
259
|
-
it "can update the special instructions for an order" do
|
260
|
-
instructions = "Don't drop it. (Please)"
|
261
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
262
|
-
order: { special_instructions: instructions }
|
263
|
-
expect(json_response['special_instructions']).to eql(instructions)
|
264
|
-
end
|
265
|
-
|
266
|
-
context "as an admin" do
|
267
|
-
sign_in_as_admin!
|
268
|
-
it "can assign a user to the order" do
|
269
|
-
user = create(:user)
|
270
|
-
# Need to pass email as well so that validations succeed
|
271
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
272
|
-
order: { user_id: user.id, email: "guest@spreecommerce.org" }
|
273
|
-
expect(response.status).to eq(200)
|
274
|
-
expect(json_response['user_id']).to eq(user.id)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
it "can assign an email to the order" do
|
279
|
-
api_put :update, id: order.to_param, order_token: order.guest_token,
|
280
|
-
order: { email: "guest@spreecommerce.org" }
|
281
|
-
expect(json_response['email']).to eq("guest@spreecommerce.org")
|
282
|
-
expect(response.status).to eq(200)
|
283
|
-
end
|
284
|
-
|
285
|
-
it "can apply a coupon code to an order" do
|
286
|
-
order.update_column(:state, "payment")
|
287
|
-
expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
|
288
|
-
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
289
|
-
api_put :update, id: order.to_param, order_token: order.guest_token, order: { coupon_code: "foobar" }
|
290
|
-
end
|
291
|
-
|
292
|
-
def send_request
|
293
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
294
|
-
end
|
295
|
-
|
296
|
-
it_should_behave_like 'action which loads order using load_order_with_lock'
|
297
|
-
end
|
298
|
-
|
299
|
-
context "PUT 'next'" do
|
300
|
-
let!(:order) { create(:order_with_line_items) }
|
301
|
-
it "cannot transition to address without a line item" do
|
302
|
-
order.line_items.delete_all
|
303
|
-
order.update_column(:email, "spree@example.com")
|
304
|
-
api_put :next, id: order.to_param, order_token: order.guest_token
|
305
|
-
expect(response.status).to eq(422)
|
306
|
-
expect(json_response["errors"]["base"]).to include(Spree.t(:there_are_no_items_for_this_order))
|
307
|
-
end
|
308
|
-
|
309
|
-
it "can transition an order to the next state" do
|
310
|
-
order.update_column(:email, "spree@example.com")
|
311
|
-
|
312
|
-
api_put :next, id: order.to_param, order_token: order.guest_token
|
313
|
-
expect(response.status).to eq(200)
|
314
|
-
expect(json_response['state']).to eq('address')
|
315
|
-
end
|
316
|
-
|
317
|
-
it "cannot transition if order email is blank" do
|
318
|
-
order.update_columns(
|
319
|
-
state: 'address',
|
320
|
-
email: nil
|
321
|
-
)
|
322
|
-
|
323
|
-
api_put :next, id: order.to_param, order_token: order.guest_token
|
324
|
-
expect(response.status).to eq(422)
|
325
|
-
expect(json_response['error']).to match(/could not be transitioned/)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "doesnt advance payment state if order has no payment" do
|
329
|
-
order.update_column(:state, "payment")
|
330
|
-
api_put :next, id: order.to_param, order_token: order.guest_token, order: {}
|
331
|
-
expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
|
332
|
-
end
|
333
|
-
|
334
|
-
def send_request
|
335
|
-
api_put :next, id: order.to_param, order_token: order.guest_token
|
336
|
-
end
|
337
|
-
|
338
|
-
it_should_behave_like 'action which loads order using load_order_with_lock'
|
339
|
-
end
|
340
|
-
|
341
|
-
context "PUT 'advance'" do
|
342
|
-
let!(:order) { create(:order_with_line_items) }
|
343
|
-
|
344
|
-
it 'continues to advance advances an order while it can move forward' do
|
345
|
-
expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
|
346
|
-
api_put :advance, id: order.to_param, order_token: order.guest_token
|
347
|
-
end
|
348
|
-
|
349
|
-
it 'returns the order' do
|
350
|
-
api_put :advance, id: order.to_param, order_token: order.guest_token
|
351
|
-
expect(json_response['id']).to eq(order.id)
|
352
|
-
end
|
353
|
-
|
354
|
-
def send_request
|
355
|
-
api_put :advance, id: order.to_param, order_token: order.guest_token
|
356
|
-
end
|
357
|
-
|
358
|
-
it_should_behave_like 'action which loads order using load_order_with_lock'
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|