spree_multi_vendor 2.0.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.travis.yml +1 -8
- data/Gemfile +5 -2
- data/README.md +12 -1
- data/app/controllers/spree/admin/vendor_settings_controller.rb +1 -1
- data/app/controllers/spree/admin/vendors_controller.rb +10 -2
- data/app/controllers/spree/api/v1/vendors_controller.rb +61 -0
- data/app/controllers/spree/api/v2/storefront/vendors_controller.rb +6 -1
- data/app/controllers/spree_multi_vendor/spree/api/base_controller_decorator.rb +17 -0
- data/app/controllers/spree_multi_vendor/spree/api/v1/products_controller_decorator.rb +9 -0
- data/app/controllers/spree_multi_vendor/spree/api/v1/users_controller_decorator.rb +13 -0
- data/app/finders/spree_multi_vendor/products_finder_decorator.rb +1 -1
- data/app/helpers/spree/api/vendor_helper.rb +11 -0
- data/app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb +19 -0
- data/app/models/spree/vendor_ability.rb +24 -9
- data/app/models/spree/vendor_user.rb +1 -1
- data/app/models/spree_multi_vendor/configuration.rb +1 -1
- data/app/models/spree_multi_vendor/spree/order_decorator.rb +5 -3
- data/app/overrides/spree/admin/shared/_main_menu.rb +1 -1
- data/app/serializers/spree/v2/storefront/vendor_order_totals_serializer.rb +2 -0
- data/app/views/spree/admin/vendor_settings/edit.html.erb +1 -1
- data/app/views/spree/admin/vendors/_form.html.erb +1 -1
- data/app/views/spree/api/v1/vendors/index.rabl +3 -0
- data/app/views/spree/api/v1/vendors/show.rabl +2 -0
- data/config/initializers/spree_permitted_attributes.rb +2 -0
- data/config/locales/es.yml +3 -0
- data/config/routes.rb +4 -1
- data/db/migrate/20210728120649_change_vendorized_models_vendor_id_type.rb +10 -0
- data/db/migrate/20210728120910_change_vendor_id_and_user_id_type_for_spree_vendor_users.rb +8 -0
- data/db/migrate/20210728121024_change_vendor_id_and_order_id_type_for_spree_order_commissions.rb +8 -0
- data/lib/spree_multi_vendor/factories.rb +1 -1
- data/lib/spree_multi_vendor/version.rb +1 -1
- data/lib/spree_multi_vendor.rb +2 -1
- data/spec/factories/spree/vendor_factory.rb +6 -0
- data/spec/features/spree/admin/orders_spec.rb +62 -12
- data/spec/features/spree/admin/vendor_settings_spec.rb +6 -8
- data/spec/models/spree/order_spec.rb +16 -2
- data/spec/requests/spree/api/v1/products_spec.rb +221 -0
- data/spec/requests/spree/api/v1/users_spec.rb +31 -0
- data/spec/requests/spree/api/v1/vendors_spec.rb +210 -0
- data/spec/requests/spree/api/v2/storefront/cart_spec.rb +19 -1
- data/spec/requests/spree/api/v2/storefront/products_spec.rb +4 -1
- data/spec/requests/spree/api/v2/storefront/vendors_spec.rb +66 -0
- data/spec/serializers/spree/v2/storefront/vendor_order_totals_serializer_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -1
- data/spree_multi_vendor.gemspec +5 -4
- metadata +32 -38
- data/Appraisals +0 -11
- data/app/controllers/spree_multi_vendor/spree/admin/option_types_controller_decorator.rb +0 -7
- data/app/controllers/spree_multi_vendor/spree/admin/properties_controller_decorator.rb +0 -7
- data/app/controllers/spree_multi_vendor/spree/api/v1/variants_controller_decorator.rb +0 -22
- data/gemfiles/spree_4_2.gemfile +0 -9
- data/gemfiles/spree_master.gemfile +0 -9
@@ -1,25 +1,75 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.feature 'Admin Orders', :js do
|
4
|
+
let(:store) { Spree::Store.default }
|
4
5
|
let(:vendor) { create(:active_vendor, name: 'Vendor') }
|
5
6
|
let(:vendor_2) { create(:active_vendor, name: 'Other vendor') }
|
6
|
-
let(:order)
|
7
|
-
|
8
|
-
line_items: [
|
9
|
-
create(:line_item, product: product),
|
10
|
-
create(:line_item, product: product_2)
|
11
|
-
])
|
12
|
-
end
|
7
|
+
let(:order) { create(:order, ship_address: create(:address), bill_address: create(:address), store: store) }
|
8
|
+
let(:order_2) { create(:order, store: store) }
|
13
9
|
let!(:user) { create(:user, vendors: [vendor]) }
|
14
|
-
let(:product) { create(:product_in_stock, vendor: vendor) }
|
15
|
-
let(:product_2) { create(:product_in_stock, vendor: vendor_2) }
|
10
|
+
let(:product) { create(:product_in_stock, vendor: vendor, stores:[store]) }
|
11
|
+
let(:product_2) { create(:product_in_stock, vendor: vendor_2,stores:[store]) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
create(:line_item, order: order, product: product)
|
15
|
+
create(:line_item, order: order, product: product_2)
|
16
|
+
order.create_proposed_shipments
|
17
|
+
order.update(state: :complete, completed_at: Time.current)
|
18
|
+
login_as(user, scope: :spree_user)
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples 'shows order data' do
|
22
|
+
it { expect(page).to have_text(order.number) }
|
23
|
+
it { expect(page).to have_content(order.display_vendor_total(vendor).to_html) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'index' do
|
27
|
+
background do
|
28
|
+
visit spree.admin_orders_path
|
29
|
+
end
|
30
|
+
|
31
|
+
it_behaves_like 'shows order data'
|
32
|
+
|
33
|
+
it 'does not show non-vendor orders' do
|
34
|
+
expect(page).not_to have_text(order_2.number)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'cart' do
|
39
|
+
background do
|
40
|
+
visit spree.cart_admin_order_path(id: order.number)
|
41
|
+
end
|
42
|
+
|
43
|
+
it_behaves_like 'shows order data'
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'customer info' do
|
47
|
+
background do
|
48
|
+
visit spree.admin_order_customer_path(order_id: order.number)
|
49
|
+
end
|
50
|
+
|
51
|
+
it_behaves_like 'shows order data'
|
52
|
+
|
53
|
+
it 'shows customer information' do
|
54
|
+
expect(page).to have_text(order.ship_address.full_name)
|
55
|
+
expect(page).to have_text(order.ship_address.address1)
|
56
|
+
expect(page).to have_text(order.ship_address.city)
|
57
|
+
|
58
|
+
expect(page).to have_text(order.bill_address.full_name)
|
59
|
+
expect(page).to have_text(order.bill_address.address1)
|
60
|
+
expect(page).to have_text(order.bill_address.city)
|
61
|
+
|
62
|
+
expect(page).not_to have_selector('input[type=text]')
|
63
|
+
end
|
64
|
+
end
|
16
65
|
|
17
66
|
context 'edit' do
|
18
67
|
background do
|
19
|
-
login_as(user, scope: :spree_user)
|
20
68
|
visit spree.edit_admin_order_path(id: order.number)
|
21
69
|
end
|
22
70
|
|
71
|
+
it_behaves_like 'shows order data'
|
72
|
+
|
23
73
|
scenario 'vendor can add his product' do
|
24
74
|
select2_open label: 'Name or SKU'
|
25
75
|
select2_search product.name, from: 'Name or SKU'
|
@@ -29,8 +79,8 @@ RSpec.feature 'Admin Orders', :js do
|
|
29
79
|
|
30
80
|
scenario 'vendor cannot add other vendors product' do
|
31
81
|
select2_open label: 'Name or SKU'
|
32
|
-
select2_search
|
33
|
-
expect(page).not_to have_text(
|
82
|
+
select2_search product_2.name, from: 'Name or SKU'
|
83
|
+
expect(page).not_to have_text(product_2.name)
|
34
84
|
end
|
35
85
|
end
|
36
86
|
end
|
@@ -42,13 +42,11 @@ RSpec.feature 'Admin Vendor Settings', :js do
|
|
42
42
|
expect(page).not_to have_text 'contact_us can\'t be blank'
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
expect(page).to have_css("img[src*='thinking-cat.jpg']")
|
51
|
-
end
|
45
|
+
scenario 'can update an existing vendor image' do
|
46
|
+
create(:vendor, name: 'New vendor')
|
47
|
+
page.attach_file("vendor_image", Spree::Core::Engine.root + 'spec/fixtures' + 'thinking-cat.jpg')
|
48
|
+
click_button 'Update'
|
49
|
+
expect(page).to have_css("img[src*='thinking-cat.jpg']")
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
@@ -70,7 +68,7 @@ RSpec.feature 'Admin Vendor Settings', :js do
|
|
70
68
|
|
71
69
|
it 'renders forbidden page' do
|
72
70
|
visit spree.admin_vendor_settings_path
|
73
|
-
expect(current_path).to eq spree.
|
71
|
+
expect(current_path).to eq spree.admin_forbidden_path
|
74
72
|
end
|
75
73
|
end
|
76
74
|
end
|
@@ -34,6 +34,20 @@ describe Spree::Order do
|
|
34
34
|
expect(v.commissions.sum(:amount)).to eq(commission_ammount)
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'sends mails only once per vendor' do
|
39
|
+
mail_double_1 = double(:mail_double_1)
|
40
|
+
mail_double_2 = double(:mail_double_1)
|
41
|
+
|
42
|
+
expect(Spree::VendorMailer).to receive(:vendor_notification_email)
|
43
|
+
.with(be_an(Integer), vendor.id) { mail_double_1 }
|
44
|
+
expect(mail_double_1).to receive(:deliver_later)
|
45
|
+
expect(Spree::VendorMailer).to receive(:vendor_notification_email)
|
46
|
+
.with(be_an(Integer), vendor_2.id) { mail_double_2 }
|
47
|
+
expect(mail_double_2).to receive(:deliver_later)
|
48
|
+
|
49
|
+
order.next!
|
50
|
+
end
|
37
51
|
end
|
38
52
|
|
39
53
|
context 'vendor methods' do
|
@@ -57,11 +71,11 @@ describe Spree::Order do
|
|
57
71
|
end
|
58
72
|
|
59
73
|
describe '#vendor_subtotal' do
|
60
|
-
it { expect(order.vendor_subtotal(vendor)).to eq(
|
74
|
+
it { expect(order.vendor_subtotal(vendor)).to eq(320) }
|
61
75
|
end
|
62
76
|
|
63
77
|
describe '#display_subtotal' do
|
64
|
-
it { expect(order.display_vendor_subtotal(vendor).to_s).to eq('$
|
78
|
+
it { expect(order.display_vendor_subtotal(vendor).to_s).to eq('$320.00') }
|
65
79
|
end
|
66
80
|
|
67
81
|
describe '#vendor_pre_tax_item_amount' do
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe 'API V1 Products Spec', type: :request do
|
5
|
+
let(:vendor) { create(:vendor, state: :active) }
|
6
|
+
let(:other_vendor) { create(:vendor) }
|
7
|
+
let(:shipping_category) { create(:shipping_category) }
|
8
|
+
let(:selected_product) { product_without_vendor }
|
9
|
+
let(:params) { {} }
|
10
|
+
|
11
|
+
let!(:product_without_vendor) { create(:product) }
|
12
|
+
let!(:product_with_vendor_vendor) { create(:product, vendor: vendor) }
|
13
|
+
let!(:product_with_other_vendor) { create(:product, vendor: other_vendor) }
|
14
|
+
|
15
|
+
before { stub_authentication! }
|
16
|
+
|
17
|
+
describe 'products#index' do
|
18
|
+
before { get '/api/v1/products', params: params }
|
19
|
+
|
20
|
+
context 'as a regular user' do
|
21
|
+
it 'gets a list of all products' do
|
22
|
+
expect(response.status).to eq(200)
|
23
|
+
expect(json_response[:products].size).to eq(3)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'as an admin' do
|
28
|
+
sign_in_as_admin!
|
29
|
+
|
30
|
+
it 'gets a list of all products' do
|
31
|
+
expect(response.status).to eq(200)
|
32
|
+
expect(json_response[:products].size).to eq(3)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'as a vendor' do
|
37
|
+
let!(:current_api_user) do
|
38
|
+
user = create(:user, vendors: [vendor])
|
39
|
+
user
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'gets a list of products assigned to that vendor' do
|
43
|
+
expect(response.status).to eq(200)
|
44
|
+
expect(json_response[:products].size).to eq(1)
|
45
|
+
expect(json_response[:products][0][:id]).to eq(vendor.products.first.id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'products#show' do
|
51
|
+
before { get "/api/v1/products/#{selected_product.id}" }
|
52
|
+
|
53
|
+
it 'gets a product' do
|
54
|
+
expect(response.status).to eq(200)
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'as a vendor' do
|
58
|
+
let!(:current_api_user) do
|
59
|
+
user = create(:user, vendors: [vendor])
|
60
|
+
user
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'cannot view product of another vendor' do
|
64
|
+
let(:selected_product) { product_with_other_vendor }
|
65
|
+
|
66
|
+
it do
|
67
|
+
expect(response.status).to eq(404)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'can view product assigned to that vendor' do
|
72
|
+
let(:selected_product) { product_with_vendor_vendor }
|
73
|
+
|
74
|
+
it do
|
75
|
+
expect(response.status).to eq(200)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'products#create' do
|
82
|
+
let(:params) do
|
83
|
+
{
|
84
|
+
product: {
|
85
|
+
name: 'Product',
|
86
|
+
shipping_category_id: shipping_category.id,
|
87
|
+
price: 12.34
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
before { post '/api/v1/products', params: params }
|
93
|
+
|
94
|
+
context 'as regular user' do
|
95
|
+
it 'cannot create a new product' do
|
96
|
+
expect(response.status).to eq(401)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'as an admin' do
|
101
|
+
sign_in_as_admin!
|
102
|
+
|
103
|
+
it 'can create a new product' do
|
104
|
+
expect(response.status).to eq(201)
|
105
|
+
expect(json_response['name']).to eq(params[:product][:name])
|
106
|
+
expect(json_response['price']).to eq(params[:product][:price].to_s)
|
107
|
+
expect(json_response['shipping_category_id']).to eq(params[:product][:shipping_category_id])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'as a vendor' do
|
112
|
+
let!(:current_api_user) do
|
113
|
+
user = create(:user, vendors: [vendor])
|
114
|
+
user
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'can create a new product assigned to vendor' do
|
118
|
+
expect(response.status).to eq(201)
|
119
|
+
product = Spree::Product.find(json_response[:id])
|
120
|
+
expect(product.vendor).to eq(vendor)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'products#update' do
|
126
|
+
let(:params) do
|
127
|
+
{
|
128
|
+
product: {
|
129
|
+
name: 'Updated Prodouct',
|
130
|
+
shipping_category_id: shipping_category.id,
|
131
|
+
price: 12.34
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
before { put "/api/v1/products/#{selected_product.id}", params: params }
|
137
|
+
|
138
|
+
context 'as regular user' do
|
139
|
+
it 'cannot update product' do
|
140
|
+
expect(response.status).to eq(401)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'as an admin' do
|
145
|
+
sign_in_as_admin!
|
146
|
+
|
147
|
+
it 'can update product' do
|
148
|
+
expect(response.status).to eq(200)
|
149
|
+
expect(json_response['name']).to eq(params[:product][:name])
|
150
|
+
expect(json_response['price']).to eq(params[:product][:price].to_s)
|
151
|
+
expect(json_response['shipping_category_id']).to eq(params[:product][:shipping_category_id])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'as a vendor' do
|
156
|
+
let!(:current_api_user) do
|
157
|
+
user = create(:user, vendors: [vendor])
|
158
|
+
user
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'cannot update product of another vendor' do
|
162
|
+
let(:selected_product) { product_with_other_vendor }
|
163
|
+
|
164
|
+
it do
|
165
|
+
expect(response.status).to eq(404)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'can update product assigned to that vendor' do
|
170
|
+
let(:selected_product) { product_with_vendor_vendor }
|
171
|
+
|
172
|
+
it do
|
173
|
+
expect(response.status).to eq(200)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe 'products#destroy' do
|
180
|
+
before { delete "/api/v1/products/#{selected_product.id}" }
|
181
|
+
|
182
|
+
context 'as regular user' do
|
183
|
+
it 'cannot delete product' do
|
184
|
+
expect(response.status).to eq(401)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'as an admin' do
|
189
|
+
sign_in_as_admin!
|
190
|
+
|
191
|
+
it 'can delete product' do
|
192
|
+
expect(response.status).to eq(204)
|
193
|
+
expect(product_without_vendor.reload.deleted_at).to_not eq(nil)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'as a vendor' do
|
198
|
+
let!(:current_api_user) do
|
199
|
+
user = create(:user, vendors: [vendor])
|
200
|
+
user
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'cannot delete product of another vendor' do
|
204
|
+
let(:selected_product) { product_with_other_vendor }
|
205
|
+
|
206
|
+
it do
|
207
|
+
expect(response.status).to eq(404)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe 'can delete product assigned to that vendor' do
|
212
|
+
let(:selected_product) { product_with_vendor_vendor }
|
213
|
+
|
214
|
+
it do
|
215
|
+
expect(response.status).to eq(204)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe 'API V1 Users Spec', type: :request do
|
5
|
+
let(:user) { create(:user) }
|
6
|
+
let(:vendor) { create(:vendor, state: :active) }
|
7
|
+
|
8
|
+
before { stub_authentication! }
|
9
|
+
|
10
|
+
describe 'users#update' do
|
11
|
+
let(:params) do
|
12
|
+
{
|
13
|
+
user: {
|
14
|
+
vendor_ids: [vendor.id]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
before { put "/api/v1/users/#{user.id}", params: params }
|
20
|
+
|
21
|
+
context 'as an admin' do
|
22
|
+
sign_in_as_admin!
|
23
|
+
|
24
|
+
it 'can update user' do
|
25
|
+
expect(response.status).to eq(200)
|
26
|
+
expect(json_response['vendor_ids']).to eq([vendor.id])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe 'API V1 Vendors Spec', type: :request do
|
5
|
+
let(:params) { {} }
|
6
|
+
let(:selected_vendor) { vendor }
|
7
|
+
|
8
|
+
let!(:vendor) { create(:vendor, state: :active) }
|
9
|
+
let!(:another_vendor) { create(:vendor, state: :active) }
|
10
|
+
|
11
|
+
before { stub_authentication! }
|
12
|
+
|
13
|
+
describe 'vendors#index' do
|
14
|
+
before { get '/api/v1/vendors', params: params }
|
15
|
+
|
16
|
+
context 'as a regular user' do
|
17
|
+
it 'gets an empty list' do
|
18
|
+
expect(response.status).to eq(200)
|
19
|
+
expect(json_response.size).to eq(0)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'as an admin' do
|
24
|
+
sign_in_as_admin!
|
25
|
+
|
26
|
+
it 'gets a list of all vendors' do
|
27
|
+
expect(response.status).to eq(200)
|
28
|
+
expect(json_response.size).to eq(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'as a vendor' do
|
33
|
+
let!(:current_api_user) do
|
34
|
+
user = create(:user, vendors: [vendor])
|
35
|
+
user
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'gets a list of assigned vendors' do
|
39
|
+
expect(response.status).to eq(200)
|
40
|
+
expect(json_response.size).to eq(1)
|
41
|
+
expect(json_response[0]['id']).to eq(vendor.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'vendors#show' do
|
47
|
+
before { get "/api/v1/vendors/#{selected_vendor.id}" }
|
48
|
+
|
49
|
+
context 'as a regular user' do
|
50
|
+
it 'cannot view a vendor' do
|
51
|
+
expect(response.status).to eq(404)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'as an admin' do
|
56
|
+
sign_in_as_admin!
|
57
|
+
it 'can view a vendor' do
|
58
|
+
expect(response.status).to eq(200)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'as a vendor' do
|
63
|
+
let!(:current_api_user) do
|
64
|
+
user = create(:user, vendors: [vendor])
|
65
|
+
user
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'can view a assigned vendor' do
|
69
|
+
it do
|
70
|
+
expect(response.status).to eq(200)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'cannot view an another vendor' do
|
75
|
+
let(:selected_vendor) { another_vendor }
|
76
|
+
|
77
|
+
it do
|
78
|
+
expect(response.status).to eq(404)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'vendors#create' do
|
85
|
+
let(:params) do
|
86
|
+
{
|
87
|
+
vendor: {
|
88
|
+
name: 'name'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
before { post '/api/v1/vendors', params: params }
|
94
|
+
|
95
|
+
context 'as regular user' do
|
96
|
+
it 'cannot create a new vendor' do
|
97
|
+
expect(response.status).to eq(401)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'as an admin' do
|
102
|
+
sign_in_as_admin!
|
103
|
+
|
104
|
+
it 'can create a new vendor' do
|
105
|
+
expect(response.status).to eq(201)
|
106
|
+
expect(json_response['name']).to eq(params[:vendor][:name])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'as a vendor' do
|
111
|
+
let!(:current_api_user) do
|
112
|
+
user = create(:user, vendors: [vendor], email: FFaker::Internet.email)
|
113
|
+
user
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'cannot create a new vendor' do
|
117
|
+
expect(response.status).to eq(401)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'vendors#update' do
|
123
|
+
let(:params) do
|
124
|
+
{
|
125
|
+
vendor: {
|
126
|
+
name: 'updated name'
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
before { put "/api/v1/vendors/#{selected_vendor.id}", params: params }
|
132
|
+
|
133
|
+
context 'as regular user' do
|
134
|
+
it 'cannot update vendor' do
|
135
|
+
expect(response.status).to eq(404)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'as an admin' do
|
140
|
+
sign_in_as_admin!
|
141
|
+
|
142
|
+
it 'can update vendor' do
|
143
|
+
expect(response.status).to eq(200)
|
144
|
+
expect(json_response['name']).to eq(params[:vendor][:name])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'as a vendor' do
|
149
|
+
let!(:current_api_user) do
|
150
|
+
user = create(:user, vendors: [vendor])
|
151
|
+
user
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'can update as assigned vendor' do
|
155
|
+
it do
|
156
|
+
expect(response.status).to eq(200)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'cannot update an another vendor' do
|
161
|
+
let(:selected_vendor) { another_vendor }
|
162
|
+
|
163
|
+
it do
|
164
|
+
expect(response.status).to eq(404)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'vendors#destroy' do
|
171
|
+
before { delete "/api/v1/vendors/#{selected_vendor.id}" }
|
172
|
+
|
173
|
+
context 'as regular user' do
|
174
|
+
it 'cannot delete vendor' do
|
175
|
+
expect(response.status).to eq(404)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'as an admin' do
|
180
|
+
sign_in_as_admin!
|
181
|
+
|
182
|
+
it 'can delete vendor' do
|
183
|
+
expect(response.status).to eq(204)
|
184
|
+
expect(vendor.reload.deleted_at).to_not eq(nil)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'as a vendor' do
|
189
|
+
let!(:current_api_user) do
|
190
|
+
user = create(:user, vendors: [vendor])
|
191
|
+
user
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'can delete an assigned vendor' do
|
195
|
+
it do
|
196
|
+
expect(response.status).to eq(204)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe 'cannot delete an another vendor' do
|
201
|
+
let(:selected_vendor) { another_vendor }
|
202
|
+
|
203
|
+
it do
|
204
|
+
expect(response.status).to eq(404)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -26,7 +26,7 @@ describe 'API V2 Storefront Cart Spec', type: :request do
|
|
26
26
|
it_behaves_like 'returns valid cart JSON'
|
27
27
|
end
|
28
28
|
|
29
|
-
context '
|
29
|
+
context 'with one vendor' do
|
30
30
|
let(:params) { { include: 'vendors,vendor_totals' } }
|
31
31
|
|
32
32
|
it_behaves_like 'showing the cart'
|
@@ -42,6 +42,24 @@ describe 'API V2 Storefront Cart Spec', type: :request do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
context 'with many vendors' do
|
46
|
+
let!(:line_item_2) { create(:line_item, order: order, product: product_2, variant: product_2.default_variant) }
|
47
|
+
let(:params) { { include: 'vendors,vendor_totals' } }
|
48
|
+
|
49
|
+
it_behaves_like 'showing the cart'
|
50
|
+
|
51
|
+
it 'includes many vendors and vendor totals' do
|
52
|
+
get '/api/v2/storefront/cart', headers: headers_bearer, params: params
|
53
|
+
|
54
|
+
[vendor, vendor_2].each do |vendor|
|
55
|
+
expect(json_response['included']).to include(have_type('vendor').and have_id(vendor.id.to_s))
|
56
|
+
expect(json_response['included']).to include(have_type('vendor_totals').and have_id(vendor.id.to_s))
|
57
|
+
expect(json_response['included']).to include(have_type('vendor').and have_attribute(:name).with_value(vendor.name))
|
58
|
+
expect(json_response['included']).to include(have_type('vendor_totals').and have_attribute(:name).with_value(vendor.name))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
45
63
|
context 'includes line item vendor data' do
|
46
64
|
it_behaves_like 'showing the cart'
|
47
65
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'API V2 Storefront Products Spec', type: :request do
|
4
|
-
let
|
4
|
+
let(:store) { Spree::Store.default }
|
5
|
+
let!(:products) { create_list(:product, 5, stores: [store]) }
|
5
6
|
let!(:vendor) { create(:vendor) }
|
6
7
|
let!(:vendor_2) { create(:vendor) }
|
7
8
|
|
@@ -26,6 +27,8 @@ describe 'API V2 Storefront Products Spec', type: :request do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
context 'with specified vendor ids' do
|
30
|
+
before { vendor.products << create(:product) }
|
31
|
+
before { vendor_2.products << create(:product) }
|
29
32
|
before { get "/api/v2/storefront/products?filter[vendor_ids]=#{vendor.id}&include=vendor" }
|
30
33
|
|
31
34
|
it_behaves_like 'returns 200 HTTP status'
|