solidus_api 1.2.3 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- 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
@@ -37,10 +37,10 @@ module Spree
|
|
37
37
|
:variant_property_attributes
|
38
38
|
]
|
39
39
|
|
40
|
-
mattr_reader
|
40
|
+
mattr_reader(*ATTRIBUTES)
|
41
41
|
|
42
42
|
def required_fields_for(model)
|
43
|
-
required_fields = model._validators.select do |
|
43
|
+
required_fields = model._validators.select do |_field, validations|
|
44
44
|
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
45
45
|
end.map(&:first) # get fields that are invalid
|
46
46
|
# Permalinks presence is validated, but are really automatically generated
|
@@ -88,7 +88,8 @@ module Spree
|
|
88
88
|
:display_additional_tax_total, :tax_total, :currency,
|
89
89
|
:covered_by_store_credit, :display_total_applicable_store_credit,
|
90
90
|
:order_total_after_store_credit, :display_order_total_after_store_credit,
|
91
|
-
:total_applicable_store_credit, :display_total_available_store_credit,
|
91
|
+
:total_applicable_store_credit, :display_total_available_store_credit,
|
92
|
+
:display_store_credit_remaining_after_capture, :canceler_id
|
92
93
|
|
93
94
|
]
|
94
95
|
|
@@ -104,7 +105,7 @@ module Spree
|
|
104
105
|
|
105
106
|
@@payment_method_attributes = [:id, :name, :description]
|
106
107
|
|
107
|
-
@@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
|
108
|
+
@@shipment_attributes = [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :state]
|
108
109
|
|
109
110
|
@@taxonomy_attributes = [:id, :name]
|
110
111
|
|
@@ -135,11 +136,11 @@ module Spree
|
|
135
136
|
@@adjustment_attributes = [
|
136
137
|
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
137
138
|
:originator_type, :originator_id, :amount, :label, :promotion_code,
|
138
|
-
:locked, :eligible,
|
139
|
+
:locked, :eligible, :created_at, :updated_at
|
139
140
|
]
|
140
141
|
|
141
142
|
@@creditcard_attributes = [
|
142
|
-
:id, :month, :year, :cc_type, :last_digits, :name
|
143
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
143
144
|
]
|
144
145
|
|
145
146
|
@@payment_source_attributes = [
|
data/lib/spree/api/engine.rb
CHANGED
@@ -16,19 +16,19 @@ module Spree
|
|
16
16
|
config.json_engine = ActiveSupport::JSON
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
config.view_version_extraction_strategy = :http_header
|
21
|
-
|
22
|
-
initializer "spree.api.environment", :before => :load_config_initializers do |app|
|
19
|
+
initializer "spree.api.environment", before: :load_config_initializers do |_app|
|
23
20
|
Spree::Api::Config = Spree::ApiConfiguration.new
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
initializer "spree.api.versioncake" do |_app|
|
24
|
+
VersionCake.setup do |config|
|
25
|
+
config.resources do |r|
|
26
|
+
r.resource %r{.*}, [], [], [1]
|
27
|
+
end
|
28
|
+
config.missing_version = 1
|
29
|
+
config.extraction_strategy = :http_header
|
29
30
|
end
|
30
31
|
end
|
31
|
-
config.to_prepare &method(:activate).to_proc
|
32
32
|
|
33
33
|
def self.root
|
34
34
|
@root ||= Pathname.new(File.expand_path('../../../../', __FILE__))
|
@@ -1,10 +1,10 @@
|
|
1
1
|
RSpec.configure do |config|
|
2
|
-
config.before(:each, :
|
2
|
+
config.before(:each, caching: true) do
|
3
3
|
ActionController::Base.perform_caching = true
|
4
4
|
end
|
5
|
-
|
6
|
-
config.after(:each, :
|
5
|
+
|
6
|
+
config.after(:each, caching: true) do
|
7
7
|
ActionController::Base.perform_caching = false
|
8
8
|
Rails.cache.clear
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
data/script/rails
CHANGED
data/solidus_api.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = 'contact@solidus.io'
|
7
7
|
gem.homepage = 'http://solidus.io/'
|
8
8
|
|
9
|
-
gem.summary =
|
9
|
+
gem.summary = 'REST API for the Solidus e-commerce framework.'
|
10
10
|
gem.description = gem.summary
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
@@ -14,9 +14,9 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
15
|
gem.name = "solidus_api"
|
16
16
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version
|
17
|
+
gem.version = Spree.solidus_version
|
18
18
|
|
19
19
|
gem.add_dependency 'solidus_core', gem.version
|
20
20
|
gem.add_dependency 'rabl', ['>= 0.9.4.pre1', '< 0.12.0']
|
21
|
-
gem.add_dependency 'versioncake', '~>
|
21
|
+
gem.add_dependency 'versioncake', '~> 3.0'
|
22
22
|
end
|
@@ -1,37 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::AddressesController, :
|
4
|
+
describe Api::AddressesController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
8
8
|
stub_authentication!
|
9
9
|
@address = create(:address)
|
10
|
-
@order = create(:order, :
|
10
|
+
@order = create(:order, bill_address: @address)
|
11
11
|
end
|
12
12
|
|
13
13
|
context "with order" do
|
14
14
|
before do
|
15
|
-
allow_any_instance_of(Order).to receive_messages :
|
15
|
+
allow_any_instance_of(Order).to receive_messages user: current_api_user
|
16
16
|
end
|
17
17
|
|
18
18
|
context "with their own address" do
|
19
|
-
|
20
19
|
it "gets an address" do
|
21
|
-
api_get :show, :
|
20
|
+
api_get :show, id: @address.id, order_id: @order.number
|
22
21
|
expect(json_response['address1']).to eq @address.address1
|
23
22
|
end
|
24
23
|
|
25
24
|
it "update replaces the readonly Address associated to the Order" do
|
26
|
-
api_put :update, :
|
27
|
-
:
|
25
|
+
api_put :update, id: @address.id, order_id: @order.number,
|
26
|
+
address: { address1: "123 Test Lane" }
|
28
27
|
expect(Order.find(@order.id).bill_address_id).not_to eq @address.id
|
29
28
|
expect(json_response['address1']).to eq '123 Test Lane'
|
30
29
|
end
|
31
30
|
|
32
31
|
it "receives the errors object if address is invalid" do
|
33
|
-
api_put :update, :
|
34
|
-
:
|
32
|
+
api_put :update, id: @address.id, order_id: @order.number,
|
33
|
+
address: { address1: "" }
|
35
34
|
|
36
35
|
expect(json_response['error']).not_to be_nil
|
37
36
|
expect(json_response['errors']).not_to be_nil
|
@@ -40,8 +39,8 @@ module Spree
|
|
40
39
|
end
|
41
40
|
|
42
41
|
it "receives the errors object if address is invalid" do
|
43
|
-
api_put :update, :
|
44
|
-
:
|
42
|
+
api_put :update, id: @address.id, order_id: @order.number,
|
43
|
+
address: { address1: "" }
|
45
44
|
|
46
45
|
expect(json_response['error']).not_to be_nil
|
47
46
|
expect(json_response['errors']).not_to be_nil
|
@@ -56,12 +55,12 @@ module Spree
|
|
56
55
|
end
|
57
56
|
|
58
57
|
it "cannot retrieve address information" do
|
59
|
-
api_get :show, :
|
58
|
+
api_get :show, id: @address.id, order_id: @order.number
|
60
59
|
assert_unauthorized!
|
61
60
|
end
|
62
61
|
|
63
62
|
it "cannot update address information" do
|
64
|
-
api_get :update, :
|
63
|
+
api_get :update, id: @address.id, order_id: @order.number
|
65
64
|
assert_unauthorized!
|
66
65
|
end
|
67
66
|
end
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
class FakesController < Spree::Api::BaseController
|
4
4
|
end
|
5
5
|
|
6
|
-
describe Spree::Api::BaseController, :
|
6
|
+
describe Spree::Api::BaseController, type: :controller do
|
7
7
|
render_views
|
8
8
|
controller(Spree::Api::BaseController) do
|
9
9
|
rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
|
10
10
|
|
11
11
|
def index
|
12
|
-
render :
|
12
|
+
render text: { "products" => [] }.to_json
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -57,7 +57,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "using an invalid token param" do
|
60
|
-
get :index, :
|
60
|
+
get :index, token: "fake_key"
|
61
61
|
expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
|
62
62
|
end
|
63
63
|
end
|
@@ -66,7 +66,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
66
66
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
67
67
|
expect(subject).to receive(:load_user_roles).and_return(true)
|
68
68
|
expect(subject).to receive(:index).and_raise("no joy")
|
69
|
-
get :index, :
|
69
|
+
get :index, token: "fake_key"
|
70
70
|
expect(json_response).to eq({ "exception" => "no joy" })
|
71
71
|
end
|
72
72
|
|
@@ -75,7 +75,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
75
75
|
expect(subject).to receive(:load_user_roles).and_return(true)
|
76
76
|
expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
|
77
77
|
expect {
|
78
|
-
get :index, :
|
78
|
+
get :index, token: "fake_key"
|
79
79
|
}.to raise_error(Exception, "no joy")
|
80
80
|
end
|
81
81
|
|
@@ -93,7 +93,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
# What would be placed in config/initializers/spree.rb
|
96
|
-
Spree::Api::BaseController.error_notifier =
|
96
|
+
Spree::Api::BaseController.error_notifier = proc do |e, controller|
|
97
97
|
MockHoneybadger.notify_or_ignore(e, rack_env: controller.request.env)
|
98
98
|
end
|
99
99
|
|
@@ -101,7 +101,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
101
101
|
# Fake HB alert class
|
102
102
|
class MockHoneybadger
|
103
103
|
# https://github.com/honeybadger-io/honeybadger-ruby/blob/master/lib/honeybadger.rb#L136
|
104
|
-
def self.notify_or_ignore(
|
104
|
+
def self.notify_or_ignore(_exception, _opts = {})
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -125,7 +125,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
125
125
|
before do
|
126
126
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
127
127
|
expect(subject).to receive(:index).and_raise(Spree::Order::InsufficientStock)
|
128
|
-
get :index, :
|
128
|
+
get :index, token: "fake_key"
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should return a 422" do
|
@@ -134,7 +134,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
134
134
|
|
135
135
|
it "returns an error message" do
|
136
136
|
expect(json_response).to eq(
|
137
|
-
{"errors" => ["Quantity is not available for items in your order"], "type" => "insufficient_stock"}
|
137
|
+
{ "errors" => ["Quantity is not available for items in your order"], "type" => "insufficient_stock" }
|
138
138
|
)
|
139
139
|
end
|
140
140
|
end
|
@@ -146,7 +146,7 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
146
146
|
around_filter :lock_order
|
147
147
|
|
148
148
|
def index
|
149
|
-
render :
|
149
|
+
render text: { "products" => [] }.to_json
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -168,5 +168,4 @@ describe Spree::Api::BaseController, :type => :controller do
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
171
|
-
|
172
171
|
end
|
@@ -45,7 +45,7 @@ module Spree
|
|
45
45
|
expect(order.state).to eq "cart"
|
46
46
|
expect(order.email).not_to be_nil
|
47
47
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
48
|
-
api_put :update, :
|
48
|
+
api_put :update, id: order.to_param
|
49
49
|
expect(order.reload.state).to eq "address"
|
50
50
|
end
|
51
51
|
|
@@ -136,7 +136,7 @@ module Spree
|
|
136
136
|
|
137
137
|
it "can update shipping method and transition from delivery to payment" do
|
138
138
|
order.update_column(:state, "delivery")
|
139
|
-
shipment = create(:shipment, order: order)
|
139
|
+
shipment = create(:shipment, order: order, address: order.ship_address)
|
140
140
|
shipment.refresh_rates
|
141
141
|
shipping_rate = shipment.shipping_rates.where(selected: false).first
|
142
142
|
api_put :update, id: order.to_param, order_token: order.guest_token,
|
@@ -163,23 +163,10 @@ module Spree
|
|
163
163
|
expect(response.status).to eq(200)
|
164
164
|
end
|
165
165
|
|
166
|
-
context "with disallowed payment method" do
|
167
|
-
it "returns not found" do
|
168
|
-
order.update_column(:state, "payment")
|
169
|
-
allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
|
170
|
-
@payment_method.update!(display_on: "back_end")
|
171
|
-
expect {
|
172
|
-
api_put :update, id: order.to_param, order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
173
|
-
}.not_to change { Spree::Payment.count }
|
174
|
-
expect(response.status).to eq(404)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
166
|
it "returns errors when source is required and missing" do
|
180
167
|
order.update_column(:state, "payment")
|
181
|
-
api_put :update, :
|
182
|
-
:
|
168
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
169
|
+
order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
183
170
|
expect(response.status).to eq(422)
|
184
171
|
source_errors = json_response['errors']['payments.source']
|
185
172
|
expect(source_errors).to include("can't be blank")
|
@@ -194,10 +181,10 @@ module Spree
|
|
194
181
|
payments_attributes: [
|
195
182
|
{
|
196
183
|
payment_method_id: @payment_method.id.to_s,
|
197
|
-
source_attributes: attributes_for(:credit_card)
|
198
|
-
}
|
199
|
-
]
|
200
|
-
}
|
184
|
+
source_attributes: attributes_for(:credit_card)
|
185
|
+
}
|
186
|
+
]
|
187
|
+
}
|
201
188
|
}
|
202
189
|
end
|
203
190
|
|
@@ -221,10 +208,10 @@ module Spree
|
|
221
208
|
payments_attributes: [
|
222
209
|
{
|
223
210
|
payment_method_id: @payment_method.id.to_s,
|
224
|
-
source_attributes: attributes_for(:credit_card)
|
225
|
-
}
|
226
|
-
]
|
227
|
-
}
|
211
|
+
source_attributes: attributes_for(:credit_card)
|
212
|
+
}
|
213
|
+
]
|
214
|
+
}
|
228
215
|
}
|
229
216
|
end
|
230
217
|
|
@@ -242,10 +229,10 @@ module Spree
|
|
242
229
|
order_token: order.guest_token,
|
243
230
|
order: {
|
244
231
|
payments_attributes: [
|
245
|
-
{ payment_method_id: @payment_method.id.to_s }
|
246
|
-
]
|
232
|
+
{ payment_method_id: @payment_method.id.to_s }
|
233
|
+
]
|
247
234
|
},
|
248
|
-
payment_source: { @payment_method.id.to_s => attributes_for(:credit_card) }
|
235
|
+
payment_source: { @payment_method.id.to_s => attributes_for(:credit_card) }
|
249
236
|
}
|
250
237
|
end
|
251
238
|
|
@@ -273,10 +260,10 @@ module Spree
|
|
273
260
|
payments_attributes: [
|
274
261
|
{
|
275
262
|
payment_method_id: @payment_method.id.to_s,
|
276
|
-
source_attributes: {name: "Spree"}
|
277
|
-
}
|
278
|
-
]
|
279
|
-
}
|
263
|
+
source_attributes: { name: "Spree" }
|
264
|
+
}
|
265
|
+
]
|
266
|
+
}
|
280
267
|
}
|
281
268
|
end
|
282
269
|
|
@@ -285,7 +272,7 @@ module Spree
|
|
285
272
|
|
286
273
|
expect(response.status).to eq(422)
|
287
274
|
cc_errors = json_response['errors']['payments.Credit Card']
|
288
|
-
expect(cc_errors).to include("Number can't be blank")
|
275
|
+
expect(cc_errors).to include("Card Number can't be blank")
|
289
276
|
expect(cc_errors).to include("Month is not a number")
|
290
277
|
expect(cc_errors).to include("Year is not a number")
|
291
278
|
expect(cc_errors).to include("Verification Value can't be blank")
|
@@ -298,12 +285,12 @@ module Spree
|
|
298
285
|
order_token: order.guest_token,
|
299
286
|
order: {
|
300
287
|
payments_attributes: [
|
301
|
-
{payment_method_id: @payment_method.id.to_s}
|
302
|
-
]
|
288
|
+
{ payment_method_id: @payment_method.id.to_s }
|
289
|
+
]
|
303
290
|
},
|
304
291
|
payment_source: {
|
305
|
-
@payment_method.id.to_s => {name: "Spree"}
|
306
|
-
}
|
292
|
+
@payment_method.id.to_s => { name: "Spree" }
|
293
|
+
}
|
307
294
|
}
|
308
295
|
end
|
309
296
|
|
@@ -314,7 +301,7 @@ module Spree
|
|
314
301
|
|
315
302
|
expect(response.status).to eq(422)
|
316
303
|
cc_errors = json_response['errors']['payments.Credit Card']
|
317
|
-
expect(cc_errors).to include("Number can't be blank")
|
304
|
+
expect(cc_errors).to include("Card Number can't be blank")
|
318
305
|
expect(cc_errors).to include("Month is not a number")
|
319
306
|
expect(cc_errors).to include("Year is not a number")
|
320
307
|
expect(cc_errors).to include("Verification Value can't be blank")
|
@@ -336,11 +323,11 @@ module Spree
|
|
336
323
|
{
|
337
324
|
source_attributes: {
|
338
325
|
existing_card_id: credit_card.id.to_s,
|
339
|
-
verification_value: '456'
|
326
|
+
verification_value: '456'
|
340
327
|
}
|
341
|
-
}
|
342
|
-
]
|
343
|
-
}
|
328
|
+
}
|
329
|
+
]
|
330
|
+
}
|
344
331
|
}
|
345
332
|
end
|
346
333
|
|
@@ -368,9 +355,9 @@ module Spree
|
|
368
355
|
id: order.to_param,
|
369
356
|
order_token: order.guest_token,
|
370
357
|
order: {
|
371
|
-
existing_card: credit_card.id.to_s
|
358
|
+
existing_card: credit_card.id.to_s
|
372
359
|
},
|
373
|
-
cvc_confirm: '456'
|
360
|
+
cvc_confirm: '456'
|
374
361
|
}
|
375
362
|
end
|
376
363
|
|
@@ -392,14 +379,6 @@ module Spree
|
|
392
379
|
end
|
393
380
|
end
|
394
381
|
|
395
|
-
it "can transition from confirm to complete" do
|
396
|
-
order.update_columns(completed_at: Time.current, state: 'complete')
|
397
|
-
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
398
|
-
api_put :update, id: order.to_param, order_token: order.guest_token
|
399
|
-
expect(json_response['state']).to eq('complete')
|
400
|
-
expect(response.status).to eq(200)
|
401
|
-
end
|
402
|
-
|
403
382
|
it "returns the order if the order is already complete" do
|
404
383
|
order.update_columns(completed_at: Time.current, state: 'complete')
|
405
384
|
api_put :update, id: order.to_param, order_token: order.guest_token
|
@@ -438,7 +417,7 @@ module Spree
|
|
438
417
|
order.update_column(:state, "payment")
|
439
418
|
expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
|
440
419
|
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
441
|
-
api_put :update, :
|
420
|
+
api_put :update, id: order.to_param, order_token: order.guest_token, order: { coupon_code: "foobar" }
|
442
421
|
end
|
443
422
|
end
|
444
423
|
|
@@ -466,7 +445,7 @@ module Spree
|
|
466
445
|
email: nil
|
467
446
|
)
|
468
447
|
|
469
|
-
api_put :next, :
|
448
|
+
api_put :next, id: order.to_param, order_token: order.guest_token
|
470
449
|
expect(response.status).to eq(422)
|
471
450
|
expect(json_response['error']).to match(/could not be transitioned/)
|
472
451
|
end
|
@@ -475,7 +454,7 @@ module Spree
|
|
475
454
|
# NOTE: Temporarily making "next" behave just like "complete" when order is in confirm state
|
476
455
|
# Using "next" this way is deprecated.
|
477
456
|
[:next, :complete].each do |action|
|
478
|
-
context
|
457
|
+
context action.to_s do
|
479
458
|
context "with order in confirm state" do
|
480
459
|
subject do
|
481
460
|
if action == :next
|
@@ -487,7 +466,7 @@ module Spree
|
|
487
466
|
end
|
488
467
|
end
|
489
468
|
|
490
|
-
let(:params) { {id: order.to_param, order_token: order.guest_token} }
|
469
|
+
let(:params) { { id: order.to_param, order_token: order.guest_token } }
|
491
470
|
let(:order) { create(:order_with_line_items) }
|
492
471
|
|
493
472
|
before do
|
@@ -495,7 +474,7 @@ module Spree
|
|
495
474
|
end
|
496
475
|
|
497
476
|
it "can transition from confirm to complete" do
|
498
|
-
allow_any_instance_of(Spree::Order).to receive_messages(
|
477
|
+
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
499
478
|
subject
|
500
479
|
expect(json_response['state']).to eq('complete')
|
501
480
|
expect(response.status).to eq(200)
|
@@ -514,7 +493,7 @@ module Spree
|
|
514
493
|
# api_put :complete, :id => order.to_param, :order_token => order.token, :expected_total => order.total + 1
|
515
494
|
subject
|
516
495
|
expect(response.status).to eq(400)
|
517
|
-
expect(json_response['errors']['expected_total']).to include(Spree.t(:expected_total_mismatch, :
|
496
|
+
expect(json_response['errors']['expected_total']).to include(Spree.t(:expected_total_mismatch, scope: 'api.order'))
|
518
497
|
end
|
519
498
|
end
|
520
499
|
end
|
@@ -524,7 +503,7 @@ module Spree
|
|
524
503
|
context "PUT 'advance'" do
|
525
504
|
let!(:order) { create(:order_with_line_items) }
|
526
505
|
|
527
|
-
it 'continues to advance
|
506
|
+
it 'continues to advance an order while it can move forward' do
|
528
507
|
expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
|
529
508
|
api_put :advance, id: order.to_param, order_token: order.guest_token
|
530
509
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ConfigController, :
|
4
|
+
describe Api::ConfigController, type: :controller do
|
5
|
+
let!(:default_country) { create :country, iso: "US"}
|
5
6
|
render_views
|
6
7
|
|
7
8
|
before do
|
@@ -17,7 +18,8 @@ module Spree
|
|
17
18
|
it "returns some configuration settings" do
|
18
19
|
api_get :show
|
19
20
|
expect(response).to be_success
|
20
|
-
expect(json_response["
|
21
|
+
expect(json_response["default_country_iso"]).to eq("US")
|
22
|
+
expect(json_response["default_country_id"]).to eq(default_country.id)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CountriesController, :
|
4
|
+
describe Api::CountriesController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context "with two countries" do
|
19
|
-
before { @zambia = create(:country, :
|
19
|
+
before { @zambia = create(:country, name: "Zambia") }
|
20
20
|
|
21
21
|
it "can view all countries" do
|
22
22
|
api_get :index
|
@@ -26,13 +26,13 @@ module Spree
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can query the results through a paramter' do
|
29
|
-
api_get :index, :
|
29
|
+
api_get :index, q: { name_cont: 'zam' }
|
30
30
|
expect(json_response['count']).to eq(1)
|
31
31
|
expect(json_response['countries'].first['name']).to eq @zambia.name
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'can control the page size through a parameter' do
|
35
|
-
api_get :index, :
|
35
|
+
api_get :index, per_page: 1
|
36
36
|
expect(json_response['count']).to eq(1)
|
37
37
|
expect(json_response['current_page']).to eq(1)
|
38
38
|
expect(json_response['pages']).to eq(2)
|
@@ -40,7 +40,7 @@ module Spree
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "includes states" do
|
43
|
-
api_get :show, :
|
43
|
+
api_get :show, id: @country.id
|
44
44
|
states = json_response['states']
|
45
45
|
expect(states.first['name']).to eq @state.name
|
46
46
|
end
|