Browse Source

CLDC-3283 Validate allocation values (#2294)

* Validate allocation values for 2024

* Validate allocation values for 2023
pull/2278/head^2
kosiakkatrina 10 months ago committed by GitHub
parent
commit
7c30c33868
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  2. 32
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  3. 27
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  4. 54
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

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

@ -337,6 +337,30 @@ class BulkUpload::Lettings::Year2023::RowParser
}, },
on: :after_log on: :after_log
validates :field_116,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Choice-Based Lettings (CBL)"),
if: -> { field_116.present? },
},
on: :after_log
validates :field_117,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Allocation Policy (CAP)"),
if: -> { field_117.present? },
},
on: :after_log
validates :field_118,
inclusion: {
in: [1, 2],
message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Housing Register (CHR)"),
if: -> { field_118.present? },
},
on: :after_log
validates :field_46, 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_46, 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_52, 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 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? }
validates :field_56, 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? } validates :field_56, 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? }

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

@ -337,6 +337,38 @@ class BulkUpload::Lettings::Year2024::RowParser
}, },
on: :after_log 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_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_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? } 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? }

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

@ -1997,6 +1997,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.log.cbl).to be(0) expect(parser.log.cbl).to be(0)
end end
end end
context "when field_116 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_116: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_116]).to include("Enter a valid value for was the letting made under the Choice-Based Lettings (CBL)")
end
end
end end
describe "#chr" do describe "#chr" do
@ -2015,6 +2024,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.log.chr).to be(0) expect(parser.log.chr).to be(0)
end end
end end
context "when field_118 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_118: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_118]).to include("Enter a valid value for was the letting made under the Common Housing Register (CHR)")
end
end
end end
describe "#cap" do describe "#cap" do
@ -2033,6 +2051,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser.log.cap).to be(0) expect(parser.log.cap).to be(0)
end end
end end
context "when field_117 is not a permitted value" do
let(:attributes) { { bulk_upload:, field_117: 3 } }
it "adds an error" do
parser.valid?
expect(parser.errors[:field_117]).to include("Enter a valid value for was the letting made under the Common Allocation Policy (CAP)")
end
end
end end
describe "#letting_allocation_unknown" do describe "#letting_allocation_unknown" do

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

@ -1889,6 +1889,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.cbl).to be(0) expect(parser.log.cbl).to be(0)
end end
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 end
describe "#chr" do describe "#chr" do
@ -1907,6 +1916,15 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.chr).to be(0) expect(parser.log.chr).to be(0)
end end
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 end
describe "#cap" do describe "#cap" do
@ -1925,6 +1943,42 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.log.cap).to be(0) expect(parser.log.cap).to be(0)
end end
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 end
describe "#letting_allocation_unknown" do describe "#letting_allocation_unknown" do

Loading…
Cancel
Save