From e9998c8ea6f1466fccb9018624f1052f94fb4ffa Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 16 May 2023 08:49:23 +0100 Subject: [PATCH] Do not allow 32 as an option for 22/23 sale type --- .../bulk_upload/sales/year2022/row_parser.rb | 9 +++++++++ .../bulk_upload/sales/year2022/row_parser_spec.rb | 14 ++++++++++++++ .../bulk_upload/sales/year2023/row_parser_spec.rb | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 405975974..5f5834a63 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -287,6 +287,7 @@ class BulkUpload::Sales::Year2022::RowParser validate :validate_relevant_collection_window, on: :after_log validate :validate_incomplete_soft_validations, on: :after_log validate :validate_if_log_already_exists, on: :after_log, if: -> { FeatureToggle.bulk_upload_duplicate_log_check_enabled? } + validate :validate_shared_ownership_type, on: :after_log, if: :shared_ownership? def self.question_for_field(field) QUESTIONS[field] @@ -1028,4 +1029,12 @@ private errors.add(:field_24, "Buyer 1 cannot be a child under 16") end end + + def validate_shared_ownership_type + block_log_creation! + + if sale_type == 32 + errors.add(:field_8, I18n.t("validations.invalid_option", question: "shared ownership type"), category: :setup) + end + end end diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 53ecaa01a..f9a97f14d 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -622,6 +622,20 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do end end end + + describe "shared ownership sale type" do + context "when 32 is selected for shared ownership type" do + let(:attributes) { valid_attributes.merge(field_113: 1, field_57: "32") } + + it "is not permitted as a setup error" do + expect(parser.errors.where(:field_8, category: :setup)).to be_present + end + + it "blocks log creation" do + expect(parser).to be_block_log_creation + end + end + end end describe "inferences" do 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 4c248d7f2..878192034 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -931,5 +931,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(log["mscharge"]).to be_nil end end + + describe "shared ownership sale type" do + context "when 32 is selected for shared ownership type" do + let(:attributes) { valid_attributes.merge(field_8: "32") } + + it "sets the value correctly" do + log = parser.log + expect(log["type"]).to eq(32) + end + end + end end end