Browse Source

Fix sales validator

pull/1795/head
Jack S 3 years ago
parent
commit
d8c8860116
  1. 2
      app/services/bulk_upload/sales/validator.rb
  2. 34
      spec/services/bulk_upload/lettings/validator_spec.rb
  3. 1
      spec/services/bulk_upload/sales/validator_spec.rb

2
app/services/bulk_upload/sales/validator.rb

@ -139,7 +139,7 @@ private
def validate_file_not_empty def validate_file_not_empty
if File.size(path).zero? || csv_parser.row_parsers.empty? if File.size(path).zero? || csv_parser.row_parsers.empty?
errors.add(:file, :blank) errors.add(:base, :blank_file)
halt_validations! halt_validations!
end end

34
spec/services/bulk_upload/lettings/validator_spec.rb

@ -11,12 +11,6 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:file) { Tempfile.new } let(:file) { Tempfile.new }
describe "validations" do 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 context "when 2022" do
let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) } let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) }
@ -34,6 +28,13 @@ RSpec.describe BulkUpload::Lettings::Validator do
end end
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 context "and doesn't have too many columns" do
before do before do
file.write(("a" * 95).chars.join(",")) file.write(("a" * 95).chars.join(","))
@ -71,6 +72,13 @@ RSpec.describe BulkUpload::Lettings::Validator do
end end
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 context "and file has too few valid headers" do
let(:seed) { rand } let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) } let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
@ -128,6 +136,13 @@ RSpec.describe BulkUpload::Lettings::Validator do
end end
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 context "and doesn't have too many columns" do
before do before do
file.write(("a" * 142).chars.join(",")) file.write(("a" * 142).chars.join(","))
@ -142,6 +157,13 @@ RSpec.describe BulkUpload::Lettings::Validator do
end end
context "when file has headers" do 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 context "and file has extra invalid headers" do
let(:seed) { rand } let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) } let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }

1
spec/services/bulk_upload/sales/validator_spec.rb

@ -13,6 +13,7 @@ RSpec.describe BulkUpload::Sales::Validator do
context "when file is empty" do context "when file is empty" do
it "is not valid" do it "is not valid" do
expect(validator).not_to be_valid 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
end end

Loading…
Cancel
Save