From 5d6ac4331b17b157d8b18708af10694361d58d5b Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Fri, 29 Nov 2024 04:17:57 +0500 Subject: [PATCH] 12973: add specs --- spec/models/product_importer_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index a2a2917f20a..a2a5b96b258 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -1012,6 +1012,30 @@ expect(lettuce.count_on_hand).to eq 96 # In different enterprise; unchanged end end + + # Fix https://github.com/openfoodfoundation/openfoodnetwork/issues/12973 + describe 'update existing product with units and on_hand/on_demand is empty' do + let(:csv_data) do + CSV.generate do |csv| + csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", + "shipping_category", "on_demand"] + csv << ["Beetroot", enterprise3.name, "Vegetables", "", "6.50", "", "g", + shipping_category.name, "1"] + end + end + let(:importer) { import_data csv_data } + + it "returns the units error due to invalid data" do + importer.validate_entries + entries = JSON.parse(importer.entries_json) + + expect(entries.dig('2', 'errors')).to eq( + { + "units" => "Units can't be blank", + } + ) + end + end end private