solidus_api 2.10.5 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::ClassificationsController, type: :request do
|
7
|
-
let(:taxon) do
|
8
|
-
taxon = create(:taxon)
|
9
|
-
|
10
|
-
3.times do
|
11
|
-
product = create(:product)
|
12
|
-
product.taxons << taxon
|
13
|
-
end
|
14
|
-
taxon
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
stub_authentication!
|
19
|
-
end
|
20
|
-
|
21
|
-
context "as a user" do
|
22
|
-
it "cannot change the order of a product" do
|
23
|
-
put spree.api_classifications_path, params: { taxon_id: taxon, product_id: taxon.products.first, position: 1 }
|
24
|
-
expect(response.status).to eq(401)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "as an admin" do
|
29
|
-
sign_in_as_admin!
|
30
|
-
|
31
|
-
let(:last_product) { taxon.products.last }
|
32
|
-
|
33
|
-
it "can change the order a product" do
|
34
|
-
classification = taxon.classifications.find_by(product_id: last_product.id)
|
35
|
-
expect(classification.position).to eq(3)
|
36
|
-
put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
|
37
|
-
expect(response.status).to eq(200)
|
38
|
-
expect(classification.reload.position).to eq(1)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should touch the taxon" do
|
42
|
-
taxon.update(updated_at: Time.current - 10.seconds)
|
43
|
-
taxon_last_updated_at = taxon.updated_at
|
44
|
-
put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
|
45
|
-
taxon.reload
|
46
|
-
expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::ConfigController, type: :request do
|
7
|
-
let!(:default_country) { create :country, iso: "US" }
|
8
|
-
|
9
|
-
before do
|
10
|
-
stub_authentication!
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns Spree::Money settings" do
|
14
|
-
get '/api/config/money'
|
15
|
-
expect(response).to be_successful
|
16
|
-
expect(json_response["symbol"]).to eq("$")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns some configuration settings" do
|
20
|
-
get '/api/config'
|
21
|
-
expect(response).to be_successful
|
22
|
-
expect(json_response["default_country_iso"]).to eq("US")
|
23
|
-
expect(json_response["default_country_id"]).to eq(default_country.id)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::CountriesController, type: :request do
|
7
|
-
before do
|
8
|
-
stub_authentication!
|
9
|
-
@state = create(:state)
|
10
|
-
@country = @state.country
|
11
|
-
end
|
12
|
-
|
13
|
-
it "gets all countries" do
|
14
|
-
get spree.api_countries_path
|
15
|
-
expect(json_response['countries'].first['iso3']).to eq @country.iso3
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with two countries" do
|
19
|
-
before { @zambia = create(:country, name: "Zambia") }
|
20
|
-
|
21
|
-
it "can view all countries" do
|
22
|
-
get spree.api_countries_path
|
23
|
-
expect(json_response['count']).to eq(2)
|
24
|
-
expect(json_response['current_page']).to eq(1)
|
25
|
-
expect(json_response['pages']).to eq(1)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'can query the results through a paramter' do
|
29
|
-
get spree.api_countries_path, params: { q: { name_cont: 'zam' } }
|
30
|
-
expect(json_response['count']).to eq(1)
|
31
|
-
expect(json_response['countries'].first['name']).to eq @zambia.name
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'can control the page size through a parameter' do
|
35
|
-
get spree.api_countries_path, params: { per_page: 1 }
|
36
|
-
expect(json_response['count']).to eq(1)
|
37
|
-
expect(json_response['current_page']).to eq(1)
|
38
|
-
expect(json_response['pages']).to eq(2)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "includes states" do
|
43
|
-
get spree.api_country_path(@country.id)
|
44
|
-
states = json_response['states']
|
45
|
-
expect(states.first['name']).to eq @state.name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::CouponCodesController, type: :request do
|
7
|
-
let(:current_api_user) do
|
8
|
-
user = Spree.user_class.new(email: "spree@example.com")
|
9
|
-
user.generate_spree_api_key!
|
10
|
-
user
|
11
|
-
end
|
12
|
-
|
13
|
-
before do
|
14
|
-
stub_authentication!
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#create' do
|
18
|
-
let(:promo) { create(:promotion_with_item_adjustment, code: 'night_melody') }
|
19
|
-
let(:promo_code) { promo.codes.first }
|
20
|
-
|
21
|
-
before do
|
22
|
-
allow_any_instance_of(Order).to receive_messages user: current_api_user
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when successful' do
|
26
|
-
let(:order) { create(:order_with_line_items) }
|
27
|
-
|
28
|
-
it 'applies the coupon' do
|
29
|
-
post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
|
30
|
-
|
31
|
-
expect(response.status).to eq(200)
|
32
|
-
expect(order.reload.promotions).to eq([promo])
|
33
|
-
expect(json_response).to eq({
|
34
|
-
"success" => I18n.t('spree.coupon_code_applied'),
|
35
|
-
"error" => nil,
|
36
|
-
"successful" => true,
|
37
|
-
"status_code" => "coupon_code_applied"
|
38
|
-
})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when unsuccessful' do
|
43
|
-
let(:order) { create(:order) }
|
44
|
-
|
45
|
-
it 'returns an error' do
|
46
|
-
post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
|
47
|
-
|
48
|
-
expect(response.status).to eq(422)
|
49
|
-
expect(order.reload.promotions).to eq([])
|
50
|
-
expect(json_response).to eq({
|
51
|
-
"success" => nil,
|
52
|
-
"error" => I18n.t('spree.coupon_code_unknown_error'),
|
53
|
-
"successful" => false,
|
54
|
-
"status_code" => "coupon_code_unknown_error"
|
55
|
-
})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#destroy' do
|
61
|
-
let(:promo) {
|
62
|
-
create(:promotion_with_item_adjustment,
|
63
|
-
code: 'tenoff',
|
64
|
-
per_code_usage_limit: 5,
|
65
|
-
adjustment_rate: 10)
|
66
|
-
}
|
67
|
-
|
68
|
-
let(:promo_code) { promo.codes.first }
|
69
|
-
let(:order) { create(:order_with_line_items, user: current_api_user) }
|
70
|
-
|
71
|
-
before do
|
72
|
-
post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
|
73
|
-
delete spree.api_order_coupon_code_path(order, promo_code.value)
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when successful' do
|
77
|
-
it 'removes the coupon' do
|
78
|
-
expect(response.status).to eq(200)
|
79
|
-
expect(order.reload.promotions).to eq([])
|
80
|
-
expect(json_response).to eq({
|
81
|
-
"success" => I18n.t('spree.coupon_code_removed'),
|
82
|
-
"error" => nil,
|
83
|
-
"successful" => true,
|
84
|
-
"status_code" => "coupon_code_removed"
|
85
|
-
})
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when unsuccessful' do
|
90
|
-
it 'returns an error' do
|
91
|
-
delete spree.api_order_coupon_code_path(order, promo_code.value)
|
92
|
-
|
93
|
-
expect(response.status).to eq(422)
|
94
|
-
expect(order.reload.promotions).to eq([])
|
95
|
-
expect(json_response).to eq({
|
96
|
-
"success" => nil,
|
97
|
-
"error" => I18n.t('spree.coupon_code_not_present'),
|
98
|
-
"successful" => false,
|
99
|
-
"status_code" => "coupon_code_not_present"
|
100
|
-
})
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::CreditCardsController, type: :request do
|
7
|
-
describe '#index' do
|
8
|
-
let!(:admin_user) do
|
9
|
-
create(:admin_user)
|
10
|
-
end
|
11
|
-
|
12
|
-
let!(:normal_user) do
|
13
|
-
create(:user, :with_api_key)
|
14
|
-
end
|
15
|
-
|
16
|
-
let!(:card) { create(:credit_card, user_id: admin_user.id, gateway_customer_profile_id: "random") }
|
17
|
-
|
18
|
-
before do
|
19
|
-
stub_authentication!
|
20
|
-
end
|
21
|
-
|
22
|
-
it "the user id doesn't exist" do
|
23
|
-
get spree.api_user_credit_cards_path(1000)
|
24
|
-
expect(response.status).to eq(404)
|
25
|
-
end
|
26
|
-
|
27
|
-
context "calling user is in admin role" do
|
28
|
-
let(:current_api_user) do
|
29
|
-
admin_user
|
30
|
-
end
|
31
|
-
|
32
|
-
it "no credit cards exist for user" do
|
33
|
-
get spree.api_user_credit_cards_path(normal_user)
|
34
|
-
|
35
|
-
expect(response.status).to eq(200)
|
36
|
-
expect(json_response["pages"]).to eq(0)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can view all credit cards for user" do
|
40
|
-
get spree.api_user_credit_cards_path(current_api_user.id)
|
41
|
-
|
42
|
-
expect(response.status).to eq(200)
|
43
|
-
expect(json_response["pages"]).to eq(1)
|
44
|
-
expect(json_response["current_page"]).to eq(1)
|
45
|
-
expect(json_response["credit_cards"].length).to eq(1)
|
46
|
-
expect(json_response["credit_cards"].first["id"]).to eq(card.id)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "calling user is not in admin role" do
|
51
|
-
let(:current_api_user) do
|
52
|
-
normal_user
|
53
|
-
end
|
54
|
-
|
55
|
-
let!(:card) { create(:credit_card, user_id: normal_user.id, gateway_customer_profile_id: "random") }
|
56
|
-
|
57
|
-
it "can not view user" do
|
58
|
-
get spree.api_user_credit_cards_path(admin_user.id)
|
59
|
-
|
60
|
-
expect(response.status).to eq(404)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "can view own credit cards" do
|
64
|
-
get spree.api_user_credit_cards_path(normal_user.id)
|
65
|
-
|
66
|
-
expect(response.status).to eq(200)
|
67
|
-
expect(json_response["pages"]).to eq(1)
|
68
|
-
expect(json_response["current_page"]).to eq(1)
|
69
|
-
expect(json_response["credit_cards"].length).to eq(1)
|
70
|
-
expect(json_response["credit_cards"].first["id"]).to eq(card.id)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#update' do
|
76
|
-
let(:credit_card) { create(:credit_card, name: 'Joe Shmoe', user: credit_card_user) }
|
77
|
-
let(:credit_card_user) { create(:user) }
|
78
|
-
|
79
|
-
before do
|
80
|
-
stub_authentication!
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'when the user is authorized' do
|
84
|
-
let(:current_api_user) { credit_card_user }
|
85
|
-
|
86
|
-
it 'updates the credit card' do
|
87
|
-
expect {
|
88
|
-
put spree.api_credit_card_path(credit_card.to_param), params: { credit_card: { name: 'Jordan Brough' } }
|
89
|
-
}.to change {
|
90
|
-
credit_card.reload.name
|
91
|
-
}.from('Joe Shmoe').to('Jordan Brough')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'when the user is not authorized' do
|
96
|
-
let(:current_api_user) { create(:user) }
|
97
|
-
|
98
|
-
it 'rejects the request' do
|
99
|
-
put spree.api_credit_card_path(credit_card.to_param), params: { credit_card: { name: 'Jordan Brough' } }
|
100
|
-
expect(response.status).to eq(401)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Spree::Api::ImagesController, type: :request do
|
7
|
-
let!(:product) { create(:product) }
|
8
|
-
let!(:attributes) {
|
9
|
-
[:id, :position, :attachment_content_type,
|
10
|
-
:attachment_file_name, :type, :attachment_updated_at, :attachment_width,
|
11
|
-
:attachment_height, :alt]
|
12
|
-
}
|
13
|
-
|
14
|
-
before do
|
15
|
-
stub_authentication!
|
16
|
-
end
|
17
|
-
|
18
|
-
context "as an admin" do
|
19
|
-
sign_in_as_admin!
|
20
|
-
|
21
|
-
it "can upload a new image for a variant" do
|
22
|
-
expect do
|
23
|
-
post spree.api_product_images_path(product.id), params: {
|
24
|
-
image: {
|
25
|
-
attachment: upload_image('thinking-cat.jpg'),
|
26
|
-
viewable_type: 'Spree::Variant',
|
27
|
-
viewable_id: product.master.to_param
|
28
|
-
},
|
29
|
-
}
|
30
|
-
expect(response.status).to eq(201)
|
31
|
-
expect(json_response).to have_attributes(attributes)
|
32
|
-
end.to change(Image, :count).by(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
context "working with an existing image" do
|
36
|
-
let!(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
|
37
|
-
|
38
|
-
it "can get a single product image" do
|
39
|
-
get spree.api_product_image_path(product.id, product_image)
|
40
|
-
expect(response.status).to eq(200)
|
41
|
-
expect(json_response).to have_attributes(attributes)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "can get a single variant image" do
|
45
|
-
get spree.api_variant_image_path(product.master.id, product_image)
|
46
|
-
expect(response.status).to eq(200)
|
47
|
-
expect(json_response).to have_attributes(attributes)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "can get a list of product images" do
|
51
|
-
get spree.api_product_images_path(product.id)
|
52
|
-
expect(response.status).to eq(200)
|
53
|
-
expect(json_response).to have_key("images")
|
54
|
-
expect(json_response["images"].first).to have_attributes(attributes)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "can get a list of variant images" do
|
58
|
-
get spree.api_variant_images_path(product.master.id)
|
59
|
-
expect(response.status).to eq(200)
|
60
|
-
expect(json_response).to have_key("images")
|
61
|
-
expect(json_response["images"].first).to have_attributes(attributes)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can update image data" do
|
65
|
-
expect(product_image.position).to eq(1)
|
66
|
-
put spree.api_variant_image_path(product.id, product_image), params: { image: { position: 2 } }
|
67
|
-
expect(response.status).to eq(200)
|
68
|
-
expect(json_response).to have_attributes(attributes)
|
69
|
-
expect(product_image.reload.position).to eq(2)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "can delete an image" do
|
73
|
-
delete spree.api_variant_image_path(product.id, product_image)
|
74
|
-
expect(response.status).to eq(204)
|
75
|
-
expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "as a non-admin" do
|
81
|
-
let(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
|
82
|
-
|
83
|
-
it "cannot create an image" do
|
84
|
-
post spree.api_product_images_path(product.id)
|
85
|
-
assert_unauthorized!
|
86
|
-
end
|
87
|
-
|
88
|
-
it "cannot update an image" do
|
89
|
-
put spree.api_product_image_path(product.id, product_image)
|
90
|
-
assert_not_found!
|
91
|
-
end
|
92
|
-
|
93
|
-
it "cannot delete an image" do
|
94
|
-
delete spree.api_product_image_path(product.id, product_image)
|
95
|
-
assert_not_found!
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
describe Api::InventoryUnitsController, type: :request do
|
7
|
-
let!(:inventory_unit) { create(:inventory_unit) }
|
8
|
-
|
9
|
-
before do
|
10
|
-
stub_authentication!
|
11
|
-
end
|
12
|
-
|
13
|
-
context "as an admin" do
|
14
|
-
sign_in_as_admin!
|
15
|
-
let(:variant) { create(:variant) }
|
16
|
-
|
17
|
-
it "gets an inventory unit" do
|
18
|
-
get spree.api_inventory_unit_path(inventory_unit)
|
19
|
-
expect(json_response['state']).to eq inventory_unit.state
|
20
|
-
end
|
21
|
-
|
22
|
-
it "updates an inventory unit" do
|
23
|
-
put spree.api_inventory_unit_path(inventory_unit), params: {
|
24
|
-
inventory_unit: { variant_id: variant.id }
|
25
|
-
}
|
26
|
-
expect(json_response['variant_id']).to eq variant.id
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'fires state event' do
|
30
|
-
it 'if supplied with :fire param' do
|
31
|
-
put spree.api_inventory_unit_path(inventory_unit), params: {
|
32
|
-
fire: 'ship',
|
33
|
-
inventory_unit: { variant_id: variant.id }
|
34
|
-
}
|
35
|
-
|
36
|
-
expect(json_response['state']).to eq 'shipped'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'and returns exception if cannot fire' do
|
40
|
-
put spree.api_inventory_unit_path(inventory_unit), params: {
|
41
|
-
fire: 'return'
|
42
|
-
}
|
43
|
-
expect(json_response['exception']).to match /cannot transition to return/
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'and returns exception bad state' do
|
47
|
-
put spree.api_inventory_unit_path(inventory_unit), params: {
|
48
|
-
fire: 'bad'
|
49
|
-
}
|
50
|
-
expect(json_response['exception']).to match /cannot transition to bad/
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|