mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #7402 from filipefurtad0/products_spec_add_ons
Adds coverage for product deletion and cloning
This commit is contained in:
@@ -164,6 +164,7 @@ describe Api::V0::ProductsController, type: :controller do
|
||||
|
||||
context 'as an enterprise user' do
|
||||
let(:current_api_user) { supplier_enterprise_user(supplier) }
|
||||
let!(:variant) { create(:variant, product_id: product.id) }
|
||||
|
||||
it 'responds with a successful response' do
|
||||
spree_post :clone, product_id: product.id, format: :json
|
||||
@@ -183,6 +184,27 @@ describe Api::V0::ProductsController, type: :controller do
|
||||
expect(response.status).to eq(201)
|
||||
expect(json_response['name']).to eq("COPY OF #{product_with_image.name}")
|
||||
end
|
||||
|
||||
# test cases related to bug #660: product duplication clones master variant
|
||||
|
||||
# stock info - clone is set to zero
|
||||
it '(does not) clone the stock info of the product' do
|
||||
spree_post :clone, product_id: product.id, format: :json
|
||||
expect(json_response['on_hand']).to eq(0)
|
||||
end
|
||||
|
||||
# variants: only the master variant of the product is cloned
|
||||
it '(does not) clone variants from a product with several variants' do
|
||||
spree_post :clone, product_id: product.id, format: :json
|
||||
expect(Spree::Product.second.variants.count).not_to eq Spree::Product.first.variants.count
|
||||
end
|
||||
|
||||
#price info: it does not consider price changes; it considers the price set upon product creation
|
||||
it '(does not) clone price which was updated' do
|
||||
product.update_attribute(:price, 2.22)
|
||||
spree_post :clone, product_id: product.id, format: :json
|
||||
expect(json_response['price']).not_to eq(2.22)
|
||||
end
|
||||
end
|
||||
|
||||
context 'as an administrator' do
|
||||
|
||||
@@ -114,6 +114,70 @@ feature '
|
||||
expect(page).to have_content "Unit value can't be blank"
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting", js: true do
|
||||
let!(:product1) { create(:simple_product, name: 'a product to keep', supplier: @supplier) }
|
||||
|
||||
context 'a simple product' do
|
||||
let!(:product2) { create(:simple_product, name: 'a product to delete', supplier: @supplier) }
|
||||
|
||||
before do
|
||||
login_as_admin_and_visit spree.admin_products_path
|
||||
|
||||
within "#p_#{product2.id}" do
|
||||
accept_alert { page.find("[data-powertip=Remove]").click }
|
||||
end
|
||||
visit current_path
|
||||
end
|
||||
|
||||
it 'removes it from the product list' do
|
||||
expect(page).not_to have_selector "#p_#{product2.id}"
|
||||
expect(page).to have_selector "#p_#{product1.id}"
|
||||
end
|
||||
end
|
||||
|
||||
context 'a shipped product' do
|
||||
let!(:order) { create(:shipped_order, line_items_count: 1) }
|
||||
let!(:line_item) { order.reload.line_items.first }
|
||||
|
||||
before do
|
||||
login_as_admin_and_visit spree.admin_products_path
|
||||
|
||||
within "#p_#{order.variants.first.product_id}" do
|
||||
accept_alert { page.find("[data-powertip=Remove]").click }
|
||||
end
|
||||
visit current_path
|
||||
end
|
||||
it 'removes it from the product list' do
|
||||
expect(page).to have_selector "#p_#{product1.id}"
|
||||
expect(page).not_to have_selector "#p_#{order.variants.first.product_id}"
|
||||
end
|
||||
|
||||
it 'keeps the line item on the order (admin)' do
|
||||
visit spree.admin_orders_path
|
||||
find(".icon-edit").click
|
||||
expect(page).to have_content(line_item.product.name.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cloning' do
|
||||
let!(:product1) { create(:simple_product, name: 'a weight product', supplier: @supplier, variant_unit: "weight") }
|
||||
|
||||
context 'products', js: true do
|
||||
before { login_as_admin_and_visit spree.admin_products_path }
|
||||
|
||||
it 'creates a copy of the product' do
|
||||
within "#p_#{product1.id}" do
|
||||
page.find("[data-powertip=Clone]").click
|
||||
end
|
||||
visit current_path
|
||||
within "#p_#{product1.id + 1}" do
|
||||
expect(page).to have_input "product_name", with: 'COPY OF a weight product'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
let!(:tax_category) { create(:tax_category) }
|
||||
|
||||
Reference in New Issue
Block a user