From f603758194765b2de3817425e8968e25a83c1cb3 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 2 May 2023 16:20:08 +0100 Subject: [PATCH] add bulk upload sales 23 buyer2 ethnic fields --- .../bulk_upload/sales/year2023/row_parser.rb | 20 +++++++++++++++++++ .../sales/year2023/row_parser_spec.rb | 16 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 02c7e8c48..899f9522a 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -407,6 +407,23 @@ class BulkUpload::Sales::Year2023::RowParser private + def infer_buyer2_ethnic_group_from_ethnic + case field_40 + when 1, 2, 3, 18 + 0 + when 4, 5, 6, 7 + 1 + when 8, 9, 10, 11, 15 + 2 + when 12, 13, 14 + 3 + when 16, 19 + 4 + else + field_40 + end + end + def validate_uprn_exists_if_any_key_adddress_fields_are_blank if field_19.blank? && (field_20.blank? || field_22.blank? || field_24.blank? || field_25.blank?) errors.add(:field_19, I18n.t("validations.not_answered", question: "UPRN")) @@ -735,6 +752,9 @@ private attributes["town_or_city"] = field_22 attributes["county"] = field_23 + attributes["ethnic_group2"] = infer_buyer2_ethnic_group_from_ethnic + attributes["ethnicbuy2"] = field_40 + attributes 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 25a234dcb..475a8703f 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -627,5 +627,21 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(parser.log.county).to eql("some county") end end + + describe "#ethnic_group2" do + let(:attributes) { setup_section_params.merge({ field_40: "1" }) } + + it "is correctly set" do + expect(parser.log.ethnic_group2).to be(0) + end + end + + describe "#ethnicbuy2" do + let(:attributes) { setup_section_params.merge({ field_40: "1" }) } + + it "is correctly set" do + expect(parser.log.ethnicbuy2).to be(1) + end + end end end