From 7c30c3386893cc27abe95e16e203090e818394f6 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:21:55 +0000 Subject: [PATCH] CLDC-3283 Validate allocation values (#2294) * Validate allocation values for 2024 * Validate allocation values for 2023 --- .../lettings/year2023/row_parser.rb | 24 +++++++++ .../lettings/year2024/row_parser.rb | 32 +++++++++++ .../lettings/year2023/row_parser_spec.rb | 27 ++++++++++ .../lettings/year2024/row_parser_spec.rb | 54 +++++++++++++++++++ 4 files changed, 137 insertions(+) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 9fda600b5..3c48bc141 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -337,6 +337,30 @@ class BulkUpload::Lettings::Year2023::RowParser }, 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_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? } diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index ba19acb8c..d2e0d88ca 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/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? } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 7435a3d74..a5dd076aa 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/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) 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 describe "#chr" do @@ -2015,6 +2024,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.log.chr).to be(0) 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 describe "#cap" do @@ -2033,6 +2051,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.log.cap).to be(0) 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 describe "#letting_allocation_unknown" do diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index 7b15d4381..733bb6b6c 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/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) 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 @@ -1907,6 +1916,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 @@ -1925,6 +1943,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