From 1df1ddcf66cf15848a114f1e8cdd674d8722aa91 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 27 Aug 2018 23:06:54 +0100 Subject: [PATCH] Add spec for saving product and variant simultaneously --- spec/features/admin/product_import_spec.rb | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index af23ddf9bf..31477f1338 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -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"]