mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add spec for saving product and variant simultaneously
This commit is contained in:
@@ -201,6 +201,44 @@ feature "Product Import", js: true do
|
||||
expect(Spree::Product.find_by_name('Beans').on_hand).to eq 0
|
||||
end
|
||||
|
||||
it "can save a new product and variant of that product at the same time" do
|
||||
csv_data = CSV.generate do |csv|
|
||||
csv << ["name", "supplier", "category", "on_hand", "price", "units", "unit_type", "display_name"]
|
||||
csv << ["Potatoes", "User Enterprise", "Vegetables", "5", "3.50", "500", "g", "Small Bag"]
|
||||
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "5.50", "2", "kg", "Big Bag"]
|
||||
end
|
||||
File.write('/tmp/test.csv', csv_data)
|
||||
|
||||
visit main_app.admin_product_import_path
|
||||
attach_file 'file', '/tmp/test.csv'
|
||||
click_button 'Upload'
|
||||
|
||||
import_data
|
||||
|
||||
expect(page).to have_selector '.item-count', text: "2"
|
||||
expect(page).to_not have_selector '.invalid-count'
|
||||
expect(page).to have_selector '.create-count', text: "2"
|
||||
expect(page).to_not have_selector '.update-count'
|
||||
expect(page).to_not have_selector '.update-count'
|
||||
expect(page).to_not have_selector '.inv-create-count'
|
||||
expect(page).to_not have_selector '.inv-update-count'
|
||||
|
||||
save_data
|
||||
|
||||
small_bag = Spree::Variant.find_by_display_name('Small Bag')
|
||||
expect(small_bag.product.name).to eq 'Potatoes'
|
||||
expect(small_bag.price).to eq 3.50
|
||||
expect(small_bag.on_hand).to eq 5
|
||||
|
||||
big_bag = Spree::Variant.find_by_display_name('Big Bag')
|
||||
expect(big_bag.product.name).to eq 'Potatoes'
|
||||
expect(big_bag.price).to eq 5.50
|
||||
expect(big_bag.on_hand).to eq 6
|
||||
|
||||
expect(big_bag.product.id).to eq small_bag.product.id
|
||||
end
|
||||
|
||||
|
||||
it "can import items into inventory" do
|
||||
csv_data = CSV.generate do |csv|
|
||||
csv << ["name", "supplier", "producer", "category", "on_hand", "price", "units"]
|
||||
|
||||
Reference in New Issue
Block a user