mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Removes html tr tag; Clarifies it block
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
|
||||
|
||||
@@ -115,43 +115,42 @@ feature '
|
||||
end
|
||||
end
|
||||
|
||||
describe "soft-deleting" do
|
||||
describe "deleting", js: true do
|
||||
let!(:product1) { create(:simple_product, name: 'a product to keep', supplier: @supplier) }
|
||||
|
||||
context 'a simple product', js: true do
|
||||
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 "tr#p_#{product2.id}" do
|
||||
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 "tr#p_#{product2.id}"
|
||||
expect(page).to have_selector "tr#p_#{product1.id}"
|
||||
expect(page).not_to have_selector "#p_#{product2.id}"
|
||||
expect(page).to have_selector "#p_#{product1.id}"
|
||||
end
|
||||
end
|
||||
|
||||
context 'a shipped product', js: true do
|
||||
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 "tr#p_#{order.variants.first.product_id}" do
|
||||
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 "tr#p_#{product1.id}"
|
||||
expect(page).not_to have_selector "tr#p_#{order.variants.first.product_id}"
|
||||
expect(Spree::Product.count).to eq 1
|
||||
expect(order.line_items.count).to eq 1
|
||||
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
|
||||
@@ -164,29 +163,18 @@ feature '
|
||||
|
||||
describe 'cloning' do
|
||||
let!(:product1) { create(:simple_product, name: 'a weight product', supplier: @supplier, variant_unit: "weight") }
|
||||
let!(:variant1) { create(:variant, product_id: product1.id, display_name: 'kg oranges') }
|
||||
|
||||
context 'products', js: true do
|
||||
before { login_as_admin_and_visit spree.admin_products_path }
|
||||
|
||||
it 'creates a copy of the product' do
|
||||
within "tr#p_#{product1.id}" do
|
||||
within "#p_#{product1.id}" do
|
||||
page.find("[data-powertip=Clone]").click
|
||||
end
|
||||
expect(page).to have_selector "tr#p_#{variant1.product_id}"
|
||||
|
||||
within "tr#p_#{product1.id + 1}" do
|
||||
visit current_path
|
||||
within "#p_#{product1.id + 1}" do
|
||||
expect(page).to have_input "product_name", with: 'COPY OF a weight product'
|
||||
end
|
||||
|
||||
# bug #660
|
||||
# only the first variant is duplicated
|
||||
expect(Spree::Product.second.variants.count).to eq 1
|
||||
# TODO expect(Spree::Product.second.variants.count).to eq Spree::Product.first.variants.count
|
||||
|
||||
# the stock of the cloned product is always zero
|
||||
expect(Spree::Product.second.on_hand).to eq 0
|
||||
# TODO expect(Spree::Product.second.on_hand).to eq Spree::Product.first.on_hand
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user