solidus_api 2.2.2 → 2.3.0.beta1
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.
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
@@ -2,8 +2,7 @@ require 'shared_examples/protect_product_actions'
|
|
2
2
|
require 'spec_helper'
|
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(:attributes) { [:id, :name, :description, :price, :available_on, :slug, :meta_description, :meta_keywords, :taxon_ids] }
|
@@ -12,7 +11,7 @@ module Spree
|
|
12
11
|
before { Spree::Api::Config[:requires_authentication] = false }
|
13
12
|
|
14
13
|
it "retrieves a list of products" do
|
15
|
-
|
14
|
+
get spree.api_products_path
|
16
15
|
expect(json_response["products"].first).to have_attributes(attributes)
|
17
16
|
expect(json_response["count"]).to eq(1)
|
18
17
|
expect(json_response["current_page"]).to eq(1)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::UsersController, type: :
|
5
|
-
render_views
|
4
|
+
describe Api::UsersController, type: :request do
|
6
5
|
|
7
6
|
let(:user) { create(:user, spree_api_key: SecureRandom.hex) }
|
8
7
|
let(:stranger) { create(:user, email: 'stranger@example.com') }
|
@@ -10,19 +9,19 @@ module Spree
|
|
10
9
|
|
11
10
|
context "as a normal user" do
|
12
11
|
it "can get own details" do
|
13
|
-
|
12
|
+
get spree.api_user_path(user.id), params: { token: user.spree_api_key }
|
14
13
|
|
15
14
|
expect(json_response['email']).to eq user.email
|
16
15
|
end
|
17
16
|
|
18
17
|
it "cannot get other users details" do
|
19
|
-
|
18
|
+
get spree.api_user_path(stranger.id), params: { token: user.spree_api_key }
|
20
19
|
|
21
20
|
assert_not_found!
|
22
21
|
end
|
23
22
|
|
24
23
|
it "can learn how to create a new user" do
|
25
|
-
|
24
|
+
get spree.new_api_user_path, params: { token: user.spree_api_key }
|
26
25
|
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
27
26
|
end
|
28
27
|
|
@@ -31,20 +30,20 @@ module Spree
|
|
31
30
|
email: 'new@example.com', password: 'spree123', password_confirmation: 'spree123'
|
32
31
|
}
|
33
32
|
|
34
|
-
|
33
|
+
post spree.api_users_path, params: { user: user_params, token: user.spree_api_key }
|
35
34
|
expect(json_response['email']).to eq 'new@example.com'
|
36
35
|
end
|
37
36
|
|
38
37
|
# there's no validations on LegacyUser?
|
39
38
|
xit "cannot create a new user with invalid attributes" do
|
40
|
-
|
39
|
+
post spree.api_users_path, params: { user: {}, token: user.spree_api_key }
|
41
40
|
expect(response.status).to eq(422)
|
42
41
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
43
42
|
end
|
44
43
|
|
45
44
|
it "can update own details" do
|
46
45
|
country = create(:country)
|
47
|
-
|
46
|
+
put spree.api_user_path(user.id), params: { token: user.spree_api_key, user: {
|
48
47
|
email: "mine@example.com",
|
49
48
|
bill_address_attributes: {
|
50
49
|
first_name: 'First',
|
@@ -66,30 +65,30 @@ module Spree
|
|
66
65
|
zipcode: '55555',
|
67
66
|
phone: '5555555555'
|
68
67
|
}
|
69
|
-
}
|
68
|
+
} }
|
70
69
|
expect(json_response['email']).to eq 'mine@example.com'
|
71
70
|
expect(json_response['bill_address']).to_not be_nil
|
72
71
|
expect(json_response['ship_address']).to_not be_nil
|
73
72
|
end
|
74
73
|
|
75
74
|
it "cannot update other users details" do
|
76
|
-
|
75
|
+
put spree.api_user_path(stranger.id), params: { token: user.spree_api_key, user: { email: "mine@example.com" } }
|
77
76
|
assert_not_found!
|
78
77
|
end
|
79
78
|
|
80
79
|
it "cannot delete itself" do
|
81
|
-
|
80
|
+
delete spree.api_user_path(user.id), params: { token: user.spree_api_key }
|
82
81
|
expect(response.status).to eq(401)
|
83
82
|
end
|
84
83
|
|
85
84
|
it "cannot delete other user" do
|
86
|
-
|
85
|
+
delete spree.api_user_path(stranger.id), params: { token: user.spree_api_key }
|
87
86
|
assert_not_found!
|
88
87
|
end
|
89
88
|
|
90
89
|
it "should only get own details on index" do
|
91
90
|
2.times { create(:user) }
|
92
|
-
|
91
|
+
get spree.api_users_path, params: { token: user.spree_api_key }
|
93
92
|
|
94
93
|
expect(Spree.user_class.count).to eq 3
|
95
94
|
expect(json_response['count']).to eq 1
|
@@ -107,7 +106,7 @@ module Spree
|
|
107
106
|
|
108
107
|
2.times { create(:user) }
|
109
108
|
|
110
|
-
|
109
|
+
get spree.api_users_path
|
111
110
|
expect(Spree.user_class.count).to eq 2
|
112
111
|
expect(json_response['count']).to eq 2
|
113
112
|
expect(json_response['users'].size).to eq 2
|
@@ -115,7 +114,7 @@ module Spree
|
|
115
114
|
|
116
115
|
it 'can control the page size through a parameter' do
|
117
116
|
2.times { create(:user) }
|
118
|
-
|
117
|
+
get spree.api_users_path, params: { per_page: 1 }
|
119
118
|
expect(json_response['count']).to eq(1)
|
120
119
|
expect(json_response['current_page']).to eq(1)
|
121
120
|
expect(json_response['pages']).to eq(2)
|
@@ -123,26 +122,26 @@ module Spree
|
|
123
122
|
|
124
123
|
it 'can query the results through a paramter' do
|
125
124
|
expected_result = create(:user, email: 'brian@spreecommerce.com')
|
126
|
-
|
125
|
+
get spree.api_users_path, params: { q: { email_cont: 'brian' } }
|
127
126
|
expect(json_response['count']).to eq(1)
|
128
127
|
expect(json_response['users'].first['email']).to eq expected_result.email
|
129
128
|
end
|
130
129
|
|
131
130
|
it "can create" do
|
132
|
-
|
131
|
+
post spree.api_users_path, params: { user: { email: "new@example.com", password: 'spree123', password_confirmation: 'spree123' } }
|
133
132
|
expect(json_response).to have_attributes(attributes)
|
134
133
|
expect(response.status).to eq(201)
|
135
134
|
end
|
136
135
|
|
137
136
|
it "can destroy user without orders" do
|
138
137
|
user.orders.destroy_all
|
139
|
-
|
138
|
+
delete spree.api_user_path(user)
|
140
139
|
expect(response.status).to eq(204)
|
141
140
|
end
|
142
141
|
|
143
142
|
it "cannot destroy user with orders" do
|
144
143
|
create(:completed_order_with_totals, user: user)
|
145
|
-
|
144
|
+
delete spree.api_user_path(user)
|
146
145
|
expect(json_response["exception"]).to eq "Spree::Core::DestroyWithOrdersError"
|
147
146
|
expect(response.status).to eq(422)
|
148
147
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::VariantsController, type: :
|
5
|
-
render_views
|
4
|
+
describe Api::VariantsController, type: :request do
|
6
5
|
|
7
6
|
let!(:product) { create(:product) }
|
8
7
|
let!(:variant) do
|
@@ -21,7 +20,7 @@ module Spree
|
|
21
20
|
|
22
21
|
describe "#index" do
|
23
22
|
it "can see a paginated list of variants" do
|
24
|
-
|
23
|
+
get spree.api_variants_path
|
25
24
|
first_variant = json_response["variants"].first
|
26
25
|
expect(first_variant).to have_attributes(show_attributes)
|
27
26
|
expect(first_variant["stock_items"]).to be_present
|
@@ -32,7 +31,7 @@ module Spree
|
|
32
31
|
|
33
32
|
it 'can control the page size through a parameter' do
|
34
33
|
create(:variant)
|
35
|
-
|
34
|
+
get spree.api_variants_path, params: { per_page: 1 }
|
36
35
|
expect(json_response['count']).to eq(1)
|
37
36
|
expect(json_response['current_page']).to eq(1)
|
38
37
|
expect(json_response['pages']).to eq(3)
|
@@ -40,13 +39,13 @@ module Spree
|
|
40
39
|
|
41
40
|
it 'can query the results through a paramter' do
|
42
41
|
expected_result = create(:variant, sku: 'FOOBAR')
|
43
|
-
|
42
|
+
get spree.api_variants_path, params: { q: { sku_cont: 'FOO' } }
|
44
43
|
expect(json_response['count']).to eq(1)
|
45
44
|
expect(json_response['variants'].first['sku']).to eq expected_result.sku
|
46
45
|
end
|
47
46
|
|
48
47
|
it "variants returned contain option values data" do
|
49
|
-
|
48
|
+
get spree.api_variants_path
|
50
49
|
option_values = json_response["variants"].last["option_values"]
|
51
50
|
expect(option_values.first).to have_attributes([:name,
|
52
51
|
:presentation,
|
@@ -57,7 +56,7 @@ module Spree
|
|
57
56
|
it "variants returned contain images data" do
|
58
57
|
variant.images.create!(attachment: image("thinking-cat.jpg"))
|
59
58
|
|
60
|
-
|
59
|
+
get spree.api_variants_path
|
61
60
|
|
62
61
|
expect(json_response["variants"].last).to have_attributes([:images])
|
63
62
|
expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
|
@@ -77,38 +76,67 @@ module Spree
|
|
77
76
|
end
|
78
77
|
|
79
78
|
it "is not returned in the results" do
|
80
|
-
|
79
|
+
get spree.api_variants_path
|
81
80
|
expect(json_response["variants"].count).to eq(0)
|
82
81
|
end
|
83
82
|
|
84
83
|
it "is not returned even when show_deleted is passed" do
|
85
|
-
|
84
|
+
get spree.api_variants_path, params: { show_deleted: true }
|
86
85
|
expect(json_response["variants"].count).to eq(0)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
context "stock filtering" do
|
91
|
-
subject { api_get :index, in_stock_only: true }
|
92
90
|
|
93
|
-
context "
|
94
|
-
|
95
|
-
|
91
|
+
context "only variants in stock" do
|
92
|
+
subject { get spree.api_variants_path, params: { in_stock_only: "true" } }
|
93
|
+
|
94
|
+
context "variant is out of stock" do
|
95
|
+
before do
|
96
|
+
variant.stock_items.update_all(count_on_hand: 0)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is not returned in the results" do
|
100
|
+
subject
|
101
|
+
expect(json_response["variants"].count).to eq 0
|
102
|
+
end
|
96
103
|
end
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
105
|
+
context "variant is in stock" do
|
106
|
+
before do
|
107
|
+
variant.stock_items.update_all(count_on_hand: 10)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "is returned in the results" do
|
111
|
+
subject
|
112
|
+
expect(json_response["variants"].count).to eq 1
|
113
|
+
end
|
101
114
|
end
|
102
115
|
end
|
103
116
|
|
104
|
-
context "
|
105
|
-
|
106
|
-
|
117
|
+
context "all variants" do
|
118
|
+
subject { get spree.api_variants_path, params: { in_stock_only: "false" } }
|
119
|
+
|
120
|
+
context "variant is out of stock" do
|
121
|
+
before do
|
122
|
+
variant.stock_items.update_all(count_on_hand: 0)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "is returned in the results" do
|
126
|
+
subject
|
127
|
+
expect(json_response["variants"].count).to eq 1
|
128
|
+
end
|
107
129
|
end
|
108
130
|
|
109
|
-
|
110
|
-
|
111
|
-
|
131
|
+
context "variant is in stock" do
|
132
|
+
before do
|
133
|
+
variant.stock_items.update_all(count_on_hand: 10)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "is returned in the results" do
|
137
|
+
subject
|
138
|
+
expect(json_response["variants"].count).to eq 1
|
139
|
+
end
|
112
140
|
end
|
113
141
|
end
|
114
142
|
end
|
@@ -116,7 +144,7 @@ module Spree
|
|
116
144
|
context "pagination" do
|
117
145
|
it "can select the next page of variants" do
|
118
146
|
create(:variant)
|
119
|
-
|
147
|
+
get spree.api_variants_path, params: { page: 2, per_page: 1 }
|
120
148
|
expect(json_response["variants"].first).to have_attributes(show_attributes)
|
121
149
|
expect(json_response["total_count"]).to eq(3)
|
122
150
|
expect(json_response["current_page"]).to eq(2)
|
@@ -129,7 +157,7 @@ module Spree
|
|
129
157
|
let!(:inactive_stock_location) { create(:stock_location, propagate_all_variants: true, name: "My special stock location", active: false) }
|
130
158
|
|
131
159
|
it "only returns stock items for active stock locations" do
|
132
|
-
|
160
|
+
get spree.api_variants_path
|
133
161
|
variant = json_response['variants'].first
|
134
162
|
stock_items = variant['stock_items'].map { |si| si['stock_location_name'] }
|
135
163
|
|
@@ -140,7 +168,9 @@ module Spree
|
|
140
168
|
end
|
141
169
|
|
142
170
|
describe "#show" do
|
143
|
-
subject
|
171
|
+
subject do
|
172
|
+
get spree.api_variant_path(variant)
|
173
|
+
end
|
144
174
|
|
145
175
|
it "can see a single variant" do
|
146
176
|
subject
|
@@ -195,30 +225,29 @@ module Spree
|
|
195
225
|
end
|
196
226
|
|
197
227
|
it "can learn how to create a new variant" do
|
198
|
-
|
228
|
+
get spree.new_api_variant_path(variant)
|
199
229
|
expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
|
200
230
|
expect(json_response["required_attributes"]).to be_empty
|
201
231
|
end
|
202
232
|
|
203
233
|
it "cannot create a new variant if not an admin" do
|
204
|
-
|
234
|
+
post spree.api_variants_path, params: { variant: { sku: "12345" } }
|
205
235
|
assert_unauthorized!
|
206
236
|
end
|
207
237
|
|
208
238
|
it "cannot update a variant" do
|
209
|
-
|
239
|
+
put spree.api_variant_path(variant), params: { variant: { sku: "12345" } }
|
210
240
|
assert_not_found!
|
211
241
|
end
|
212
242
|
|
213
243
|
it "cannot delete a variant" do
|
214
|
-
|
244
|
+
delete spree.api_variant_path(variant)
|
215
245
|
assert_not_found!
|
216
246
|
expect { variant.reload }.not_to raise_error
|
217
247
|
end
|
218
248
|
|
219
249
|
context "as an admin" do
|
220
250
|
sign_in_as_admin!
|
221
|
-
let(:resource_scoping) { { product_id: variant.product.to_param } }
|
222
251
|
|
223
252
|
# Test for https://github.com/spree/spree/issues/2141
|
224
253
|
context "deleted variants" do
|
@@ -227,13 +256,13 @@ module Spree
|
|
227
256
|
end
|
228
257
|
|
229
258
|
it "are visible by admin" do
|
230
|
-
|
259
|
+
get spree.api_variants_path, params: { show_deleted: 1 }
|
231
260
|
expect(json_response["variants"].count).to eq(1)
|
232
261
|
end
|
233
262
|
end
|
234
263
|
|
235
264
|
it "can create a new variant" do
|
236
|
-
|
265
|
+
post spree.api_product_variants_path(product), params: { variant: { sku: "12345" } }
|
237
266
|
expect(json_response).to have_attributes(new_attributes)
|
238
267
|
expect(response.status).to eq(201)
|
239
268
|
expect(json_response["sku"]).to eq("12345")
|
@@ -244,24 +273,28 @@ module Spree
|
|
244
273
|
it "creates new variants with nested option values" do
|
245
274
|
option_values = create_list(:option_value, 2)
|
246
275
|
expect do
|
247
|
-
|
248
|
-
|
276
|
+
post spree.api_product_variants_path(product), params: {
|
277
|
+
variant: {
|
278
|
+
sku: "12345",
|
279
|
+
option_value_ids: option_values.map(&:id)
|
280
|
+
}
|
281
|
+
}
|
249
282
|
end.to change { Spree::OptionValuesVariant.count }.by(2)
|
250
283
|
end
|
251
284
|
|
252
285
|
it "can update a variant" do
|
253
|
-
|
286
|
+
put spree.api_variant_path(variant), params: { variant: { sku: "12345" } }
|
254
287
|
expect(response.status).to eq(200)
|
255
288
|
end
|
256
289
|
|
257
290
|
it "can delete a variant" do
|
258
|
-
|
291
|
+
delete spree.api_variant_path(variant)
|
259
292
|
expect(response.status).to eq(204)
|
260
293
|
expect { Spree::Variant.find(variant.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
261
294
|
end
|
262
295
|
|
263
296
|
it 'variants returned contain cost price data' do
|
264
|
-
|
297
|
+
get spree.api_variants_path
|
265
298
|
expect(json_response["variants"].first.key?(:cost_price)).to eq true
|
266
299
|
end
|
267
300
|
end
|
@@ -1,24 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ZonesController, type: :
|
5
|
-
render_views
|
4
|
+
describe Api::ZonesController, type: :request do
|
6
5
|
|
7
6
|
let!(:attributes) { [:id, :name, :zone_members] }
|
7
|
+
let!(:zone) { create(:zone, name: 'Europe') }
|
8
8
|
|
9
9
|
before do
|
10
10
|
stub_authentication!
|
11
|
-
@zone = create(:zone, name: 'Europe')
|
12
11
|
end
|
13
12
|
|
14
13
|
it "gets list of zones" do
|
15
|
-
|
14
|
+
get spree.api_zones_path
|
16
15
|
expect(json_response['zones'].first).to have_attributes(attributes)
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'can control the page size through a parameter' do
|
20
19
|
create(:zone)
|
21
|
-
|
20
|
+
get spree.api_zones_path, params: { per_page: 1 }
|
22
21
|
expect(json_response['count']).to eq(1)
|
23
22
|
expect(json_response['current_page']).to eq(1)
|
24
23
|
expect(json_response['pages']).to eq(2)
|
@@ -26,16 +25,16 @@ module Spree
|
|
26
25
|
|
27
26
|
it 'can query the results through a paramter' do
|
28
27
|
expected_result = create(:zone, name: 'South America')
|
29
|
-
|
28
|
+
get spree.api_zones_path, params: { q: { name_cont: 'south' } }
|
30
29
|
expect(json_response['count']).to eq(1)
|
31
30
|
expect(json_response['zones'].first['name']).to eq expected_result.name
|
32
31
|
end
|
33
32
|
|
34
33
|
it "gets a zone" do
|
35
|
-
|
34
|
+
get spree.api_zone_path(zone)
|
36
35
|
expect(json_response).to have_attributes(attributes)
|
37
|
-
expect(json_response['name']).to eq
|
38
|
-
expect(json_response['zone_members'].size).to eq
|
36
|
+
expect(json_response['name']).to eq zone.name
|
37
|
+
expect(json_response['zone_members'].size).to eq zone.zone_members.count
|
39
38
|
end
|
40
39
|
|
41
40
|
context "as an admin" do
|
@@ -54,14 +53,14 @@ module Spree
|
|
54
53
|
}
|
55
54
|
}
|
56
55
|
|
57
|
-
|
56
|
+
post spree.api_zones_path, params: params
|
58
57
|
expect(response.status).to eq(201)
|
59
58
|
expect(json_response).to have_attributes(attributes)
|
60
59
|
expect(json_response["zone_members"]).not_to be_empty
|
61
60
|
end
|
62
61
|
|
63
62
|
it "updates a zone" do
|
64
|
-
params = {
|
63
|
+
params = {
|
65
64
|
zone: {
|
66
65
|
name: "North Pole",
|
67
66
|
zone_members: [
|
@@ -73,16 +72,16 @@ module Spree
|
|
73
72
|
}
|
74
73
|
}
|
75
74
|
|
76
|
-
|
75
|
+
put spree.api_zone_path(zone), params: params
|
77
76
|
expect(response.status).to eq(200)
|
78
77
|
expect(json_response['name']).to eq 'North Pole'
|
79
78
|
expect(json_response['zone_members']).not_to be_blank
|
80
79
|
end
|
81
80
|
|
82
81
|
it "can delete a zone" do
|
83
|
-
|
82
|
+
delete spree.api_zone_path(zone)
|
84
83
|
expect(response.status).to eq(204)
|
85
|
-
expect {
|
84
|
+
expect { zone.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|