From 95c9f9afbbf616110578246d9a9190051b572b33 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 21 Dec 2022 23:13:37 +0000 Subject: [PATCH 1/3] Adds coverage for inconsistent variant unit name on csv - inventory import --- spec/system/admin/product_import_spec.rb | 81 ++++++++++++++++-------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index 1fc6302b15..a3c60ca5df 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -382,36 +382,67 @@ describe "Product Import", js: true do with: "3.2" end - it "handles the Items unit for inventory import" do - product = create(:simple_product, supplier: enterprise, on_hand: nil, name: 'Aubergine', - unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Bag") - csv_data = CSV.generate do |csv| - csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", - "units", "on_demand", "variant_unit_name"] - csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3", - "kg", "1", "true", "Bag"] + describe "Item type products" do + let!(:product) { + create(:simple_product, supplier: enterprise, on_hand: nil, name: 'Aubergine', + unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Bag") + } + it "are sucessfully imported to inventory" do + csv_data = CSV.generate do |csv| + csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", + "units", "on_demand", "variant_unit_name"] + csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3", + "kg", "1", "true", "Bag"] + end + + File.write('/tmp/test.csv', csv_data) + visit main_app.admin_product_import_path + select I18n.t('admin.product_import.index.inventories'), from: "settings_import_into" + attach_file 'file', '/tmp/test.csv' + click_button 'Upload' + proceed_to_validation + expect(page).to have_selector '.item-count', text: "1" + expect(page).to have_no_selector '.invalid-count' + expect(page).to have_selector '.inv-create-count', text: '1' + save_data + + expect(page).to have_selector '.inv-created-count', text: '1' + + visit main_app.admin_inventory_path + + expect(page).to have_content "Aubergine" + expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-on_demand", + selected: "Yes" + expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-price", + with: "3.3" end - File.write('/tmp/test.csv', csv_data) - visit main_app.admin_product_import_path - select I18n.t('admin.product_import.index.inventories'), from: "settings_import_into" - attach_file 'file', '/tmp/test.csv' - click_button 'Upload' - proceed_to_validation - expect(page).to have_selector '.item-count', text: "1" - expect(page).to have_no_selector '.invalid-count' - expect(page).to have_selector '.inv-create-count', text: '1' - save_data + it "displays the appropriate error message, when variant unit names are inconsistent" do + csv_data = CSV.generate do |csv| + csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", + "units", "on_demand", "variant_unit_name"] + csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3", + "kg", "1", "true", "Bag"] + csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "6.6", + "kg", "1", "true", "Big-Bag"] + end - expect(page).to have_selector '.inv-created-count', text: '1' + File.write('/tmp/test.csv', csv_data) + visit main_app.admin_product_import_path + select I18n.t('admin.product_import.index.inventories'), from: "settings_import_into" + attach_file 'file', '/tmp/test.csv' + click_button 'Upload' + proceed_to_validation - visit main_app.admin_inventory_path + find('div.header-description', text: 'Items contain errors').click + expect(page).to have_content "Variant_unit_name cannot be updated on existing products via product import" + expect(page).to have_content "Imported file contains invalid entries" + expect(page).to have_no_selector 'input[type=submit][value="Save"]' - expect(page).to have_content "Aubergine" - expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-on_demand", - selected: "Yes" - expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-price", - with: "3.3" + visit main_app.admin_inventory_path + + expect(page).not_to have_content "Aubergine" + end end it "handles on_demand and on_hand validations with inventory" do From a465093d12024beab915bf0517d5c9e310eab708 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 21 Dec 2022 23:37:48 +0000 Subject: [PATCH 2/3] Adds coverage for inconsistent variant unit name on csv - product creation --- spec/system/admin/product_import_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index a3c60ca5df..a86f356c11 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -136,6 +136,29 @@ describe "Product Import", js: true do expect(page).to have_no_selector 'input[type=submit][value="Save"]' end + it "displays info about inconsistent variant unit names, within the same product" do + csv_data = CSV.generate do |csv| + csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "variant_unit_name", + "shipping_category_id"] + csv << ["Carrots", "User Enterprise", "Vegetables", "50", "3.20", "250", "", "Bag", shipping_category_id_str] + csv << ["Carrots", "User Enterprise", "Vegetables", "50", "6.40", "500", "", "Big-Bag", shipping_category_id_str] + end + File.write('/tmp/test.csv', csv_data) + + visit main_app.admin_product_import_path + + expect(page).to have_content "Select a spreadsheet to upload" + attach_file 'file', '/tmp/test.csv' + click_button 'Upload' + + proceed_to_validation + find('div.header-description', text: 'Items contain errors').click + expect(page).to have_content "Variant_unit_name cannot be updated on existing products via product import" + expect(page).to have_content "Imported file contains invalid entries" + + expect(page).to have_no_selector 'input[type=submit][value="Save"]' + end + it "handles saving of named tax and shipping categories" do csv_data = CSV.generate do |csv| csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", From 5ae6223a8c7b3ae70f3f2af7cbe123afd1e224ae Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 22 Dec 2022 11:21:34 +0000 Subject: [PATCH 3/3] Updates error messages after #10174 merge --- spec/system/admin/product_import_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index a86f356c11..9b0f1615ae 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -153,7 +153,7 @@ describe "Product Import", js: true do proceed_to_validation find('div.header-description', text: 'Items contain errors').click - expect(page).to have_content "Variant_unit_name cannot be updated on existing products via product import" + expect(page).to have_content "Variant_unit_name must be the same for products with the same name" expect(page).to have_content "Imported file contains invalid entries" expect(page).to have_no_selector 'input[type=submit][value="Save"]' @@ -458,7 +458,7 @@ describe "Product Import", js: true do proceed_to_validation find('div.header-description', text: 'Items contain errors').click - expect(page).to have_content "Variant_unit_name cannot be updated on existing products via product import" + expect(page).to have_content "Variant_unit_name must be the same for products with the same name" expect(page).to have_content "Imported file contains invalid entries" expect(page).to have_no_selector 'input[type=submit][value="Save"]'