solidus_api 2.10.0.beta1 → 2.10.5
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/README.md +30 -11
- data/app/controllers/spree/api/base_controller.rb +10 -10
- data/app/controllers/spree/api/checkouts_controller.rb +21 -8
- data/app/controllers/spree/api/orders_controller.rb +17 -6
- data/app/controllers/spree/api/taxonomies_controller.rb +3 -1
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/views/spree/api/images/_image.json.jbuilder +2 -2
- data/app/views/spree/api/orders/_order.json.jbuilder +1 -1
- data/lib/spree/api/responders.rb +2 -2
- data/lib/spree/api/responders/{rabl_template.rb → jbuilder_template.rb} +3 -1
- data/openapi/api.oas2.yml +17 -16
- data/solidus_api.gemspec +1 -1
- data/spec/controllers/spree/api/resource_controller_spec.rb +4 -4
- data/spec/lib/spree_api_responders_spec.rb +10 -0
- data/spec/requests/api/address_books_spec.rb +2 -2
- data/spec/requests/{rabl_cache_spec.rb → jbuilder_cache_spec.rb} +2 -2
- data/spec/requests/spree/api/checkouts_controller_spec.rb +35 -7
- data/spec/requests/spree/api/option_types_controller_spec.rb +2 -2
- data/spec/requests/spree/api/option_values_controller_spec.rb +2 -2
- data/spec/requests/spree/api/orders_controller_spec.rb +35 -12
- data/spec/requests/spree/api/products_controller_spec.rb +6 -6
- data/spec/requests/spree/api/taxons_controller_spec.rb +2 -2
- metadata +14 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7558124aed1cd9856a3b948cebe6ce41d2c279d2beafb8546ad309766954d45e
|
|
4
|
+
data.tar.gz: eb5c240b130fd09e20d950ebce3ebbe83d7b3197fffdaa2903935d1b59e2104c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37233aac3ded8ed602509f052e79e4c07781d4e826697df09088291deba177d5ff5f66691f604765fbdd0bf4e6e8bd44fa32475f926a5cc946e182c6c73be23c
|
|
7
|
+
data.tar.gz: 76c2977bd07b8276d34d132d9107808e0587423b699d472d1a3016bf19bf16f60c45513d8c75f274280e52ae135b469526e291998dc16d5ef90e81775ceeac0c
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# solidus_api
|
|
2
2
|
|
|
3
|
-
API contains the controllers and
|
|
3
|
+
API contains the controllers and Jbuilder views implementing the REST API of
|
|
4
|
+
Solidus.
|
|
4
5
|
|
|
5
6
|
## Testing
|
|
6
7
|
|
|
@@ -12,14 +13,32 @@ bundle exec rspec
|
|
|
12
13
|
|
|
13
14
|
## Documentation
|
|
14
15
|
|
|
15
|
-
The API documentation is in the [openapi]
|
|
16
|
-
|
|
17
|
-
[Stoplight](https://solidus.docs.stoplight.io/).
|
|
16
|
+
The API documentation is in the [openapi][docs-dir] directory. It follows the
|
|
17
|
+
OpenAPI specification and it is hosted on [Stoplight Docs][live-docs].
|
|
18
18
|
|
|
19
|
-
If you want to contribute, you can use [Stoplight Studio]
|
|
20
|
-
|
|
21
|
-
resulting code into the `openapi` directory.
|
|
19
|
+
If you want to contribute, you can use [Stoplight Studio][studio]. Simply
|
|
20
|
+
follow these steps:
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
1. Create a new Stoplight Studio project
|
|
23
|
+
2. Copy-paste the content of `openapi/api.oas2.yml` into your project
|
|
24
|
+
3. Edit the endpoints and models as needed
|
|
25
|
+
4. Copy-paste the result back into `openapi/api.oas2.yml`
|
|
26
|
+
5. Open a PR!
|
|
27
|
+
|
|
28
|
+
**Note: Only use embedded models in Stoplight Studio, as Stoplight Docs is
|
|
29
|
+
not compatible with externally-defined models!**
|
|
30
|
+
|
|
31
|
+
CircleCI automatically syncs our Git repo with Stoplight Docs when a PR is
|
|
32
|
+
merged, and automatically publishes a new version on Docs when a new Solidus
|
|
33
|
+
version is released.
|
|
34
|
+
|
|
35
|
+
## Related projects
|
|
36
|
+
|
|
37
|
+
- [solidus-sdk](https://gitlab.com/deseretbook/packages/solidus-sdk): created
|
|
38
|
+
by Joel Saupe at [Deseret Book](https://deseretbook.com/), this is a JS SDK
|
|
39
|
+
that allows you to use the Solidus API. It even supports plug-ins, so you can
|
|
40
|
+
easily extend it with the endpoints provided by your Solidus extensions!
|
|
41
|
+
|
|
42
|
+
[docs-dir]: https://github.com/solidusio/solidus/tree/master/api/openapi
|
|
43
|
+
[live-docs]: https://solidus.docs.stoplight.io
|
|
44
|
+
[studio]: https://stoplight.io/p/studio
|
|
@@ -49,9 +49,9 @@ module Spree
|
|
|
49
49
|
def authenticate_user
|
|
50
50
|
unless @current_api_user
|
|
51
51
|
if requires_authentication? && api_key.blank? && order_token.blank?
|
|
52
|
-
render "spree/api/errors/must_specify_api_key", status:
|
|
52
|
+
render "spree/api/errors/must_specify_api_key", status: :unauthorized
|
|
53
53
|
elsif order_token.blank? && (requires_authentication? || api_key.present?)
|
|
54
|
-
render "spree/api/errors/invalid_api_key", status:
|
|
54
|
+
render "spree/api/errors/invalid_api_key", status: :unauthorized
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -65,7 +65,7 @@ module Spree
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def unauthorized
|
|
68
|
-
render "spree/api/errors/unauthorized", status:
|
|
68
|
+
render "spree/api/errors/unauthorized", status: :unauthorized
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def gateway_error(exception)
|
|
@@ -78,7 +78,7 @@ module Spree
|
|
|
78
78
|
exception: exception.message,
|
|
79
79
|
error: exception.message,
|
|
80
80
|
missing_param: exception.param
|
|
81
|
-
}, status:
|
|
81
|
+
}, status: :unprocessable_entity
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def requires_authentication?
|
|
@@ -86,7 +86,7 @@ module Spree
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def not_found
|
|
89
|
-
render "spree/api/errors/not_found", status:
|
|
89
|
+
render "spree/api/errors/not_found", status: :not_found
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def current_ability
|
|
@@ -96,7 +96,7 @@ module Spree
|
|
|
96
96
|
def invalid_resource!(resource)
|
|
97
97
|
Rails.logger.error "invalid_resouce_errors=#{resource.errors.full_messages}"
|
|
98
98
|
@resource = resource
|
|
99
|
-
render "spree/api/errors/invalid_resource", status:
|
|
99
|
+
render "spree/api/errors/invalid_resource", status: :unprocessable_entity
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def api_key
|
|
@@ -112,7 +112,7 @@ module Spree
|
|
|
112
112
|
|
|
113
113
|
def spree_token
|
|
114
114
|
token = request.headers["X-Spree-Token"]
|
|
115
|
-
return
|
|
115
|
+
return if token.blank?
|
|
116
116
|
|
|
117
117
|
Spree::Deprecation.warn(
|
|
118
118
|
'The custom X-Spree-Token request header is deprecated and will be removed in the next release.' \
|
|
@@ -164,8 +164,8 @@ module Spree
|
|
|
164
164
|
|
|
165
165
|
def lock_order
|
|
166
166
|
OrderMutex.with_lock!(@order) { yield }
|
|
167
|
-
rescue Spree::OrderMutex::LockFailed =>
|
|
168
|
-
render plain:
|
|
167
|
+
rescue Spree::OrderMutex::LockFailed => error
|
|
168
|
+
render plain: error.message, status: :conflict
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
def insufficient_stock_error(exception)
|
|
@@ -175,7 +175,7 @@ module Spree
|
|
|
175
175
|
errors: [I18n.t(:quantity_is_not_available, scope: "spree.api.order")],
|
|
176
176
|
type: 'insufficient_stock'
|
|
177
177
|
},
|
|
178
|
-
status:
|
|
178
|
+
status: :unprocessable_entity
|
|
179
179
|
)
|
|
180
180
|
end
|
|
181
181
|
|
|
@@ -23,8 +23,8 @@ module Spree
|
|
|
23
23
|
authorize! :update, @order, order_token
|
|
24
24
|
@order.next!
|
|
25
25
|
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
|
|
26
|
-
rescue StateMachines::InvalidTransition =>
|
|
27
|
-
logger.error("invalid_transition #{
|
|
26
|
+
rescue StateMachines::InvalidTransition => error
|
|
27
|
+
logger.error("invalid_transition #{error.event} from #{error.from} for #{error.object.class.name}. Error: #{error.inspect}")
|
|
28
28
|
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -42,8 +42,8 @@ module Spree
|
|
|
42
42
|
@order.complete!
|
|
43
43
|
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
|
|
44
44
|
end
|
|
45
|
-
rescue StateMachines::InvalidTransition =>
|
|
46
|
-
logger.error("invalid_transition #{
|
|
45
|
+
rescue StateMachines::InvalidTransition => error
|
|
46
|
+
logger.error("invalid_transition #{error.event} from #{error.from} for #{error.object.class.name}. Error: #{error.inspect}")
|
|
47
47
|
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -76,11 +76,24 @@ module Spree
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def update_params
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
state = @order.state
|
|
80
|
+
case state.to_sym
|
|
81
|
+
when :cart, :address
|
|
82
|
+
massaged_params.fetch(:order, {}).permit(
|
|
83
|
+
permitted_checkout_address_attributes
|
|
84
|
+
)
|
|
85
|
+
when :delivery
|
|
86
|
+
massaged_params.require(:order).permit(
|
|
87
|
+
permitted_checkout_delivery_attributes
|
|
88
|
+
)
|
|
89
|
+
when :payment
|
|
90
|
+
massaged_params.require(:order).permit(
|
|
91
|
+
permitted_checkout_payment_attributes
|
|
92
|
+
)
|
|
81
93
|
else
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
massaged_params.fetch(:order, {}).permit(
|
|
95
|
+
permitted_checkout_confirm_attributes
|
|
96
|
+
)
|
|
84
97
|
end
|
|
85
98
|
end
|
|
86
99
|
|
|
@@ -55,10 +55,9 @@ module Spree
|
|
|
55
55
|
def index
|
|
56
56
|
authorize! :index, Order
|
|
57
57
|
orders_includes = [
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
61
|
-
:line_items
|
|
58
|
+
{ user: :store_credits },
|
|
59
|
+
:line_items,
|
|
60
|
+
:valid_store_credit_payments
|
|
62
61
|
]
|
|
63
62
|
@orders = paginate(
|
|
64
63
|
Spree::Order
|
|
@@ -131,7 +130,13 @@ module Spree
|
|
|
131
130
|
end
|
|
132
131
|
|
|
133
132
|
def normalize_params
|
|
134
|
-
|
|
133
|
+
if params[:order][:payments]
|
|
134
|
+
payments_params = params[:order].delete(:payments)
|
|
135
|
+
params[:order][:payments_attributes] = payments_params.map do |payment_params|
|
|
136
|
+
payment_params[:source_attributes] = payment_params.delete(:source) if payment_params[:source].present?
|
|
137
|
+
payment_params
|
|
138
|
+
end
|
|
139
|
+
end
|
|
135
140
|
params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
|
|
136
141
|
params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
|
|
137
142
|
params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address].present?
|
|
@@ -168,7 +173,13 @@ module Spree
|
|
|
168
173
|
end
|
|
169
174
|
|
|
170
175
|
def find_order(_lock = false)
|
|
171
|
-
@order = Spree::Order.
|
|
176
|
+
@order = Spree::Order.
|
|
177
|
+
includes(line_items: [:adjustments, { variant: :images }],
|
|
178
|
+
payments: :payment_method,
|
|
179
|
+
shipments: {
|
|
180
|
+
shipping_rates: { shipping_method: :zones, taxes: :tax_rate }
|
|
181
|
+
}).
|
|
182
|
+
find_by!(number: params[:id])
|
|
172
183
|
end
|
|
173
184
|
|
|
174
185
|
def order_id
|
|
@@ -58,7 +58,9 @@ module Spree
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def taxonomy
|
|
61
|
-
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).
|
|
61
|
+
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).
|
|
62
|
+
includes(root: :children).
|
|
63
|
+
find(params[:id])
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
def taxonomy_params
|
|
@@ -40,7 +40,7 @@ module Spree
|
|
|
40
40
|
|
|
41
41
|
def required_fields_for(model)
|
|
42
42
|
required_fields = model._validators.select do |_field, validations|
|
|
43
|
-
validations.any? { |
|
|
43
|
+
validations.any? { |validation| validation.is_a?(ActiveModel::Validations::PresenceValidator) }
|
|
44
44
|
end.map(&:first) # get fields that are invalid
|
|
45
45
|
# Permalinks presence is validated, but are really automatically generated
|
|
46
46
|
# Therefore we shouldn't tell API clients that they MUST send one through
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
json.(image, *image_attributes)
|
|
4
4
|
json.(image, :viewable_type, :viewable_id)
|
|
5
|
-
Spree::Image.attachment_definitions[:attachment][:styles].each do |
|
|
6
|
-
json.set! "#{
|
|
5
|
+
Spree::Image.attachment_definitions[:attachment][:styles].each do |key, _value|
|
|
6
|
+
json.set! "#{key}_url", image.attachment.url(key)
|
|
7
7
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
json.cache! [I18n.locale, order] do
|
|
4
4
|
json.(order, *order_attributes)
|
|
5
5
|
json.display_item_total(order.display_item_total.to_s)
|
|
6
|
-
json.total_quantity(order.line_items.sum(
|
|
6
|
+
json.total_quantity(order.line_items.to_a.sum(&:quantity))
|
|
7
7
|
json.display_total(order.display_total.to_s)
|
|
8
8
|
json.display_ship_total(order.display_ship_total)
|
|
9
9
|
json.display_tax_total(order.display_tax_total)
|
data/lib/spree/api/responders.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'responders'
|
|
4
|
-
require 'spree/api/responders/
|
|
4
|
+
require 'spree/api/responders/jbuilder_template'
|
|
5
5
|
|
|
6
6
|
module Spree
|
|
7
7
|
module Api
|
|
8
8
|
module Responders
|
|
9
9
|
class AppResponder < ActionController::Responder
|
|
10
|
-
include
|
|
10
|
+
include JbuilderTemplate
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Spree
|
|
4
4
|
module Api
|
|
5
5
|
module Responders
|
|
6
|
-
module
|
|
6
|
+
module JbuilderTemplate
|
|
7
7
|
def to_format
|
|
8
8
|
if template
|
|
9
9
|
render template, status: options[:status] || 200
|
|
@@ -16,6 +16,8 @@ module Spree
|
|
|
16
16
|
options[:default_template]
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
|
+
|
|
20
|
+
RablTemplate = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('RablTemplate', 'JbuilderTemplate')
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
data/openapi/api.oas2.yml
CHANGED
|
@@ -50,7 +50,7 @@ paths:
|
|
|
50
50
|
'422':
|
|
51
51
|
$ref: '#/responses/unprocessable-entity'
|
|
52
52
|
summary: Create product
|
|
53
|
-
description:
|
|
53
|
+
description: Creates a product.
|
|
54
54
|
operationId: create-product
|
|
55
55
|
tags:
|
|
56
56
|
- Products
|
|
@@ -545,7 +545,7 @@ paths:
|
|
|
545
545
|
- Variants
|
|
546
546
|
security:
|
|
547
547
|
- api-key: []
|
|
548
|
-
|
|
548
|
+
put:
|
|
549
549
|
responses:
|
|
550
550
|
'200':
|
|
551
551
|
description: ''
|
|
@@ -4264,7 +4264,7 @@ paths:
|
|
|
4264
4264
|
type: string
|
|
4265
4265
|
required: true
|
|
4266
4266
|
'/shipments/{shipment_number}/select_shipping_method':
|
|
4267
|
-
|
|
4267
|
+
put:
|
|
4268
4268
|
responses:
|
|
4269
4269
|
'200':
|
|
4270
4270
|
description: ''
|
|
@@ -4353,12 +4353,7 @@ paths:
|
|
|
4353
4353
|
- in: body
|
|
4354
4354
|
name: body
|
|
4355
4355
|
schema:
|
|
4356
|
-
|
|
4357
|
-
- $ref: '#/definitions/line-item-input'
|
|
4358
|
-
- type: object
|
|
4359
|
-
properties:
|
|
4360
|
-
variant_id:
|
|
4361
|
-
type: integer
|
|
4356
|
+
$ref: '#/definitions/line-item-input'
|
|
4362
4357
|
security:
|
|
4363
4358
|
- api-key: []
|
|
4364
4359
|
- order-token: []
|
|
@@ -4420,12 +4415,7 @@ paths:
|
|
|
4420
4415
|
- in: body
|
|
4421
4416
|
name: body
|
|
4422
4417
|
schema:
|
|
4423
|
-
|
|
4424
|
-
- type: object
|
|
4425
|
-
properties:
|
|
4426
|
-
variant_id:
|
|
4427
|
-
type: integer
|
|
4428
|
-
- $ref: '#/definitions/line-item-input'
|
|
4418
|
+
$ref: '#/definitions/line-item-input'
|
|
4429
4419
|
security:
|
|
4430
4420
|
- api-key: []
|
|
4431
4421
|
- order-token: []
|
|
@@ -4563,10 +4553,13 @@ paths:
|
|
|
4563
4553
|
- Products
|
|
4564
4554
|
parameters:
|
|
4565
4555
|
- in: query
|
|
4566
|
-
name:
|
|
4556
|
+
name: id
|
|
4567
4557
|
type: integer
|
|
4568
4558
|
- $ref: '#/parameters/page'
|
|
4569
4559
|
- $ref: '#/parameters/per_page'
|
|
4560
|
+
- type: boolean
|
|
4561
|
+
in: query
|
|
4562
|
+
name: simple
|
|
4570
4563
|
security:
|
|
4571
4564
|
- api-key: []
|
|
4572
4565
|
schemes:
|
|
@@ -5638,8 +5631,16 @@ definitions:
|
|
|
5638
5631
|
properties:
|
|
5639
5632
|
quantity:
|
|
5640
5633
|
type: integer
|
|
5634
|
+
description: 'Passing `0`, the line item will be removed.'
|
|
5641
5635
|
options:
|
|
5642
5636
|
type: object
|
|
5637
|
+
description: 'This field can be used to pass custom line item attributes. When used, it will force a new price calculation, unless `price` is one of the options.'
|
|
5638
|
+
id:
|
|
5639
|
+
type: integer
|
|
5640
|
+
description: Required for existing line items only.
|
|
5641
|
+
variant_id:
|
|
5642
|
+
type: integer
|
|
5643
|
+
description: Required for new line items only.
|
|
5643
5644
|
option-type-input:
|
|
5644
5645
|
type: object
|
|
5645
5646
|
title: Option type input
|
data/solidus_api.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
gem.require_paths = ["lib"]
|
|
19
19
|
gem.version = Spree.solidus_version
|
|
20
20
|
|
|
21
|
-
gem.required_ruby_version = '>= 2.
|
|
21
|
+
gem.required_ruby_version = '>= 2.4.0'
|
|
22
22
|
gem.required_rubygems_version = '>= 1.8.23'
|
|
23
23
|
|
|
24
24
|
gem.add_dependency 'jbuilder', '~> 2.8'
|
|
@@ -25,10 +25,10 @@ module Spree
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
with_model 'Widget', scope: :all do
|
|
28
|
-
table do |
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
table do |widget|
|
|
29
|
+
widget.string :name
|
|
30
|
+
widget.integer :position
|
|
31
|
+
widget.timestamps null: false
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
model do
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Spree Api Responders" do
|
|
6
|
+
it "RablTemplate is deprecated Use JbuilderTemplate" do
|
|
7
|
+
warning_message = /DEPRECATION WARNING: RablTemplate is deprecated! Use JbuilderTemplate instead/
|
|
8
|
+
expect{ Spree::Api::Responders::RablTemplate.methods }.to output(warning_message).to_stderr
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -80,7 +80,7 @@ module Spree
|
|
|
80
80
|
user_address = UserAddress.last
|
|
81
81
|
|
|
82
82
|
expect(response.status).to eq(200)
|
|
83
|
-
update_target_ids = JSON.parse(response.body).select { |
|
|
83
|
+
update_target_ids = JSON.parse(response.body).select { |target| target['update_target'] }.map { |location| location['id'] }
|
|
84
84
|
expect(update_target_ids).to eq([user_address.address_id])
|
|
85
85
|
end
|
|
86
86
|
end
|
|
@@ -97,7 +97,7 @@ module Spree
|
|
|
97
97
|
}.to_not change { UserAddress.count }
|
|
98
98
|
|
|
99
99
|
expect(response.status).to eq(200)
|
|
100
|
-
update_target_ids = JSON.parse(response.body).select { |
|
|
100
|
+
update_target_ids = JSON.parse(response.body).select { |target| target['update_target'] }.map { |location| location['id'] }
|
|
101
101
|
expect(update_target_ids).to eq([address.id])
|
|
102
102
|
end
|
|
103
103
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
|
-
describe "
|
|
5
|
+
describe "Jbuilder Cache", type: :request, caching: true do
|
|
6
6
|
let!(:user) { create(:admin_user) }
|
|
7
7
|
|
|
8
8
|
before do
|
|
@@ -11,7 +11,7 @@ describe "Rabl Cache", type: :request, caching: true do
|
|
|
11
11
|
expect(Spree::Product.count).to eq(1)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
it "doesn't create a cache key collision for models with different
|
|
14
|
+
it "doesn't create a cache key collision for models with different jbuilder templates" do
|
|
15
15
|
get "/api/variants", params: { token: user.spree_api_key }
|
|
16
16
|
expect(response.status).to eq(200)
|
|
17
17
|
|
|
@@ -132,9 +132,9 @@ module Spree
|
|
|
132
132
|
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } } }
|
|
133
133
|
expect(response.status).to eq(200)
|
|
134
134
|
# Find the correct shipment...
|
|
135
|
-
json_shipment = json_response['shipments'].detect { |
|
|
135
|
+
json_shipment = json_response['shipments'].detect { |value| value["id"] == shipment.id }
|
|
136
136
|
# Find the correct shipping rate for that shipment...
|
|
137
|
-
json_shipping_rate = json_shipment['shipping_rates'].detect { |
|
|
137
|
+
json_shipping_rate = json_shipment['shipping_rates'].detect { |value| value["id"] == shipping_rate.id }
|
|
138
138
|
# ... And finally ensure that it's selected
|
|
139
139
|
expect(json_shipping_rate['selected']).to be true
|
|
140
140
|
# Order should automatically transfer to payment because all criteria are met
|
|
@@ -172,6 +172,7 @@ module Spree
|
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
describe 'setting the payment amount' do
|
|
175
|
+
let(:order) { create(:order_with_line_items, state: :payment) }
|
|
175
176
|
let(:params) do
|
|
176
177
|
{
|
|
177
178
|
order_token: order.guest_token,
|
|
@@ -322,17 +323,44 @@ module Spree
|
|
|
322
323
|
end
|
|
323
324
|
end
|
|
324
325
|
|
|
326
|
+
it "cannot update attributes of another step" do
|
|
327
|
+
order.update_column(:state, "payment")
|
|
328
|
+
|
|
329
|
+
params = {
|
|
330
|
+
order_token: order.guest_token,
|
|
331
|
+
order: {
|
|
332
|
+
payments_attributes: [
|
|
333
|
+
{
|
|
334
|
+
payment_method_id: @payment_method.id.to_s,
|
|
335
|
+
source_attributes: attributes_for(:credit_card)
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
ship_address_attributes: {
|
|
339
|
+
zipcode: 'MALICIOUS ZIPCODE'
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
expect do
|
|
344
|
+
put spree.api_checkout_path(order), params: params
|
|
345
|
+
end.not_to change { order.reload.ship_address.zipcode }
|
|
346
|
+
expect(response.status).to eq(200)
|
|
347
|
+
end
|
|
348
|
+
|
|
325
349
|
it "returns the order if the order is already complete" do
|
|
326
350
|
order.update_columns(completed_at: Time.current, state: 'complete')
|
|
327
351
|
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
|
|
328
352
|
assert_unauthorized!
|
|
329
353
|
end
|
|
330
354
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
355
|
+
context "in delivery state" do
|
|
356
|
+
let(:order) { create(:order_with_line_items, state: :delivery) }
|
|
357
|
+
|
|
358
|
+
# Regression test for https://github.com/spree/spree/issues/3784
|
|
359
|
+
it "can update the special instructions for an order" do
|
|
360
|
+
instructions = "Don't drop it. (Please)"
|
|
361
|
+
put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
|
|
362
|
+
expect(json_response['special_instructions']).to eql(instructions)
|
|
363
|
+
end
|
|
336
364
|
end
|
|
337
365
|
|
|
338
366
|
context "as an admin" do
|
|
@@ -34,9 +34,9 @@ module Spree
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "can retrieve a list of specific option types" do
|
|
37
|
-
|
|
37
|
+
option_type_one = create(:option_type)
|
|
38
38
|
create(:option_type)
|
|
39
|
-
get spree.api_option_types_path, params: { ids: "#{option_type.id},#{
|
|
39
|
+
get spree.api_option_types_path, params: { ids: "#{option_type.id},#{option_type_one.id}" }
|
|
40
40
|
expect(json_response.count).to eq(2)
|
|
41
41
|
|
|
42
42
|
check_option_values(json_response.first["option_values"])
|
|
@@ -48,9 +48,9 @@ module Spree
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "can retrieve a list of option types" do
|
|
51
|
-
|
|
51
|
+
option_value_one = create(:option_value, option_type: option_type)
|
|
52
52
|
create(:option_value, option_type: option_type)
|
|
53
|
-
get spree.api_option_values_path, params: { ids: [option_value.id,
|
|
53
|
+
get spree.api_option_values_path, params: { ids: [option_value.id, option_value_one.id] }
|
|
54
54
|
expect(json_response.count).to eq(2)
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -156,6 +156,7 @@ module Spree
|
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
context 'creating payment' do
|
|
159
|
+
let!(:order) { create(:order_with_line_items) }
|
|
159
160
|
let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
|
160
161
|
|
|
161
162
|
context "with allowed payment method" do
|
|
@@ -166,6 +167,28 @@ module Spree
|
|
|
166
167
|
subject
|
|
167
168
|
}.to change { Spree::Payment.count }.by(1)
|
|
168
169
|
end
|
|
170
|
+
|
|
171
|
+
context 'trying to change the address' do
|
|
172
|
+
let(:order_params) do
|
|
173
|
+
super().merge(
|
|
174
|
+
ship_address_attributes: {
|
|
175
|
+
zipcode: '90100'
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'changes the address' do
|
|
181
|
+
expect {
|
|
182
|
+
subject
|
|
183
|
+
}.to change { order.reload.ship_address.zipcode }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it 'invalidates the shipments' do
|
|
187
|
+
expect {
|
|
188
|
+
subject
|
|
189
|
+
}.to change { order.reload.shipments }.to([])
|
|
190
|
+
end
|
|
191
|
+
end
|
|
169
192
|
end
|
|
170
193
|
|
|
171
194
|
context "with disallowed payment method" do
|
|
@@ -246,12 +269,12 @@ module Spree
|
|
|
246
269
|
it "returns orders in reverse chronological order by completed_at" do
|
|
247
270
|
order.update_columns completed_at: Time.current, created_at: 3.days.ago
|
|
248
271
|
|
|
249
|
-
|
|
250
|
-
expect(
|
|
251
|
-
|
|
252
|
-
expect(
|
|
253
|
-
|
|
254
|
-
expect(
|
|
272
|
+
order_two = Order.create user: order.user, completed_at: Time.current - 1.day, created_at: 2.days.ago, store: store
|
|
273
|
+
expect(order_two.created_at).to be > order.created_at
|
|
274
|
+
order_three = Order.create user: order.user, completed_at: nil, created_at: 1.day.ago, store: store
|
|
275
|
+
expect(order_three.created_at).to be > order_two.created_at
|
|
276
|
+
order_four = Order.create user: order.user, completed_at: nil, created_at: 0.days.ago, store: store
|
|
277
|
+
expect(order_four.created_at).to be > order_three.created_at
|
|
255
278
|
|
|
256
279
|
get spree.api_my_orders_path, headers: { 'SERVER_NAME' => store.url }
|
|
257
280
|
expect(response.status).to eq(200)
|
|
@@ -259,8 +282,8 @@ module Spree
|
|
|
259
282
|
orders = json_response["orders"]
|
|
260
283
|
expect(orders.length).to eq(4)
|
|
261
284
|
expect(orders[0]["number"]).to eq(order.number)
|
|
262
|
-
expect(orders[1]["number"]).to eq(
|
|
263
|
-
expect([orders[2]["number"], orders[3]["number"]]).to match_array([
|
|
285
|
+
expect(orders[1]["number"]).to eq(order_two.number)
|
|
286
|
+
expect([orders[2]["number"], orders[3]["number"]]).to match_array([order_three.number, order_four.number])
|
|
264
287
|
end
|
|
265
288
|
end
|
|
266
289
|
|
|
@@ -502,18 +525,18 @@ module Spree
|
|
|
502
525
|
end
|
|
503
526
|
|
|
504
527
|
it "adds an extra line item" do
|
|
505
|
-
|
|
528
|
+
variant_two = create(:variant)
|
|
506
529
|
put spree.api_order_path(order), params: { order: {
|
|
507
530
|
line_items: {
|
|
508
531
|
"0" => { id: line_item.id, quantity: 10 },
|
|
509
|
-
"1" => { variant_id:
|
|
532
|
+
"1" => { variant_id: variant_two.id, quantity: 1 }
|
|
510
533
|
}
|
|
511
534
|
} }
|
|
512
535
|
|
|
513
536
|
expect(response.status).to eq(200)
|
|
514
537
|
expect(json_response['line_items'].count).to eq(2)
|
|
515
538
|
expect(json_response['line_items'][0]['quantity']).to eq(10)
|
|
516
|
-
expect(json_response['line_items'][1]['variant_id']).to eq(
|
|
539
|
+
expect(json_response['line_items'][1]['variant_id']).to eq(variant_two.id)
|
|
517
540
|
expect(json_response['line_items'][1]['quantity']).to eq(1)
|
|
518
541
|
end
|
|
519
542
|
|
|
@@ -727,7 +750,7 @@ module Spree
|
|
|
727
750
|
|
|
728
751
|
orders = json_response[:orders]
|
|
729
752
|
expect(orders.count).to be >= 3
|
|
730
|
-
expect(orders.map { |
|
|
753
|
+
expect(orders.map { |order| order[:id] }).to match_array Order.pluck(:id)
|
|
731
754
|
end
|
|
732
755
|
|
|
733
756
|
after { ActionController::Base.perform_caching = false }
|
|
@@ -17,8 +17,8 @@ module Spree
|
|
|
17
17
|
shipping_category_id: create(:shipping_category).id }
|
|
18
18
|
end
|
|
19
19
|
let(:attributes_for_variant) do
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
attributes = attributes_for(:variant).except(:option_values, :product)
|
|
21
|
+
attributes.merge({
|
|
22
22
|
options: [
|
|
23
23
|
{ name: "size", value: "small" },
|
|
24
24
|
{ name: "color", value: "black" }
|
|
@@ -40,7 +40,7 @@ module Spree
|
|
|
40
40
|
|
|
41
41
|
it "returns unique products" do
|
|
42
42
|
get spree.api_products_path
|
|
43
|
-
product_ids = json_response["products"].map { |
|
|
43
|
+
product_ids = json_response["products"].map { |product| product["id"] }
|
|
44
44
|
expect(product_ids.uniq.count).to eq(product_ids.count)
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -361,8 +361,8 @@ module Spree
|
|
|
361
361
|
expect(response.status).to eq 200
|
|
362
362
|
expect(json_response['variants'].count).to eq(2) # 2 variants
|
|
363
363
|
|
|
364
|
-
variants = json_response['variants'].reject { |
|
|
365
|
-
size_option_value = variants.last['option_values'].detect{ |
|
|
364
|
+
variants = json_response['variants'].reject { |variant| variant['is_master'] }
|
|
365
|
+
size_option_value = variants.last['option_values'].detect{ |value| value['option_type_name'] == 'size' }
|
|
366
366
|
expect(size_option_value['name']).to eq('small')
|
|
367
367
|
|
|
368
368
|
expect(json_response['option_types'].count).to eq(2) # size, color
|
|
@@ -385,7 +385,7 @@ module Spree
|
|
|
385
385
|
} }
|
|
386
386
|
|
|
387
387
|
expect(json_response['variants'].count).to eq(1)
|
|
388
|
-
variants = json_response['variants'].reject { |
|
|
388
|
+
variants = json_response['variants'].reject { |variant| variant['is_master'] }
|
|
389
389
|
expect(variants.last['option_values'][0]['name']).to eq('large')
|
|
390
390
|
expect(variants.last['sku']).to eq('456')
|
|
391
391
|
expect(variants.count).to eq(1)
|
|
@@ -93,9 +93,9 @@ module Spree
|
|
|
93
93
|
it 'returns only requested ids' do
|
|
94
94
|
# We need a completly new branch to avoid having parent that can be preloaded from the rails ancestors
|
|
95
95
|
python = create(:taxon, name: "Python", parent: taxonomy.root, taxonomy: taxonomy)
|
|
96
|
-
|
|
96
|
+
python_three = create(:taxon, name: "3.0", parent: python, taxonomy: taxonomy)
|
|
97
97
|
|
|
98
|
-
get spree.api_taxons_path, params: { ids: [rails_v3_2_2.id,
|
|
98
|
+
get spree.api_taxons_path, params: { ids: [rails_v3_2_2.id, python_three.id] }
|
|
99
99
|
|
|
100
100
|
expect(json_response['taxons'].size).to eq 2
|
|
101
101
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.10.
|
|
4
|
+
version: 2.10.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solidus Team
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jbuilder
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - '='
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 2.10.
|
|
61
|
+
version: 2.10.5
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - '='
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 2.10.
|
|
68
|
+
version: 2.10.5
|
|
69
69
|
description: REST API for the Solidus e-commerce framework.
|
|
70
70
|
email: contact@solidus.io
|
|
71
71
|
executables: []
|
|
@@ -232,7 +232,7 @@ files:
|
|
|
232
232
|
- lib/spree/api/config.rb
|
|
233
233
|
- lib/spree/api/engine.rb
|
|
234
234
|
- lib/spree/api/responders.rb
|
|
235
|
-
- lib/spree/api/responders/
|
|
235
|
+
- lib/spree/api/responders/jbuilder_template.rb
|
|
236
236
|
- lib/spree/api/testing_support/caching.rb
|
|
237
237
|
- lib/spree/api/testing_support/helpers.rb
|
|
238
238
|
- lib/spree/api/testing_support/setup.rb
|
|
@@ -253,9 +253,10 @@ files:
|
|
|
253
253
|
- spec/controllers/spree/api/resource_controller_spec.rb
|
|
254
254
|
- spec/features/checkout_spec.rb
|
|
255
255
|
- spec/fixtures/thinking-cat.jpg
|
|
256
|
+
- spec/lib/spree_api_responders_spec.rb
|
|
256
257
|
- spec/models/spree/legacy_user_spec.rb
|
|
257
258
|
- spec/requests/api/address_books_spec.rb
|
|
258
|
-
- spec/requests/
|
|
259
|
+
- spec/requests/jbuilder_cache_spec.rb
|
|
259
260
|
- spec/requests/ransackable_attributes_spec.rb
|
|
260
261
|
- spec/requests/spree/api/addresses_controller_spec.rb
|
|
261
262
|
- spec/requests/spree/api/checkouts_controller_spec.rb
|
|
@@ -304,7 +305,7 @@ homepage: http://solidus.io/
|
|
|
304
305
|
licenses:
|
|
305
306
|
- BSD-3-Clause
|
|
306
307
|
metadata: {}
|
|
307
|
-
post_install_message:
|
|
308
|
+
post_install_message:
|
|
308
309
|
rdoc_options: []
|
|
309
310
|
require_paths:
|
|
310
311
|
- lib
|
|
@@ -312,15 +313,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
312
313
|
requirements:
|
|
313
314
|
- - ">="
|
|
314
315
|
- !ruby/object:Gem::Version
|
|
315
|
-
version: 2.
|
|
316
|
+
version: 2.4.0
|
|
316
317
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
318
|
requirements:
|
|
318
319
|
- - ">="
|
|
319
320
|
- !ruby/object:Gem::Version
|
|
320
321
|
version: 1.8.23
|
|
321
322
|
requirements: []
|
|
322
|
-
rubygems_version: 3.
|
|
323
|
-
signing_key:
|
|
323
|
+
rubygems_version: 3.1.4
|
|
324
|
+
signing_key:
|
|
324
325
|
specification_version: 4
|
|
325
326
|
summary: REST API for the Solidus e-commerce framework.
|
|
326
327
|
test_files:
|
|
@@ -328,9 +329,10 @@ test_files:
|
|
|
328
329
|
- spec/controllers/spree/api/resource_controller_spec.rb
|
|
329
330
|
- spec/features/checkout_spec.rb
|
|
330
331
|
- spec/fixtures/thinking-cat.jpg
|
|
332
|
+
- spec/lib/spree_api_responders_spec.rb
|
|
331
333
|
- spec/models/spree/legacy_user_spec.rb
|
|
332
334
|
- spec/requests/api/address_books_spec.rb
|
|
333
|
-
- spec/requests/
|
|
335
|
+
- spec/requests/jbuilder_cache_spec.rb
|
|
334
336
|
- spec/requests/ransackable_attributes_spec.rb
|
|
335
337
|
- spec/requests/spree/api/addresses_controller_spec.rb
|
|
336
338
|
- spec/requests/spree/api/checkouts_controller_spec.rb
|