From aca9eb630162648a69515b796200b4b1c9e5f8c7 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:32:00 +0000 Subject: [PATCH] CLDC-3300 Update BU mortgageused error (#2310) * Don't allow don't know as 2023 mortgageused * Don't allow don't know as 2023 mortgageused for discounted ownership * Allow mortgageused don't know if stairowned 100 * Update row parser test * Move mortgageused validations onto the log model * Allor outright sale mortgageused 3, don't allow non staircaseing shared ownership mortgageused 3 * Rebase fix --- .../sales/sale_information_validations.rb | 15 ++- .../bulk_upload/sales/year2024/row_parser.rb | 8 -- .../sale_information_validations_spec.rb | 5 +- .../sales/year2023/row_parser_spec.rb | 114 ++++++++++++++++-- .../sales/year2024/row_parser_spec.rb | 59 +++++++-- 5 files changed, 171 insertions(+), 30 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 66ca8b1a0..883e10d1d 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -150,11 +150,24 @@ module Validations::Sales::SaleInformationValidations def validate_mortgage_used_and_stairbought(record) return unless record.stairowned && record.mortgageused - return unless record.saledate && record.form.start_year_after_2024? if !record.stairowned_100? && record.mortgageused == 3 record.errors.add :stairowned, I18n.t("validations.sale_information.stairowned.mortgageused_dont_know") record.errors.add :mortgageused, I18n.t("validations.sale_information.stairowned.mortgageused_dont_know") end end + + def validate_mortgage_used_dont_know(record) + return unless record.mortgageused == 3 + + if record.discounted_ownership_sale? + record.errors.add(:mortgageused, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property?")) + end + if record.outright_sale? && record.saledate && !record.form.start_year_after_2024? + record.errors.add(:mortgageused, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property?")) + end + if record.shared_ownership_scheme? && record.staircase && record.staircase != 1 + record.errors.add(:mortgageused, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property?")) + end + end end diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 682464331..928060dfa 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -341,14 +341,6 @@ class BulkUpload::Sales::Year2024::RowParser }, on: :before_log - validates :field_103, - inclusion: { - in: [1, 2], - if: proc { field_88.present? && field_88 != 100 && shared_ownership? }, - question: QUESTIONS[:field_103], - }, - on: :before_log - validates :field_9, presence: { message: I18n.t("validations.not_answered", question: "type of shared ownership sale"), diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 9ae84834c..ca07da6f4 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -1010,10 +1010,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do let(:record) { build(:sales_log, ownershipsch: 1, type: 9, saledate: now, mortgageused: 3, stairowned: 90) } let(:now) { Time.zone.local(2023, 4, 4) } - it "does not add an error" do + it "adds an error" do sale_information_validator.validate_mortgage_used_and_stairbought(record) - expect(record.errors).to be_empty + expect(record.errors[:stairowned]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") + expect(record.errors[:mortgageused]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") end end end diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index bca7ed817..263b5b8c9 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -981,18 +981,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end end - describe "#field_119" do - context "when validate_discounted_ownership_value is triggered" do - let(:attributes) { setup_section_params.merge(field_116: 100, field_125: 100, field_7: 2, field_9: 9, field_119: 2, field_118: 10) } - - it "only adds errors to the discounted ownership field" do - expect(parser.errors[:field_105]).to be_empty - expect(parser.errors[:field_119]).to include("Mortgage, deposit, and grant total must equal £90.00. Your given mortgage, deposit and grant total is £100.00") - expect(parser.errors[:field_128]).to be_empty - end - end - end - describe "soft validations" do context "when soft validation is triggered" do let(:attributes) { valid_attributes.merge({ field_30: 22, field_35: 5 }) } @@ -1020,6 +1008,108 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end end end + + describe "#field_105" do + context "when invalid value" do + let(:attributes) { setup_section_params.merge(field_105: "4") } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end + + context "when value is 3 and stairowned is not 100" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "1", field_88: "50", field_89: "99", field_111: nil) } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end + + context "when value is 3 and stairowned is not answered" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "1", field_88: "50", field_89: nil, field_111: nil) } + + it "does not add errors" do + expect(parser.errors[:field_105]).not_to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + expect(parser.errors[:field_105]).not_to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") + end + end + + context "when value is 3 and stairowned is 100" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "1", field_88: "50", field_89: "100", field_111: nil) } + + it "does not add errors" do + expect(parser.errors[:field_105]).to be_empty + expect(parser.errors[:field_119]).to be_empty + expect(parser.errors[:field_128]).to be_empty + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to eq(3) + end + end + + context "when it is not a staircasing transaction" do + context "when value is 3 and stairowned is not answered" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "2", field_88: "50", field_89: nil, field_111: nil) } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end + + context "when value is 3 and stairowned is 100" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "2", field_88: "50", field_89: "100", field_111: nil) } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end + end + end + + describe "#field_119" do + let(:attributes) { valid_attributes.merge({ field_7: "2", field_9: "8", field_119: "3" }) } + + it "does not allow 3 (don't know) as an option for discounted ownership" do + expect(parser.errors[:field_119]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + + context "when validate_discounted_ownership_value is triggered" do + let(:attributes) { setup_section_params.merge(field_116: 100, field_125: 100, field_7: 2, field_9: 9, field_119: 2, field_118: 10) } + + it "only adds errors to the discounted ownership field" do + expect(parser.errors[:field_105]).to be_empty + expect(parser.errors[:field_119]).to include("Mortgage, deposit, and grant total must equal £90.00. Your given mortgage, deposit and grant total is £100.00") + expect(parser.errors[:field_128]).to be_empty + end + end + end + + describe "#field_128" do + let(:attributes) { valid_attributes.merge({ field_7: "3", field_10: "10", field_128: "3", field_12: "2" }) } + + it "does not allow 3 (don't know) as an option for outright sale" do + expect(parser.errors[:field_128]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end end describe "#log" do diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index df6ed7764..ea0ea386e 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -998,6 +998,9 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "returns correct errors" do expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil end end @@ -1005,7 +1008,10 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "1", field_87: "50", field_88: "99", field_109: nil) } it "returns correct errors" do - expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + expect(parser.errors[:field_103]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil end end @@ -1013,15 +1019,32 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "1", field_87: "50", field_88: nil, field_109: nil) } it "does not add errors" do - expect(parser.errors[:field_103]).not_to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + expect(parser.errors[:field_103]).not_to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") + expect(parser.errors[:field_103]).not_to include("Enter a valid value for Was a mortgage used for the purchase of this property?") end end - context "when it's not shared ownership" do - let(:attributes) { setup_section_params.merge(field_8: "2", field_103: "3", field_86: "1", field_87: "50", field_88: "99", field_109: nil) } + context "when it is not a staircasing transaction" do + context "when value is 3 and stairowned is not answered" do + let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "2", field_87: "50", field_88: nil, field_109: nil) } - it "does not add errors" do - expect(parser.errors[:field_103]).not_to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + it "returns correct errors" do + expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + end + + context "when value is 3 and stairowned is 100" do + let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "2", field_87: "50", field_88: "100", field_109: nil) } + + it "returns correct errors" do + expect(parser.errors[:field_103]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end end end @@ -1039,6 +1062,15 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end describe "#field_117" do + let(:attributes) { valid_attributes.merge({ field_8: "2", field_10: "9", field_117: "3" }) } + + it "does not allow 3 (don't know) as an option for discounted ownership" do + expect(parser.errors[:field_117]).to include("Enter a valid value for Was a mortgage used for the purchase of this property?") + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to be_nil + end + context "when validate_discounted_ownership_value is triggered" do let(:attributes) { setup_section_params.merge(field_114: 100, field_123: 100, field_8: 2, field_10: 9, field_117: 2, field_116: 10) } @@ -1050,6 +1082,19 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "#field_126" do + let(:attributes) { valid_attributes.merge({ field_8: "3", field_11: "10", field_126: "3", field_13: "2" }) } + + it "allows 3 (don't know) as an option for outright sale" do + expect(parser.errors[:field_126]).to be_empty + expect(parser.errors[:field_103]).to be_empty + expect(parser.errors[:field_117]).to be_empty + parser.log.blank_invalid_non_setup_fields! + parser.log.save! + expect(parser.log.mortgageused).to eq(3) + end + end + describe "soft validations" do context "when soft validation is triggered" do let(:attributes) { valid_attributes.merge({ field_31: 22, field_35: 5 }) } @@ -1061,7 +1106,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "populates with correct error message" do expect(parser.errors.where(:field_31, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") - expect(parser.errors.where(:field_31, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") + expect(parser.errors.where(:field_35, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") end end end