solidus_api 2.10.5 → 2.11.0
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 +2 -2
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +11 -3
- data/app/controllers/spree/api/checkouts_controller.rb +1 -11
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +2 -2
- data/app/controllers/spree/api/customer_returns_controller.rb +67 -0
- data/app/controllers/spree/api/images_controller.rb +4 -4
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/option_types_controller.rb +3 -3
- data/app/controllers/spree/api/option_values_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +1 -1
- data/app/controllers/spree/api/payments_controller.rb +1 -1
- data/app/controllers/spree/api/product_properties_controller.rb +9 -14
- data/app/controllers/spree/api/promotions_controller.rb +3 -12
- data/app/controllers/spree/api/properties_controller.rb +3 -3
- data/app/controllers/spree/api/resource_controller.rb +2 -2
- data/app/controllers/spree/api/return_authorizations_controller.rb +3 -3
- data/app/controllers/spree/api/shipments_controller.rb +1 -1
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +2 -2
- data/app/controllers/spree/api/stock_locations_controller.rb +3 -3
- data/app/controllers/spree/api/stock_movements_controller.rb +3 -3
- data/app/controllers/spree/api/stores_controller.rb +3 -3
- data/app/controllers/spree/api/taxonomies_controller.rb +2 -2
- data/app/controllers/spree/api/taxons_controller.rb +4 -4
- data/app/controllers/spree/api/users_controller.rb +13 -0
- data/app/controllers/spree/api/variants_controller.rb +3 -3
- data/app/controllers/spree/api/zones_controller.rb +2 -2
- data/app/helpers/spree/api/api_helpers.rb +18 -5
- data/app/views/spree/api/customer_returns/index.json.jbuilder +6 -0
- data/app/views/spree/api/customer_returns/new.json.jbuilder +4 -0
- data/app/views/spree/api/customer_returns/show.json.jbuilder +3 -0
- data/app/views/spree/api/errors/could_not_transition.json.jbuilder +4 -0
- data/app/views/spree/api/orders/could_not_transition.json.jbuilder +5 -0
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +6 -3
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/openapi/authentication.md +9 -1
- data/openapi/checkout-flow.md +17 -4
- data/openapi/main.hub.yml +1 -1
- data/openapi/solidus-api.oas.yml +6753 -0
- data/solidus_api.gemspec +19 -19
- metadata +14 -114
- data/openapi/api.oas2.yml +0 -6108
- data/script/rails +0 -10
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -118
- data/spec/controllers/spree/api/resource_controller_spec.rb +0 -190
- data/spec/features/checkout_spec.rb +0 -192
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/lib/spree_api_responders_spec.rb +0 -10
- data/spec/models/spree/legacy_user_spec.rb +0 -103
- data/spec/requests/api/address_books_spec.rb +0 -240
- data/spec/requests/jbuilder_cache_spec.rb +0 -34
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
- data/spec/requests/spree/api/addresses_controller_spec.rb +0 -57
- data/spec/requests/spree/api/checkouts_controller_spec.rb +0 -484
- data/spec/requests/spree/api/classifications_controller_spec.rb +0 -50
- data/spec/requests/spree/api/config_controller_spec.rb +0 -26
- data/spec/requests/spree/api/countries_controller_spec.rb +0 -48
- data/spec/requests/spree/api/coupon_codes_controller_spec.rb +0 -105
- data/spec/requests/spree/api/credit_cards_controller_spec.rb +0 -105
- data/spec/requests/spree/api/images_controller_spec.rb +0 -99
- data/spec/requests/spree/api/inventory_units_controller_spec.rb +0 -55
- data/spec/requests/spree/api/line_items_controller_spec.rb +0 -213
- data/spec/requests/spree/api/option_types_controller_spec.rb +0 -116
- data/spec/requests/spree/api/option_values_controller_spec.rb +0 -138
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -954
- data/spec/requests/spree/api/payments_controller_spec.rb +0 -259
- data/spec/requests/spree/api/product_properties_controller_spec.rb +0 -114
- data/spec/requests/spree/api/products_controller_spec.rb +0 -422
- data/spec/requests/spree/api/promotion_application_spec.rb +0 -50
- data/spec/requests/spree/api/promotions_controller_spec.rb +0 -67
- data/spec/requests/spree/api/properties_controller_spec.rb +0 -102
- data/spec/requests/spree/api/return_authorizations_controller_spec.rb +0 -180
- data/spec/requests/spree/api/shipments_controller_spec.rb +0 -532
- data/spec/requests/spree/api/states_controller_spec.rb +0 -69
- data/spec/requests/spree/api/stock_items_controller_spec.rb +0 -311
- data/spec/requests/spree/api/stock_locations_controller_spec.rb +0 -170
- data/spec/requests/spree/api/stock_movements_controller_spec.rb +0 -81
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +0 -59
- data/spec/requests/spree/api/stores_controller_spec.rb +0 -134
- data/spec/requests/spree/api/taxonomies_controller_spec.rb +0 -114
- data/spec/requests/spree/api/taxons_controller_spec.rb +0 -217
- data/spec/requests/spree/api/unauthenticated_products_controller_spec.rb +0 -27
- data/spec/requests/spree/api/users_controller_spec.rb +0 -151
- data/spec/requests/spree/api/variants_controller_spec.rb +0 -340
- data/spec/requests/spree/api/zones_controller_spec.rb +0 -89
- data/spec/shared_examples/protect_product_actions.rb +0 -18
- data/spec/spec_helper.rb +0 -73
- data/spec/support/be_paginated_matcher.rb +0 -9
- data/spec/support/controller_hacks.rb +0 -43
- data/spec/support/database_cleaner.rb +0 -16
- data/spec/support/have_attributes_matcher.rb +0 -11
- data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +0 -3
- data/spec/test_views/spree/api/widgets/index.json.jbuilder +0 -9
- data/spec/test_views/spree/api/widgets/new.json.jbuilder +0 -3
- data/spec/test_views/spree/api/widgets/show.json.jbuilder +0 -3
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
module Spree
|
|
6
|
-
PermittedAttributes.module_eval do
|
|
7
|
-
mattr_writer :line_item_attributes
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
unless PermittedAttributes.line_item_attributes.include? :options
|
|
11
|
-
PermittedAttributes.line_item_attributes << { options: [:some_option] }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe Api::LineItemsController, type: :request do
|
|
15
|
-
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
|
|
16
|
-
|
|
17
|
-
let(:product) { create(:product) }
|
|
18
|
-
let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
|
|
19
|
-
let(:resource_scoping) { { order_id: order.to_param } }
|
|
20
|
-
|
|
21
|
-
before do
|
|
22
|
-
stub_authentication!
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "can learn how to create a new line item" do
|
|
26
|
-
get spree.new_api_order_line_item_path(order)
|
|
27
|
-
expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
|
|
28
|
-
required_attributes = json_response["required_attributes"]
|
|
29
|
-
expect(required_attributes).to include("quantity", "variant_id")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
context "authenticating with a token" do
|
|
33
|
-
it "can add a new line item to an existing order" do
|
|
34
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 }, order_token: order.guest_token }
|
|
35
|
-
expect(response.status).to eq(201)
|
|
36
|
-
expect(json_response).to have_attributes(attributes)
|
|
37
|
-
expect(json_response["variant"]["name"]).not_to be_blank
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "can add a new line item to an existing order with token in header" do
|
|
41
|
-
post spree.api_order_line_items_path(order),
|
|
42
|
-
params: { line_item: { variant_id: product.master.to_param, quantity: 1 } },
|
|
43
|
-
headers: { 'X-Spree-Order-Token' => order.guest_token }
|
|
44
|
-
expect(response.status).to eq(201)
|
|
45
|
-
expect(json_response).to have_attributes(attributes)
|
|
46
|
-
expect(json_response["variant"]["name"]).not_to be_blank
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "as the order owner" do
|
|
51
|
-
before do
|
|
52
|
-
allow_any_instance_of(Order).to receive_messages user: current_api_user
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "dealing with a completed order" do
|
|
56
|
-
let!(:order) { create(:completed_order_with_totals) }
|
|
57
|
-
|
|
58
|
-
it "can't add a new line item" do
|
|
59
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
60
|
-
assert_unauthorized!
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "can't update a line item" do
|
|
64
|
-
line_item = order.line_items.first
|
|
65
|
-
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 10 } }
|
|
66
|
-
assert_unauthorized!
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "can't delete a line item" do
|
|
70
|
-
line_item = order.line_items.first
|
|
71
|
-
delete spree.api_order_line_item_path(order, line_item)
|
|
72
|
-
assert_unauthorized!
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "can add a new line item to an existing order" do
|
|
77
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
78
|
-
expect(response.status).to eq(201)
|
|
79
|
-
expect(json_response).to have_attributes(attributes)
|
|
80
|
-
expect(json_response["variant"]["name"]).not_to be_blank
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "can add a new line item to an existing order with options" do
|
|
84
|
-
without_partial_double_verification do
|
|
85
|
-
expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
|
|
86
|
-
end
|
|
87
|
-
post spree.api_order_line_items_path(order),
|
|
88
|
-
params: {
|
|
89
|
-
line_item: {
|
|
90
|
-
variant_id: product.master.to_param,
|
|
91
|
-
quantity: 1,
|
|
92
|
-
options: { some_option: "foobar" }
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
expect(response.status).to eq(201)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "default quantity to 1 if none is given" do
|
|
99
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param } }
|
|
100
|
-
expect(response.status).to eq(201)
|
|
101
|
-
expect(json_response).to have_attributes(attributes)
|
|
102
|
-
expect(json_response[:quantity]).to eq 1
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "increases a line item's quantity if it exists already" do
|
|
106
|
-
order.line_items.create(variant_id: product.master.id, quantity: 10)
|
|
107
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
108
|
-
expect(response.status).to eq(201)
|
|
109
|
-
order.reload
|
|
110
|
-
expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test
|
|
111
|
-
expect(json_response).to have_attributes(attributes)
|
|
112
|
-
expect(json_response["quantity"]).to eq(11)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "can update a line item on the order" do
|
|
116
|
-
line_item = order.line_items.first
|
|
117
|
-
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 101 } }
|
|
118
|
-
expect(response.status).to eq(200)
|
|
119
|
-
order.reload
|
|
120
|
-
expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
|
|
121
|
-
expect(json_response).to have_attributes(attributes)
|
|
122
|
-
expect(json_response["quantity"]).to eq(101)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "can update a line item's options on the order" do
|
|
126
|
-
without_partial_double_verification do
|
|
127
|
-
expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
|
|
128
|
-
end
|
|
129
|
-
line_item = order.line_items.first
|
|
130
|
-
put spree.api_order_line_item_path(order, line_item),
|
|
131
|
-
params: {
|
|
132
|
-
line_item: { quantity: 1, options: { some_option: "foobar" } }
|
|
133
|
-
}
|
|
134
|
-
expect(response.status).to eq(200)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "can delete a line item on the order" do
|
|
138
|
-
line_item = order.line_items.first
|
|
139
|
-
delete spree.api_order_line_item_path(order, line_item)
|
|
140
|
-
expect(response.status).to eq(204)
|
|
141
|
-
order.reload
|
|
142
|
-
expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test
|
|
143
|
-
expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context "order contents changed after shipments were created" do
|
|
147
|
-
let!(:store) { create(:store) }
|
|
148
|
-
let!(:order) { Order.create(store: store) }
|
|
149
|
-
let!(:line_item) { order.contents.add(product.master) }
|
|
150
|
-
|
|
151
|
-
before { order.create_proposed_shipments }
|
|
152
|
-
|
|
153
|
-
it "clear out shipments on create" do
|
|
154
|
-
expect(order.reload.shipments).not_to be_empty
|
|
155
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
156
|
-
expect(order.reload.shipments).to be_empty
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "clear out shipments on update" do
|
|
160
|
-
expect(order.reload.shipments).not_to be_empty
|
|
161
|
-
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 1000 } }
|
|
162
|
-
expect(order.reload.shipments).to be_empty
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it "clear out shipments on delete" do
|
|
166
|
-
expect(order.reload.shipments).not_to be_empty
|
|
167
|
-
delete spree.api_order_line_item_path(order, line_item)
|
|
168
|
-
expect(order.reload.shipments).to be_empty
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
context "order is completed" do
|
|
172
|
-
before do
|
|
173
|
-
allow(order).to receive_messages completed?: true
|
|
174
|
-
allow(Order).to receive_message_chain :includes, find_by!: order
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
it "doesn't destroy shipments or restart checkout flow" do
|
|
178
|
-
expect(order.reload.shipments).not_to be_empty
|
|
179
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
180
|
-
expect(order.reload.shipments).not_to be_empty
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
context "as just another user" do
|
|
187
|
-
before do
|
|
188
|
-
user = create(:user)
|
|
189
|
-
allow(Spree.user_class).to receive(:find_by).
|
|
190
|
-
and_return(user)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it "cannot add a new line item to the order" do
|
|
194
|
-
post spree.api_order_line_items_path(order), params: { line_item: { variant_id: product.master.to_param, quantity: 1 } }
|
|
195
|
-
assert_unauthorized!
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it "cannot update a line item on the order" do
|
|
199
|
-
line_item = order.line_items.first
|
|
200
|
-
put spree.api_order_line_item_path(order, line_item), params: { line_item: { quantity: 1000 } }
|
|
201
|
-
assert_unauthorized!
|
|
202
|
-
expect(line_item.reload.quantity).not_to eq(1000)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
it "cannot delete a line item on the order" do
|
|
206
|
-
line_item = order.line_items.first
|
|
207
|
-
delete spree.api_order_line_item_path(order, line_item)
|
|
208
|
-
assert_unauthorized!
|
|
209
|
-
expect { line_item.reload }.not_to raise_error
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
module Spree
|
|
6
|
-
describe Api::OptionTypesController, type: :request do
|
|
7
|
-
let(:attributes) { [:id, :name, :position, :presentation] }
|
|
8
|
-
let!(:option_value) { create(:option_value) }
|
|
9
|
-
let!(:option_type) { option_value.option_type }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
stub_authentication!
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def check_option_values(option_values)
|
|
16
|
-
expect(option_values.count).to eq(1)
|
|
17
|
-
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
|
18
|
-
:option_type_name, :option_type_id])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "can list all option types" do
|
|
22
|
-
get spree.api_option_types_path
|
|
23
|
-
expect(json_response.count).to eq(1)
|
|
24
|
-
expect(json_response.first).to have_attributes(attributes)
|
|
25
|
-
|
|
26
|
-
check_option_values(json_response.first["option_values"])
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "can search for an option type" do
|
|
30
|
-
create(:option_type, name: "buzz")
|
|
31
|
-
get spree.api_option_types_path, params: { q: { name_cont: option_type.name } }
|
|
32
|
-
expect(json_response.count).to eq(1)
|
|
33
|
-
expect(json_response.first).to have_attributes(attributes)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "can retrieve a list of specific option types" do
|
|
37
|
-
option_type_one = create(:option_type)
|
|
38
|
-
create(:option_type)
|
|
39
|
-
get spree.api_option_types_path, params: { ids: "#{option_type.id},#{option_type_one.id}" }
|
|
40
|
-
expect(json_response.count).to eq(2)
|
|
41
|
-
|
|
42
|
-
check_option_values(json_response.first["option_values"])
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "can list a single option type" do
|
|
46
|
-
get spree.api_option_type_path(option_type)
|
|
47
|
-
expect(json_response).to have_attributes(attributes)
|
|
48
|
-
check_option_values(json_response["option_values"])
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "cannot create a new option type" do
|
|
52
|
-
post spree.api_option_types_path, params: {
|
|
53
|
-
option_type: {
|
|
54
|
-
name: "Option Type",
|
|
55
|
-
presentation: "Option Type"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
assert_unauthorized!
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "cannot alter an option type" do
|
|
62
|
-
original_name = option_type.name
|
|
63
|
-
put spree.api_option_type_path(option_type), params: {
|
|
64
|
-
option_type: {
|
|
65
|
-
name: "Option Type"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
assert_not_found!
|
|
69
|
-
expect(option_type.reload.name).to eq(original_name)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "cannot delete an option type" do
|
|
73
|
-
delete spree.api_option_type_path(option_type)
|
|
74
|
-
assert_not_found!
|
|
75
|
-
expect { option_type.reload }.not_to raise_error
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
context "as an admin" do
|
|
79
|
-
sign_in_as_admin!
|
|
80
|
-
|
|
81
|
-
it "can create an option type" do
|
|
82
|
-
post spree.api_option_types_path, params: {
|
|
83
|
-
option_type: {
|
|
84
|
-
name: "Option Type",
|
|
85
|
-
presentation: "Option Type"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
expect(json_response).to have_attributes(attributes)
|
|
89
|
-
expect(response.status).to eq(201)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "cannot create an option type with invalid attributes" do
|
|
93
|
-
post spree.api_option_types_path, params: { option_type: {} }
|
|
94
|
-
expect(response.status).to eq(422)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "can update an option type" do
|
|
98
|
-
put spree.api_option_type_path(option_type.id), params: { option_type: { name: "Option Type" } }
|
|
99
|
-
expect(response.status).to eq(200)
|
|
100
|
-
|
|
101
|
-
option_type.reload
|
|
102
|
-
expect(option_type.name).to eq("Option Type")
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "cannot update an option type with invalid attributes" do
|
|
106
|
-
put spree.api_option_type_path(option_type.id), params: { option_type: { name: "" } }
|
|
107
|
-
expect(response.status).to eq(422)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "can delete an option type" do
|
|
111
|
-
delete spree.api_option_type_path(option_type.id)
|
|
112
|
-
expect(response.status).to eq(204)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
module Spree
|
|
6
|
-
describe Api::OptionValuesController, type: :request do
|
|
7
|
-
let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
|
|
8
|
-
let!(:option_value) { create(:option_value) }
|
|
9
|
-
let!(:option_type) { option_value.option_type }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
stub_authentication!
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def check_option_values(option_values)
|
|
16
|
-
expect(option_values.count).to eq(1)
|
|
17
|
-
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
|
18
|
-
:option_type_name, :option_type_id])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "without any option type scoping" do
|
|
22
|
-
before do
|
|
23
|
-
# Create another option value with a brand new option type
|
|
24
|
-
create(:option_value, option_type: create(:option_type))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "can retrieve a list of all option values" do
|
|
28
|
-
get spree.api_option_values_path
|
|
29
|
-
expect(json_response.count).to eq(2)
|
|
30
|
-
expect(json_response.first).to have_attributes(attributes)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "for a particular option type" do
|
|
35
|
-
let(:resource_scoping) { { option_type_id: option_type.id } }
|
|
36
|
-
|
|
37
|
-
it "can list all option values" do
|
|
38
|
-
get spree.api_option_values_path
|
|
39
|
-
expect(json_response.count).to eq(1)
|
|
40
|
-
expect(json_response.first).to have_attributes(attributes)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "can search for an option type" do
|
|
44
|
-
create(:option_value, name: "buzz")
|
|
45
|
-
get spree.api_option_values_path, params: { q: { name_cont: option_value.name } }
|
|
46
|
-
expect(json_response.count).to eq(1)
|
|
47
|
-
expect(json_response.first).to have_attributes(attributes)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "can retrieve a list of option types" do
|
|
51
|
-
option_value_one = create(:option_value, option_type: option_type)
|
|
52
|
-
create(:option_value, option_type: option_type)
|
|
53
|
-
get spree.api_option_values_path, params: { ids: [option_value.id, option_value_one.id] }
|
|
54
|
-
expect(json_response.count).to eq(2)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "can list a single option value" do
|
|
58
|
-
get spree.api_option_value_path(option_value.id)
|
|
59
|
-
expect(json_response).to have_attributes(attributes)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "cannot create a new option value" do
|
|
63
|
-
post spree.api_option_type_option_values_path(option_type), params: {
|
|
64
|
-
option_value: {
|
|
65
|
-
name: "Option Value",
|
|
66
|
-
presentation: "Option Value"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
assert_unauthorized!
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "cannot alter an option value" do
|
|
73
|
-
original_name = option_type.name
|
|
74
|
-
put spree.api_option_value_path(option_value.id), params: {
|
|
75
|
-
id: option_type.id,
|
|
76
|
-
option_value: {
|
|
77
|
-
name: "Option Value"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
assert_not_found!
|
|
81
|
-
expect(option_type.reload.name).to eq(original_name)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "cannot delete an option value" do
|
|
85
|
-
delete spree.api_option_value_path(option_value)
|
|
86
|
-
assert_not_found!
|
|
87
|
-
expect { option_type.reload }.not_to raise_error
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
context "as an admin" do
|
|
91
|
-
sign_in_as_admin!
|
|
92
|
-
|
|
93
|
-
it "can create an option value" do
|
|
94
|
-
post spree.api_option_type_option_values_path(option_type), params: {
|
|
95
|
-
option_value: {
|
|
96
|
-
name: "Option Value",
|
|
97
|
-
presentation: "Option Value",
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
expect(json_response).to have_attributes(attributes)
|
|
101
|
-
expect(response.status).to eq(201)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "cannot create an option type with invalid attributes" do
|
|
105
|
-
post spree.api_option_type_option_values_path(option_type), params: { option_value: { name: "" } }
|
|
106
|
-
expect(response.status).to eq(422)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "can update an option value" do
|
|
110
|
-
put spree.api_option_value_path(option_value.id), params: { option_value: {
|
|
111
|
-
name: "Option Value"
|
|
112
|
-
} }
|
|
113
|
-
expect(response.status).to eq(200)
|
|
114
|
-
|
|
115
|
-
option_value.reload
|
|
116
|
-
expect(option_value.name).to eq("Option Value")
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "permits the correct attributes" do
|
|
120
|
-
expect_any_instance_of(Spree::Api::OptionValuesController).to receive(:permitted_option_value_attributes)
|
|
121
|
-
put spree.api_option_value_path(option_value), params: { option_value: { name: "" } }
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it "cannot update an option value with invalid attributes" do
|
|
125
|
-
put spree.api_option_value_path(option_value), params: { option_value: {
|
|
126
|
-
name: ""
|
|
127
|
-
} }
|
|
128
|
-
expect(response.status).to eq(422)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "can delete an option value" do
|
|
132
|
-
delete spree.api_option_value_path(option_value)
|
|
133
|
-
expect(response.status).to eq(204)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|