diff --git a/app/services/bulk_upload/sales/validator.rb b/app/services/bulk_upload/sales/validator.rb index b7b2d889f..f15965603 100644 --- a/app/services/bulk_upload/sales/validator.rb +++ b/app/services/bulk_upload/sales/validator.rb @@ -139,7 +139,7 @@ private def validate_file_not_empty if File.size(path).zero? || csv_parser.row_parsers.empty? - errors.add(:file, :blank) + errors.add(:base, :blank_file) halt_validations! end diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index a9c181b00..a2d3d1b6a 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -11,12 +11,6 @@ RSpec.describe BulkUpload::Lettings::Validator do let(:file) { Tempfile.new } describe "validations" do - context "when file is empty" do - it "is not valid" do - expect(validator).not_to be_valid - end - end - context "when 2022" do let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) } @@ -34,6 +28,13 @@ RSpec.describe BulkUpload::Lettings::Validator do end end + context "and is empty" do + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "and doesn't have too many columns" do before do file.write(("a" * 95).chars.join(",")) @@ -71,6 +72,13 @@ RSpec.describe BulkUpload::Lettings::Validator do end end + context "and is empty" do + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "and file has too few valid headers" do let(:seed) { rand } let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) } @@ -128,6 +136,13 @@ RSpec.describe BulkUpload::Lettings::Validator do end end + context "and is empty" do + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "and doesn't have too many columns" do before do file.write(("a" * 142).chars.join(",")) @@ -142,6 +157,13 @@ RSpec.describe BulkUpload::Lettings::Validator do end context "when file has headers" do + context "and is empty" do + it "is not valid" do + expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) + end + end + context "and file has extra invalid headers" do let(:seed) { rand } let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) } diff --git a/spec/services/bulk_upload/sales/validator_spec.rb b/spec/services/bulk_upload/sales/validator_spec.rb index 8d543b4a6..d7e254864 100644 --- a/spec/services/bulk_upload/sales/validator_spec.rb +++ b/spec/services/bulk_upload/sales/validator_spec.rb @@ -13,6 +13,7 @@ RSpec.describe BulkUpload::Sales::Validator do context "when file is empty" do it "is not valid" do expect(validator).not_to be_valid + expect(validator.errors["base"]).to eql(["Template is blank - The template must be filled in for us to create the logs and check if data is correct."]) end end