Browse Source

CLDC-2474 Allow numeric fields to accept decimal representations in bulk upload (#1753)

* feat: allow decimals for lettings type when they only have trailing 0s and add tests

* refactor: linting

* refactor: DRY tests

* refactor: linting
pull/1767/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
960b633ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 2
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 24
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  4. 40
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

2
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -773,7 +773,7 @@ private
end
def validate_data_types
unless attribute_set["field_1"].value_before_type_cast&.match?(/\A\d+\z/)
unless attribute_set["field_1"].value_before_type_cast&.match?(/^\d+\.?0*$/)
errors.add(:field_1, I18n.t("validations.invalid_number", question: "letting type"))
end
end

2
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -702,7 +702,7 @@ private
end
def validate_data_types
unless attribute_set["field_5"].value_before_type_cast&.match?(/\A\d+\z/)
unless attribute_set["field_5"].value_before_type_cast&.match?(/^\d+\.?0*$/)
errors.add(:field_5, I18n.t("validations.invalid_number", question: "letting type"))
end
end

24
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -339,6 +339,30 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
end
end
context "when valid row with valid decimal (integer) field_1" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) { valid_attributes.merge(field_1: "1.00") }
it "returns true" do
expect(parser).to be_valid
end
end
context "when valid row with invalid decimal (non-integer) field_1" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) { valid_attributes.merge(field_1: "1.56") }
it "returns false" do
expect(parser).not_to be_valid
end
end
end
context "when setup section not complete" do

40
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -120,12 +120,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
context "when valid row" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) do
context "when testing valid/invalid attributes" do
let(:valid_attributes) do
{
bulk_upload:,
field_5: "1",
@ -250,6 +246,13 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
}
end
context "when valid row" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) { valid_attributes }
it "returns true" do
expect(parser).to be_valid
end
@ -376,6 +379,31 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
context "when valid row with valid decimal (integer) field_5" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) { valid_attributes.merge(field_5: "1.00") }
it "returns true" do
expect(parser).to be_valid
end
end
context "when valid row with invalid decimal (non-integer) field_5" do
before do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end
let(:attributes) { valid_attributes.merge(field_5: "1.56") }
it "returns false" do
expect(parser).not_to be_valid
end
end
end
describe "#validate_nulls" do
context "when non-setup questions are null" do
let(:attributes) { { bulk_upload:, field_1: "a", field_18: "", field_19: "", field_21: "" } }

Loading…
Cancel
Save