From 29980b1f7b5e269657fae8deb0c8cf70b9e73279 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:58:36 +0000 Subject: [PATCH] CLDC-3302 Make mortgageused bulk upload errors only display on relevant field (#2311) * feat: only add mortgageuesd error to relevant mortgageused field * feat: add test * feat: test * feat: test 2023 --- .../bulk_upload/sales/year2023/row_parser.rb | 8 +++++++- .../bulk_upload/sales/year2024/row_parser.rb | 8 +++++++- .../bulk_upload/sales/year2023/row_parser_spec.rb | 12 ++++++++++++ .../bulk_upload/sales/year2024/row_parser_spec.rb | 12 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 506bc7456..158efec57 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -754,7 +754,7 @@ private stairbought: %i[field_88], stairowned: %i[field_89], socprevten: %i[field_102], - mortgageused: %i[field_105 field_119 field_128], + mortgageused: [mortgageused_field], soctenant: %i[field_99], uprn: %i[field_19], @@ -1103,6 +1103,12 @@ private return field_128 if outright_sale? end + def mortgageused_field + return :field_105 if shared_ownership? + return :field_119 if discounted_ownership? + return :field_128 if outright_sale? + end + def owning_organisation @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_1) end diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 7a1481300..682464331 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -760,7 +760,7 @@ private stairbought: %i[field_87], stairowned: %i[field_88], socprevten: %i[field_100], - mortgageused: %i[field_103 field_117 field_126], + mortgageused: [mortgageused_field], uprn: %i[field_22], address_line1: %i[field_23], @@ -1116,6 +1116,12 @@ private return field_126 if outright_sale? end + def mortgageused_field + return :field_103 if shared_ownership? + return :field_117 if discounted_ownership? + return :field_126 if outright_sale? + end + def owning_organisation @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_1) 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 7fde3c99e..bca7ed817 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -981,6 +981,18 @@ 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 }) } 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 ce81300b5..df6ed7764 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1038,6 +1038,18 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "#field_117" do + 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) } + + it "only adds errors to the discounted ownership field" do + expect(parser.errors[:field_103]).to be_empty + expect(parser.errors[:field_117]).to include("The mortgage, deposit, and grant when added together is £100.00, and the purchase purchase price times by the discount is £90.00. These figures should be the same") + expect(parser.errors[:field_126]).to be_empty + end + end + end + describe "soft validations" do context "when soft validation is triggered" do let(:attributes) { valid_attributes.merge({ field_31: 22, field_35: 5 }) }