solidus_api 2.2.2 → 2.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/app/controllers/spree/api/images_controller.rb +2 -2
- data/app/controllers/spree/api/line_items_controller.rb +2 -10
- data/app/controllers/spree/api/orders_controller.rb +2 -12
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/app/controllers/spree/api/promotions_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +2 -1
- data/app/views/spree/api/orders/show.v1.rabl +2 -1
- data/lib/spree/api/testing_support/setup.rb +1 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +7 -7
- data/spec/controllers/spree/api/resource_controller_spec.rb +16 -16
- data/spec/requests/api/address_books_spec.rb +1 -1
- data/spec/{controllers → requests}/spree/api/addresses_controller_spec.rb +6 -9
- data/spec/{controllers → requests}/spree/api/checkouts_controller_spec.rb +38 -69
- data/spec/{controllers → requests}/spree/api/classifications_controller_spec.rb +4 -4
- data/spec/{controllers → requests}/spree/api/config_controller_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/countries_controller_spec.rb +6 -7
- data/spec/{controllers → requests}/spree/api/credit_cards_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/images_controller_spec.rb +19 -16
- data/spec/{controllers → requests}/spree/api/inventory_units_controller_spec.rb +17 -14
- data/spec/{controllers → requests}/spree/api/line_items_controller_spec.rb +32 -32
- data/spec/{controllers → requests}/spree/api/option_types_controller_spec.rb +27 -27
- data/spec/{controllers → requests}/spree/api/option_values_controller_spec.rb +32 -29
- data/spec/{controllers → requests}/spree/api/orders_controller_spec.rb +103 -133
- data/spec/{controllers → requests}/spree/api/payments_controller_spec.rb +30 -44
- data/spec/{controllers → requests}/spree/api/product_properties_controller_spec.rb +15 -17
- data/spec/{controllers → requests}/spree/api/products_controller_spec.rb +44 -43
- data/spec/{controllers → requests}/spree/api/promotion_application_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/promotions_controller_spec.rb +8 -6
- data/spec/{controllers → requests}/spree/api/properties_controller_spec.rb +15 -16
- data/spec/{controllers → requests}/spree/api/return_authorizations_controller_spec.rb +19 -21
- data/spec/requests/spree/api/shipments_controller_spec.rb +394 -88
- data/spec/{controllers → requests}/spree/api/states_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/stock_items_controller_spec.rb +21 -21
- data/spec/{controllers → requests}/spree/api/stock_locations_controller_spec.rb +18 -20
- data/spec/{controllers → requests}/spree/api/stock_movements_controller_spec.rb +9 -12
- data/spec/{controllers → requests}/spree/api/stock_transfers_controller_spec.rb +2 -3
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +57 -0
- data/spec/{controllers → requests}/spree/api/stores_controller_spec.rb +19 -20
- data/spec/{controllers → requests}/spree/api/taxonomies_controller_spec.rb +14 -15
- data/spec/{controllers → requests}/spree/api/taxons_controller_spec.rb +17 -18
- data/spec/{controllers → requests}/spree/api/transfer_items_controller_spec.rb +7 -9
- data/spec/{controllers → requests}/spree/api/unauthenticated_products_controller_spec.rb +2 -3
- data/spec/{controllers → requests}/spree/api/users_controller_spec.rb +18 -19
- data/spec/{controllers → requests}/spree/api/variants_controller_spec.rb +70 -37
- data/spec/{controllers → requests}/spree/api/zones_controller_spec.rb +13 -14
- data/spec/shared_examples/protect_product_actions.rb +3 -3
- data/spec/spec_helper.rb +4 -1
- metadata +70 -72
- data/spec/controllers/spree/api/shipments_controller_spec.rb +0 -301
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -66
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Spree::Api::PaymentsController, type: :
|
5
|
-
render_views
|
4
|
+
describe Spree::Api::PaymentsController, type: :request do
|
6
5
|
let!(:order) { create(:order) }
|
7
6
|
let!(:payment) { create(:payment, order: order) }
|
8
7
|
let!(:attributes) {
|
@@ -11,8 +10,6 @@ module Spree
|
|
11
10
|
:created_at, :updated_at]
|
12
11
|
}
|
13
12
|
|
14
|
-
let(:resource_scoping) { { order_id: order.to_param } }
|
15
|
-
|
16
13
|
before do
|
17
14
|
stub_authentication!
|
18
15
|
end
|
@@ -24,12 +21,12 @@ module Spree
|
|
24
21
|
end
|
25
22
|
|
26
23
|
it "can view the payments for their order" do
|
27
|
-
|
24
|
+
get spree.api_order_payments_path(order)
|
28
25
|
expect(json_response["payments"].first).to have_attributes(attributes)
|
29
26
|
end
|
30
27
|
|
31
28
|
it "can learn how to create a new payment" do
|
32
|
-
|
29
|
+
get spree.new_api_order_payment_path(order)
|
33
30
|
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
34
31
|
expect(json_response["payment_methods"]).not_to be_empty
|
35
32
|
expect(json_response["payment_methods"].first).to have_attributes([:id, :name, :description])
|
@@ -37,31 +34,20 @@ module Spree
|
|
37
34
|
|
38
35
|
context "payment source is not required" do
|
39
36
|
before do
|
40
|
-
allow_any_instance_of(Spree::
|
37
|
+
allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
|
41
38
|
end
|
42
39
|
|
43
40
|
it "can create a new payment" do
|
44
|
-
|
41
|
+
post spree.api_order_payments_path(order), params: { payment: { payment_method_id: PaymentMethod.first.id, amount: 50 } }
|
45
42
|
expect(response.status).to eq(201)
|
46
43
|
expect(json_response).to have_attributes(attributes)
|
47
44
|
end
|
48
|
-
|
49
|
-
context "disallowed payment method" do
|
50
|
-
it "does not create a new payment" do
|
51
|
-
PaymentMethod.first.update!(available_to_users: false)
|
52
|
-
|
53
|
-
expect {
|
54
|
-
api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
|
55
|
-
}.not_to change { Spree::Payment.count }
|
56
|
-
expect(response.status).to eq(404)
|
57
|
-
end
|
58
|
-
end
|
59
45
|
end
|
60
46
|
|
61
47
|
context "payment source is required" do
|
62
48
|
context "no source is provided" do
|
63
49
|
it "returns errors" do
|
64
|
-
|
50
|
+
post spree.api_order_payments_path(order), params: { payment: { payment_method_id: PaymentMethod.first.id, amount: 50 } }
|
65
51
|
expect(response.status).to eq(422)
|
66
52
|
expect(json_response['error']).to eq("Invalid resource. Please fix errors and try again.")
|
67
53
|
expect(json_response['errors']['source']).to eq(["can't be blank"])
|
@@ -70,7 +56,7 @@ module Spree
|
|
70
56
|
|
71
57
|
context "source is provided" do
|
72
58
|
it "can create a new payment" do
|
73
|
-
|
59
|
+
post spree.api_order_payments_path(order), params: { payment: { payment_method_id: PaymentMethod.first.id, amount: 50, source_attributes: { gateway_payment_profile_id: 1 } } }
|
74
60
|
expect(response.status).to eq(201)
|
75
61
|
expect(json_response).to have_attributes(attributes)
|
76
62
|
end
|
@@ -78,17 +64,17 @@ module Spree
|
|
78
64
|
end
|
79
65
|
|
80
66
|
it "can view a pre-existing payment's details" do
|
81
|
-
|
67
|
+
get spree.api_order_payment_path(order, payment)
|
82
68
|
expect(json_response).to have_attributes(attributes)
|
83
69
|
end
|
84
70
|
|
85
71
|
it "cannot update a payment" do
|
86
|
-
|
72
|
+
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
|
87
73
|
assert_unauthorized!
|
88
74
|
end
|
89
75
|
|
90
76
|
it "cannot authorize a payment" do
|
91
|
-
|
77
|
+
put spree.authorize_api_order_payment_path(order, payment)
|
92
78
|
assert_unauthorized!
|
93
79
|
end
|
94
80
|
end
|
@@ -99,12 +85,12 @@ module Spree
|
|
99
85
|
end
|
100
86
|
|
101
87
|
it "cannot view payments for somebody else's order" do
|
102
|
-
|
88
|
+
get spree.api_order_payments_path(order)
|
103
89
|
assert_unauthorized!
|
104
90
|
end
|
105
91
|
|
106
92
|
it "can view the payments for an order given the order token" do
|
107
|
-
|
93
|
+
get spree.api_order_payments_path(order), params: { order_token: order.guest_token }
|
108
94
|
expect(json_response["payments"].first).to have_attributes(attributes)
|
109
95
|
end
|
110
96
|
end
|
@@ -114,7 +100,7 @@ module Spree
|
|
114
100
|
sign_in_as_admin!
|
115
101
|
|
116
102
|
it "can view the payments on any order" do
|
117
|
-
|
103
|
+
get spree.api_order_payments_path(order)
|
118
104
|
expect(response.status).to eq(200)
|
119
105
|
expect(json_response["payments"].first).to have_attributes(attributes)
|
120
106
|
end
|
@@ -123,12 +109,12 @@ module Spree
|
|
123
109
|
before { @payment = create(:payment, order: order) }
|
124
110
|
|
125
111
|
it "can view all payments on an order" do
|
126
|
-
|
112
|
+
get spree.api_order_payments_path(order)
|
127
113
|
expect(json_response["count"]).to eq(2)
|
128
114
|
end
|
129
115
|
|
130
116
|
it 'can control the page size through a parameter' do
|
131
|
-
|
117
|
+
get spree.api_order_payments_path(order), params: { per_page: 1 }
|
132
118
|
expect(json_response['count']).to eq(1)
|
133
119
|
expect(json_response['current_page']).to eq(1)
|
134
120
|
expect(json_response['pages']).to eq(2)
|
@@ -139,7 +125,7 @@ module Spree
|
|
139
125
|
context "updating" do
|
140
126
|
it "can update" do
|
141
127
|
payment.update_attributes(state: 'pending')
|
142
|
-
|
128
|
+
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
|
143
129
|
expect(response.status).to eq(200)
|
144
130
|
expect(payment.reload.amount).to eq(2.01)
|
145
131
|
end
|
@@ -147,14 +133,14 @@ module Spree
|
|
147
133
|
context "update fails" do
|
148
134
|
it "returns a 422 status when the amount is invalid" do
|
149
135
|
payment.update_attributes(state: 'pending')
|
150
|
-
|
136
|
+
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 'invalid' } }
|
151
137
|
expect(response.status).to eq(422)
|
152
138
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
153
139
|
end
|
154
140
|
|
155
141
|
it "returns a 403 status when the payment is not pending" do
|
156
142
|
payment.update_attributes(state: 'completed')
|
157
|
-
|
143
|
+
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
|
158
144
|
expect(response.status).to eq(403)
|
159
145
|
expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
|
160
146
|
end
|
@@ -163,7 +149,7 @@ module Spree
|
|
163
149
|
|
164
150
|
context "authorizing" do
|
165
151
|
it "can authorize" do
|
166
|
-
|
152
|
+
put spree.authorize_api_order_payment_path(order, payment)
|
167
153
|
expect(response.status).to eq(200)
|
168
154
|
expect(payment.reload.state).to eq("pending")
|
169
155
|
end
|
@@ -171,8 +157,8 @@ module Spree
|
|
171
157
|
context "authorization fails" do
|
172
158
|
before do
|
173
159
|
fake_response = double(success?: false, to_s: "Could not authorize card")
|
174
|
-
expect_any_instance_of(Spree::
|
175
|
-
|
160
|
+
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:authorize).and_return(fake_response)
|
161
|
+
put spree.authorize_api_order_payment_path(order, payment)
|
176
162
|
end
|
177
163
|
|
178
164
|
it "returns a 422 status" do
|
@@ -190,7 +176,7 @@ module Spree
|
|
190
176
|
|
191
177
|
context "capturing" do
|
192
178
|
it "can capture" do
|
193
|
-
|
179
|
+
put spree.capture_api_order_payment_path(order, payment)
|
194
180
|
expect(response.status).to eq(200)
|
195
181
|
expect(payment.reload.state).to eq("completed")
|
196
182
|
end
|
@@ -198,11 +184,11 @@ module Spree
|
|
198
184
|
context "capturing fails" do
|
199
185
|
before do
|
200
186
|
fake_response = double(success?: false, to_s: "Insufficient funds")
|
201
|
-
expect_any_instance_of(Spree::
|
187
|
+
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:capture).and_return(fake_response)
|
202
188
|
end
|
203
189
|
|
204
190
|
it "returns a 422 status" do
|
205
|
-
|
191
|
+
put spree.capture_api_order_payment_path(order, payment)
|
206
192
|
expect(response.status).to eq(422)
|
207
193
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
208
194
|
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
|
@@ -212,7 +198,7 @@ module Spree
|
|
212
198
|
|
213
199
|
context "purchasing" do
|
214
200
|
it "can purchase" do
|
215
|
-
|
201
|
+
put spree.purchase_api_order_payment_path(order, payment)
|
216
202
|
expect(response.status).to eq(200)
|
217
203
|
expect(payment.reload.state).to eq("completed")
|
218
204
|
end
|
@@ -220,11 +206,11 @@ module Spree
|
|
220
206
|
context "purchasing fails" do
|
221
207
|
before do
|
222
208
|
fake_response = double(success?: false, to_s: "Insufficient funds")
|
223
|
-
expect_any_instance_of(Spree::
|
209
|
+
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:purchase).and_return(fake_response)
|
224
210
|
end
|
225
211
|
|
226
212
|
it "returns a 422 status" do
|
227
|
-
|
213
|
+
put spree.purchase_api_order_payment_path(order, payment)
|
228
214
|
expect(response.status).to eq(422)
|
229
215
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
230
216
|
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
|
@@ -234,7 +220,7 @@ module Spree
|
|
234
220
|
|
235
221
|
context "voiding" do
|
236
222
|
it "can void" do
|
237
|
-
|
223
|
+
put spree.void_api_order_payment_path(order, payment)
|
238
224
|
expect(response.status).to eq 200
|
239
225
|
expect(payment.reload.state).to eq "void"
|
240
226
|
end
|
@@ -242,11 +228,11 @@ module Spree
|
|
242
228
|
context "voiding fails" do
|
243
229
|
before do
|
244
230
|
fake_response = double(success?: false, to_s: "NO REFUNDS")
|
245
|
-
expect_any_instance_of(Spree::
|
231
|
+
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:void).and_return(fake_response)
|
246
232
|
end
|
247
233
|
|
248
234
|
it "returns a 422 status" do
|
249
|
-
|
235
|
+
put spree.void_api_order_payment_path(order, payment)
|
250
236
|
expect(response.status).to eq 422
|
251
237
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
252
238
|
expect(json_response["errors"]["base"][0]).to eq "NO REFUNDS"
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples/protect_product_actions'
|
3
3
|
|
4
4
|
module Spree
|
5
|
-
describe Spree::Api::ProductPropertiesController, type: :
|
6
|
-
render_views
|
5
|
+
describe Spree::Api::ProductPropertiesController, type: :request do
|
7
6
|
|
8
7
|
let!(:product) { create(:product) }
|
9
8
|
let!(:property_1) { product.product_properties.create(property_name: "My Property 1", value: "my value 1", position: 0) }
|
@@ -22,19 +21,19 @@ module Spree
|
|
22
21
|
end
|
23
22
|
|
24
23
|
it "can not see a list of product properties" do
|
25
|
-
|
24
|
+
get spree.api_product_product_properties_path(product)
|
26
25
|
expect(response.status).to eq(404)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
29
|
it "can see a list of all product properties" do
|
31
|
-
|
30
|
+
get spree.api_product_product_properties_path(product)
|
32
31
|
expect(json_response["product_properties"].count).to eq 2
|
33
32
|
expect(json_response["product_properties"].first).to have_attributes(attributes)
|
34
33
|
end
|
35
34
|
|
36
35
|
it "can control the page size through a parameter" do
|
37
|
-
|
36
|
+
get spree.api_product_product_properties_path(product), params: { per_page: 1 }
|
38
37
|
expect(json_response['product_properties'].count).to eq(1)
|
39
38
|
expect(json_response['current_page']).to eq(1)
|
40
39
|
expect(json_response['pages']).to eq(2)
|
@@ -43,34 +42,34 @@ module Spree
|
|
43
42
|
it 'can query the results through a parameter' do
|
44
43
|
Spree::ProductProperty.last.update_attribute(:value, 'loose')
|
45
44
|
property = Spree::ProductProperty.last
|
46
|
-
|
45
|
+
get spree.api_product_product_properties_path(product), params: { q: { value_cont: 'loose' } }
|
47
46
|
expect(json_response['count']).to eq(1)
|
48
47
|
expect(json_response['product_properties'].first['value']).to eq property.value
|
49
48
|
end
|
50
49
|
|
51
50
|
it "can see a single product_property" do
|
52
|
-
|
51
|
+
get spree.api_product_product_property_path(product, property_1.property_name)
|
53
52
|
expect(json_response).to have_attributes(attributes)
|
54
53
|
end
|
55
54
|
|
56
55
|
it "can learn how to create a new product property" do
|
57
|
-
|
56
|
+
get spree.new_api_product_product_property_path(product)
|
58
57
|
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
59
58
|
expect(json_response["required_attributes"]).to be_empty
|
60
59
|
end
|
61
60
|
|
62
61
|
it "cannot create a new product property if not an admin" do
|
63
|
-
|
62
|
+
post spree.api_product_product_properties_path(product), params: { product_property: { property_name: "My Property 3" } }
|
64
63
|
assert_unauthorized!
|
65
64
|
end
|
66
65
|
|
67
66
|
it "cannot update a product property" do
|
68
|
-
|
67
|
+
put spree.api_product_product_property_path(product, property_1.property_name), params: { product_property: { value: "my value 456" } }
|
69
68
|
assert_unauthorized!
|
70
69
|
end
|
71
70
|
|
72
71
|
it "cannot delete a product property" do
|
73
|
-
|
72
|
+
delete spree.api_product_product_property_path(product, property_1.property_name)
|
74
73
|
assert_unauthorized!
|
75
74
|
expect { property_1.reload }.not_to raise_error
|
76
75
|
end
|
@@ -80,34 +79,33 @@ module Spree
|
|
80
79
|
|
81
80
|
it "can create a new product property" do
|
82
81
|
expect do
|
83
|
-
|
82
|
+
post spree.api_product_product_properties_path(product), params: { product_property: { property_name: "My Property 3", value: "my value 3" } }
|
84
83
|
end.to change(product.product_properties, :count).by(1)
|
85
84
|
expect(json_response).to have_attributes(attributes)
|
86
85
|
expect(response.status).to eq(201)
|
87
86
|
end
|
88
87
|
|
89
88
|
it "can update a product property" do
|
90
|
-
|
89
|
+
put spree.api_product_product_property_path(product, property_1.property_name), params: { product_property: { value: "my value 456" } }
|
91
90
|
expect(response.status).to eq(200)
|
92
91
|
end
|
93
92
|
|
94
93
|
it "can delete a product property" do
|
95
|
-
|
94
|
+
delete spree.api_product_product_property_path(product, property_1.property_name)
|
96
95
|
expect(response.status).to eq(204)
|
97
96
|
expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
100
|
context "with product identified by id" do
|
102
|
-
let(:resource_scoping) { { product_id: product.id } }
|
103
101
|
it "can see a list of all product properties" do
|
104
|
-
|
102
|
+
get spree.api_product_product_properties_path(product)
|
105
103
|
expect(json_response["product_properties"].count).to eq 2
|
106
104
|
expect(json_response["product_properties"].first).to have_attributes(attributes)
|
107
105
|
end
|
108
106
|
|
109
107
|
it "can see a single product_property by id" do
|
110
|
-
|
108
|
+
get spree.api_product_product_property_path(product, property_1.id)
|
111
109
|
expect(json_response).to have_attributes(attributes)
|
112
110
|
end
|
113
111
|
end
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples/protect_product_actions'
|
3
3
|
|
4
4
|
module Spree
|
5
|
-
describe Spree::Api::ProductsController, type: :
|
6
|
-
render_views
|
5
|
+
describe Spree::Api::ProductsController, type: :request do
|
7
6
|
|
8
7
|
let!(:product) { create(:product) }
|
9
8
|
let!(:inactive_product) { create(:product, available_on: Time.current.tomorrow, name: "inactive") }
|
@@ -39,7 +38,7 @@ module Spree
|
|
39
38
|
end
|
40
39
|
|
41
40
|
it "returns unique products" do
|
42
|
-
|
41
|
+
get spree.api_products_path
|
43
42
|
product_ids = json_response["products"].map { |p| p["id"] }
|
44
43
|
expect(product_ids.uniq.count).to eq(product_ids.count)
|
45
44
|
end
|
@@ -50,7 +49,7 @@ module Spree
|
|
50
49
|
end
|
51
50
|
|
52
51
|
it "retrieves a list of products" do
|
53
|
-
|
52
|
+
get spree.api_products_path
|
54
53
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
55
54
|
expect(json_response["total_count"]).to eq(1)
|
56
55
|
expect(json_response["current_page"]).to eq(1)
|
@@ -59,7 +58,7 @@ module Spree
|
|
59
58
|
end
|
60
59
|
|
61
60
|
it "retrieves a list of products by id" do
|
62
|
-
|
61
|
+
get spree.api_products_path, params: { ids: [product.id] }
|
63
62
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
64
63
|
expect(json_response["total_count"]).to eq(1)
|
65
64
|
expect(json_response["current_page"]).to eq(1)
|
@@ -71,14 +70,14 @@ module Spree
|
|
71
70
|
before { product.master.prices.create currency: "EUR", amount: 22 }
|
72
71
|
|
73
72
|
it "returns distinct products only" do
|
74
|
-
|
73
|
+
get spree.api_products_path
|
75
74
|
expect(assigns(:products).map(&:id).uniq).to eq assigns(:products).map(&:id)
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
78
|
it "retrieves a list of products by ids string" do
|
80
79
|
second_product = create(:product)
|
81
|
-
|
80
|
+
get spree.api_products_path, params: { ids: [product.id, second_product.id].join(",") }
|
82
81
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
83
82
|
expect(json_response["products"][1]).to have_attributes(show_attributes)
|
84
83
|
expect(json_response["total_count"]).to eq(2)
|
@@ -88,19 +87,19 @@ module Spree
|
|
88
87
|
end
|
89
88
|
|
90
89
|
it "does not return inactive products when queried by ids" do
|
91
|
-
|
90
|
+
get spree.api_products_path, params: { ids: [inactive_product.id] }
|
92
91
|
expect(json_response["count"]).to eq(0)
|
93
92
|
end
|
94
93
|
|
95
94
|
it "does not list unavailable products" do
|
96
|
-
|
95
|
+
get spree.api_products_path
|
97
96
|
expect(json_response["products"].first["name"]).not_to eq("inactive")
|
98
97
|
end
|
99
98
|
|
100
99
|
context "pagination" do
|
101
100
|
it "can select the next page of products" do
|
102
101
|
create(:product)
|
103
|
-
|
102
|
+
get spree.api_products_path, params: { page: 2, per_page: 1 }
|
104
103
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
105
104
|
expect(json_response["total_count"]).to eq(2)
|
106
105
|
expect(json_response["current_page"]).to eq(2)
|
@@ -109,7 +108,7 @@ module Spree
|
|
109
108
|
|
110
109
|
it 'can control the page size through a parameter' do
|
111
110
|
create(:product)
|
112
|
-
|
111
|
+
get spree.api_products_path, params: { per_page: 1 }
|
113
112
|
expect(json_response['count']).to eq(1)
|
114
113
|
expect(json_response['total_count']).to eq(2)
|
115
114
|
expect(json_response['current_page']).to eq(1)
|
@@ -119,7 +118,7 @@ module Spree
|
|
119
118
|
|
120
119
|
it "can search for products" do
|
121
120
|
create(:product, name: "The best product in the world")
|
122
|
-
|
121
|
+
get spree.api_products_path, params: { q: { name_cont: "best" } }
|
123
122
|
expect(json_response["products"].first).to have_attributes(show_attributes)
|
124
123
|
expect(json_response["count"]).to eq(1)
|
125
124
|
end
|
@@ -131,7 +130,7 @@ module Spree
|
|
131
130
|
product.set_property("spree", "rocks")
|
132
131
|
product.taxons << create(:taxon)
|
133
132
|
|
134
|
-
|
133
|
+
get spree.api_product_path(product)
|
135
134
|
|
136
135
|
expect(json_response).to have_attributes(show_attributes)
|
137
136
|
expect(json_response['variants'].first).to have_attributes([:name,
|
@@ -161,7 +160,7 @@ module Spree
|
|
161
160
|
before { Config.track_inventory_levels = false }
|
162
161
|
|
163
162
|
it "still displays valid json with total_on_hand Float::INFINITY" do
|
164
|
-
|
163
|
+
get spree.api_product_path(product)
|
165
164
|
expect(response).to be_ok
|
166
165
|
expect(json_response[:total_on_hand]).to eq nil
|
167
166
|
end
|
@@ -177,27 +176,27 @@ module Spree
|
|
177
176
|
end
|
178
177
|
|
179
178
|
specify do
|
180
|
-
|
179
|
+
get spree.api_product_path(product)
|
181
180
|
expect(json_response["slug"]).to match(/and-1-ways/)
|
182
181
|
product.destroy
|
183
182
|
|
184
|
-
|
183
|
+
get spree.api_product_path(other_product)
|
185
184
|
expect(json_response["slug"]).to match(/droids/)
|
186
185
|
end
|
187
186
|
end
|
188
187
|
|
189
188
|
it "cannot see inactive products" do
|
190
|
-
|
189
|
+
get spree.api_product_path(inactive_product)
|
191
190
|
assert_not_found!
|
192
191
|
end
|
193
192
|
|
194
193
|
it "returns a 404 error when it cannot find a product" do
|
195
|
-
|
194
|
+
get spree.api_product_path("non-existant")
|
196
195
|
assert_not_found!
|
197
196
|
end
|
198
197
|
|
199
198
|
it "can learn how to create a new product" do
|
200
|
-
|
199
|
+
get spree.new_api_product_path
|
201
200
|
expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
|
202
201
|
required_attributes = json_response["required_attributes"]
|
203
202
|
expect(required_attributes).to include("name")
|
@@ -215,7 +214,7 @@ module Spree
|
|
215
214
|
sign_in_as_admin!
|
216
215
|
|
217
216
|
it "can see all products" do
|
218
|
-
|
217
|
+
get spree.api_products_path
|
219
218
|
expect(json_response["products"].count).to eq(2)
|
220
219
|
expect(json_response["count"]).to eq(2)
|
221
220
|
expect(json_response["current_page"]).to eq(1)
|
@@ -229,21 +228,23 @@ module Spree
|
|
229
228
|
end
|
230
229
|
|
231
230
|
it "does not include deleted products" do
|
232
|
-
|
231
|
+
get spree.api_products_path
|
233
232
|
expect(json_response["products"].count).to eq(2)
|
234
233
|
end
|
235
234
|
|
236
235
|
it "can include deleted products" do
|
237
|
-
|
236
|
+
get spree.api_products_path, params: { show_deleted: 1 }
|
238
237
|
expect(json_response["products"].count).to eq(3)
|
239
238
|
end
|
240
239
|
end
|
241
240
|
|
242
241
|
describe "creating a product" do
|
243
242
|
it "can create a new product" do
|
244
|
-
|
245
|
-
|
246
|
-
|
243
|
+
post spree.api_products_path, params: {
|
244
|
+
product: { name: "The Other Product",
|
245
|
+
price: 19.99,
|
246
|
+
shipping_category_id: create(:shipping_category).id }
|
247
|
+
}
|
247
248
|
expect(json_response).to have_attributes(base_attributes)
|
248
249
|
expect(response.status).to eq(201)
|
249
250
|
end
|
@@ -251,7 +252,7 @@ module Spree
|
|
251
252
|
it "creates with embedded variants" do
|
252
253
|
product_data[:variants] = [attributes_for_variant, attributes_for_variant]
|
253
254
|
|
254
|
-
|
255
|
+
post spree.api_products_path, params: { product: product_data }
|
255
256
|
expect(response.status).to eq 201
|
256
257
|
|
257
258
|
variants = json_response['variants']
|
@@ -268,7 +269,7 @@ module Spree
|
|
268
269
|
value: "cotton"
|
269
270
|
}]
|
270
271
|
|
271
|
-
|
272
|
+
post spree.api_products_path, params: { product: product_data }
|
272
273
|
|
273
274
|
expect(json_response['product_properties'][0]['property_name']).to eq('fabric')
|
274
275
|
expect(json_response['product_properties'][0]['value']).to eq('cotton')
|
@@ -277,7 +278,7 @@ module Spree
|
|
277
278
|
it "can create a new product with option_types" do
|
278
279
|
product_data[:option_types] = ['size', 'color']
|
279
280
|
|
280
|
-
|
281
|
+
post spree.api_products_path, params: { product: product_data }
|
281
282
|
expect(json_response['option_types'].count).to eq(2)
|
282
283
|
end
|
283
284
|
|
@@ -286,23 +287,23 @@ module Spree
|
|
286
287
|
price: 19.99,
|
287
288
|
shipping_category: "Free Ships" }
|
288
289
|
|
289
|
-
|
290
|
+
post spree.api_products_path, params: { product: hash }
|
290
291
|
expect(response.status).to eq 201
|
291
292
|
|
292
|
-
shipping_id = ShippingCategory.
|
293
|
+
shipping_id = ShippingCategory.find_by(name: "Free Ships").id
|
293
294
|
expect(json_response['shipping_category_id']).to eq shipping_id
|
294
295
|
end
|
295
296
|
|
296
297
|
it "puts the created product in the given taxon" do
|
297
298
|
product_data[:taxon_ids] = taxon_1.id.to_s
|
298
|
-
|
299
|
+
post spree.api_products_path, params: { product: product_data }
|
299
300
|
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
|
300
301
|
end
|
301
302
|
|
302
303
|
# Regression test for https://github.com/spree/spree/issues/4123
|
303
304
|
it "puts the created product in the given taxons" do
|
304
305
|
product_data[:taxon_ids] = [taxon_1.id, taxon_2.id].join(',')
|
305
|
-
|
306
|
+
post spree.api_products_path, params: { product: product_data }
|
306
307
|
expect(json_response["taxon_ids"]).to eq([taxon_1.id, taxon_2.id])
|
307
308
|
end
|
308
309
|
|
@@ -317,14 +318,14 @@ module Spree
|
|
317
318
|
end
|
318
319
|
|
319
320
|
it "can still create a product" do
|
320
|
-
|
321
|
+
post spree.api_products_path, params: { product: product_data, token: "fake" }
|
321
322
|
expect(json_response).to have_attributes(show_attributes)
|
322
323
|
expect(response.status).to eq(201)
|
323
324
|
end
|
324
325
|
end
|
325
326
|
|
326
327
|
it "cannot create a new product with invalid attributes" do
|
327
|
-
|
328
|
+
post spree.api_products_path, params: { product: { foo: :bar } }
|
328
329
|
expect(response.status).to eq(422)
|
329
330
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
330
331
|
errors = json_response["errors"]
|
@@ -334,17 +335,17 @@ module Spree
|
|
334
335
|
|
335
336
|
context 'updating a product' do
|
336
337
|
it "can update a product" do
|
337
|
-
|
338
|
+
put spree.api_product_path(product), params: { product: { name: "New and Improved Product!" } }
|
338
339
|
expect(response.status).to eq(200)
|
339
340
|
end
|
340
341
|
|
341
342
|
it "can create new option types on a product" do
|
342
|
-
|
343
|
+
put spree.api_product_path(product), params: { product: { option_types: ['shape', 'color'] } }
|
343
344
|
expect(json_response['option_types'].count).to eq(2)
|
344
345
|
end
|
345
346
|
|
346
347
|
it "can create new variants on a product" do
|
347
|
-
|
348
|
+
put spree.api_product_path(product), params: { product: { variants: [attributes_for_variant, attributes_for_variant.merge(sku: "ABC-#{Kernel.rand(9999)}")] } }
|
348
349
|
expect(response.status).to eq 200
|
349
350
|
expect(json_response['variants'].count).to eq(2) # 2 variants
|
350
351
|
|
@@ -361,7 +362,7 @@ module Spree
|
|
361
362
|
}
|
362
363
|
variant_id = product.variants.create!({ product: product }.merge(variant_hash)).id
|
363
364
|
|
364
|
-
|
365
|
+
put spree.api_product_path(product), params: { product: {
|
365
366
|
variants: [
|
366
367
|
variant_hash.merge(
|
367
368
|
id: variant_id.to_s,
|
@@ -369,7 +370,7 @@ module Spree
|
|
369
370
|
options: [{ name: "size", value: "large" }]
|
370
371
|
)
|
371
372
|
]
|
372
|
-
}
|
373
|
+
} }
|
373
374
|
|
374
375
|
expect(json_response['variants'].count).to eq(1)
|
375
376
|
variants = json_response['variants'].select { |v| !v['is_master'] }
|
@@ -379,7 +380,7 @@ module Spree
|
|
379
380
|
end
|
380
381
|
|
381
382
|
it "cannot update a product with an invalid attribute" do
|
382
|
-
|
383
|
+
put spree.api_product_path(product), params: { product: { name: "" } }
|
383
384
|
expect(response.status).to eq(422)
|
384
385
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
385
386
|
expect(json_response["errors"]["name"]).to eq(["can't be blank"])
|
@@ -387,20 +388,20 @@ module Spree
|
|
387
388
|
|
388
389
|
# Regression test for https://github.com/spree/spree/issues/4123
|
389
390
|
it "puts the created product in the given taxon" do
|
390
|
-
|
391
|
+
put spree.api_product_path(product), params: { product: { taxon_ids: taxon_1.id.to_s } }
|
391
392
|
expect(json_response["taxon_ids"]).to eq([taxon_1.id])
|
392
393
|
end
|
393
394
|
|
394
395
|
# Regression test for https://github.com/spree/spree/issues/4123
|
395
396
|
it "puts the created product in the given taxons" do
|
396
|
-
|
397
|
+
put spree.api_product_path(product), params: { product: { taxon_ids: [taxon_1.id, taxon_2.id].join(',') } }
|
397
398
|
expect(json_response["taxon_ids"]).to match_array([taxon_1.id, taxon_2.id])
|
398
399
|
end
|
399
400
|
end
|
400
401
|
|
401
402
|
it "can delete a product" do
|
402
403
|
expect(product.deleted_at).to be_nil
|
403
|
-
|
404
|
+
delete spree.api_product_path(product)
|
404
405
|
expect(response.status).to eq(204)
|
405
406
|
expect(product.reload.deleted_at).not_to be_nil
|
406
407
|
end
|