Browse Source

Validate allocation values for 2024

pull/2294/head
Kat 2 years ago
parent
commit
4175a87c3f
  1. 32
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  2. 54
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

32
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -337,6 +337,38 @@ class BulkUpload::Lettings::Year2024::RowParser
},
on: :after_log
validates :field_112,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Choice-Based Lettings (CBL)"),
if: -> { field_112.present? },
},
on: :after_log
validates :field_113,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Allocation Policy (CAP)"),
if: -> { field_113.present? },
},
on: :after_log
validates :field_114,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Housing Register (CHR)"),
if: -> { field_114.present? },
},
on: :after_log
validates :field_115,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Accessible Register"),
if: -> { field_115.present? },
},
on: :after_log
validates :field_42, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log
validates :field_48, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? }
validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? }

54
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -1873,6 +1873,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.cbl).to be(0)
end
end
context "when field_112 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_112: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_112]).to include("Enter a valid value for was the letting made under the Choice-Based Lettings (CBL)")
end
end
end
describe "#chr" do
@ -1891,6 +1900,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.chr).to be(0)
end
end
context "when field_114 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_114: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_114]).to include("Enter a valid value for was the letting made under the Common Housing Register (CHR)")
end
end
end
describe "#cap" do
@ -1909,6 +1927,42 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.cap).to be(0)
end
end
context "when field_113 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_113: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_113]).to include("Enter a valid value for was the letting made under the Common Allocation Policy (CAP)")
end
end
end
describe "#accessible_register" do
context "when field_115 is yes ie 1" do
let(:attributes) { { bulk_upload:, field_115: 1 } }
it "sets value to 1" do
expect(parser.log.accessible_register).to be(1)
end
end
context "when field_115 is no ie 2" do
let(:attributes) { { bulk_upload:, field_115: 2 } }
it "sets value to 0" do
expect(parser.log.accessible_register).to be(0)
end
end
context "when field_115 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_115: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_115]).to include("Enter a valid value for was the letting made under the Accessible Register")
end
end
end
describe "#letting_allocation_unknown" do

Loading…
Cancel
Save