From 97e217069955ef384d6fe885ffaa4fa6cdc1dc4d Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Mon, 2 Mar 2026 15:19:29 +0000 Subject: [PATCH] CLDC-4012: Allow lower case letters for codes in BU (#3181) * CLDC-4012: Add case-sensitive function for 2025 * CLDC-4012: Add case-sensitive function for 2026 * CLDC-4012: Add tests * CLDC-4012: Remove integer attributes * fixup! CLDC-4012: Add tests move R overrides for integers to their own test * fixup! CLDC-4012: Add tests don't check field 58 * fixup! CLDC-4012: Add tests Co-authored-by: Oscar Richardson <116292912+oscar-richardson-softwire@users.noreply.github.com> --------- Co-authored-by: Oscar Richardson <116292912+oscar-richardson-softwire@users.noreply.github.com> --- .../lettings/year2025/row_parser.rb | 29 +++++++++++++++++ .../lettings/year2026/row_parser.rb | 29 +++++++++++++++++ .../bulk_upload/sales/year2025/row_parser.rb | 31 +++++++++++++++++++ .../bulk_upload/sales/year2026/row_parser.rb | 31 +++++++++++++++++++ .../lettings/year2025/row_parser_spec.rb | 14 +++++++++ .../lettings/year2026/row_parser_spec.rb | 14 +++++++++ .../sales/year2025/row_parser_spec.rb | 14 +++++++++ .../sales/year2026/row_parser_spec.rb | 14 +++++++++ 8 files changed, 176 insertions(+) diff --git a/app/services/bulk_upload/lettings/year2025/row_parser.rb b/app/services/bulk_upload/lettings/year2025/row_parser.rb index 9887c42be..5d132d3ef 100644 --- a/app/services/bulk_upload/lettings/year2025/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2025/row_parser.rb @@ -148,6 +148,26 @@ class BulkUpload::Lettings::Year2025::RowParser ERROR_BASE_KEY = "validations.lettings.2025.bulk_upload".freeze + CASE_INSENSITIVE_FIELDS = [ + :field_42, # What is the lead tenant’s age? + :field_48, # What is person 2’s age? + :field_52, # What is person 3’s age? + :field_56, # What is person 4’s age? + :field_60, # What is person 5’s age? + :field_64, # What is person 6’s age? + :field_68, # What is person 7’s age? + :field_72, # What is person 8’s age? + + :field_43, # Which of these best describes the lead tenant’s gender identity? + :field_49, # Which of these best describes person 2’s gender identity? + :field_53, # Which of these best describes person 3’s gender identity? + :field_57, # Which of these best describes person 4’s gender identity? + :field_61, # Which of these best describes person 5’s gender identity? + :field_65, # Which of these best describes person 6’s gender identity? + :field_69, # Which of these best describes person 7’s gender identity? + :field_73, # Which of these best describes person 8’s gender identity? + ].freeze + attribute :bulk_upload attribute :block_log_creation, :boolean, default: -> { false } @@ -459,6 +479,8 @@ class BulkUpload::Lettings::Year2025::RowParser return @valid = true if blank_row? + normalise_case_insensitive_fields + super(:before_log) @before_errors = errors.dup @@ -560,6 +582,13 @@ class BulkUpload::Lettings::Year2025::RowParser private + def normalise_case_insensitive_fields + CASE_INSENSITIVE_FIELDS.each do |field| + value = send(field) + send("#{field}=", value.upcase) if value.present? + end + end + def validate_valid_radio_option log.attributes.each_key do |question_id| question = log.form.get_question(question_id, log) diff --git a/app/services/bulk_upload/lettings/year2026/row_parser.rb b/app/services/bulk_upload/lettings/year2026/row_parser.rb index 87d6bb526..577a48190 100644 --- a/app/services/bulk_upload/lettings/year2026/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2026/row_parser.rb @@ -166,6 +166,26 @@ class BulkUpload::Lettings::Year2026::RowParser ERROR_BASE_KEY = "validations.lettings.2026.bulk_upload".freeze + CASE_INSENSITIVE_FIELDS = [ + :field_41, # What is the lead tenant's age? + :field_48, # What is person 2's age? + :field_54, # What is person 3's age? + :field_60, # What is person 4's age? + :field_66, # What is person 5's age? + :field_72, # What is person 6's age? + :field_78, # What is person 7's age? + :field_84, # What is person 8's age? + + :field_42, # What is the lead tenant's sex? + :field_50, # What is person 2's sex? + :field_56, # What is person 3's sex? + :field_62, # What is person 4's sex? + :field_68, # What is person 5's sex? + :field_74, # What is person 6's sex? + :field_80, # What is person 7's sex? + :field_86, # What is person 8's sex? + ].freeze + attribute :bulk_upload attribute :block_log_creation, :boolean, default: -> { false } @@ -494,6 +514,8 @@ class BulkUpload::Lettings::Year2026::RowParser return @valid = true if blank_row? + normalise_case_insensitive_fields + super(:before_log) @before_errors = errors.dup @@ -600,6 +622,13 @@ class BulkUpload::Lettings::Year2026::RowParser private + def normalise_case_insensitive_fields + CASE_INSENSITIVE_FIELDS.each do |field| + value = send(field) + send("#{field}=", value.upcase) if value.present? + end + end + def validate_valid_radio_option log.attributes.each_key do |question_id| question = log.form.get_question(question_id, log) diff --git a/app/services/bulk_upload/sales/year2025/row_parser.rb b/app/services/bulk_upload/sales/year2025/row_parser.rb index 19094f6c6..19ad2cb1b 100644 --- a/app/services/bulk_upload/sales/year2025/row_parser.rb +++ b/app/services/bulk_upload/sales/year2025/row_parser.rb @@ -139,6 +139,28 @@ class BulkUpload::Sales::Year2025::RowParser ERROR_BASE_KEY = "validations.sales.2025.bulk_upload".freeze + CASE_INSENSITIVE_FIELDS = [ + :field_28, # Age of buyer 1 + :field_35, # Age of person 2 + :field_43, # Age of person 3 + :field_47, # Age of person 4 + :field_51, # Age of person 5 + :field_55, # Age of person 6 + + :field_29, # Gender identity of buyer 1 + :field_36, # Gender identity of person 2 + :field_44, # Gender identity of person 3 + :field_48, # Gender identity of person 4 + :field_52, # Gender identity of person 5 + :field_56, # Gender identity of person 6 + + :field_64, # What was buyer 2’s previous tenure? + + :field_75, # What is the total amount the buyers had in savings before they paid any deposit for the property? + :field_70, # What is buyer 1’s gross annual income? + :field_72, # What is buyer 2’s gross annual income? + ].freeze + attribute :bulk_upload attribute :block_log_creation, :boolean, default: -> { false } @@ -454,6 +476,8 @@ class BulkUpload::Sales::Year2025::RowParser return true if blank_row? + normalise_case_insensitive_fields + super(:before_log) @before_errors = errors.dup @@ -525,6 +549,13 @@ class BulkUpload::Sales::Year2025::RowParser private + def normalise_case_insensitive_fields + CASE_INSENSITIVE_FIELDS.each do |field| + value = send(field) + send("#{field}=", value.upcase) if value.present? + end + end + def prevtenbuy2 case field_64 when "R" diff --git a/app/services/bulk_upload/sales/year2026/row_parser.rb b/app/services/bulk_upload/sales/year2026/row_parser.rb index efba9967e..5fd6caada 100644 --- a/app/services/bulk_upload/sales/year2026/row_parser.rb +++ b/app/services/bulk_upload/sales/year2026/row_parser.rb @@ -147,6 +147,28 @@ class BulkUpload::Sales::Year2026::RowParser ERROR_BASE_KEY = "validations.sales.2026.bulk_upload".freeze + CASE_INSENSITIVE_FIELDS = [ + :field_28, # Age of buyer 1 + :field_35, # Age of person 2 + :field_43, # Age of person 3 + :field_47, # Age of person 4 + :field_51, # Age of person 5 + :field_55, # Age of person 6 + + :field_122, # Buyer 1's sex, as registered at birth + :field_123, # Buyer/Person 2's sex, as registered at birth + :field_124, # Person 3's sex, as registered at birth + :field_125, # Person 4's sex, as registered at birth + :field_126, # Person 5's sex, as registered at birth + :field_127, # Person 6's sex, as registered at birth + + :field_64, # What was buyer 2’s previous tenure? + + :field_75, # What is the total amount the buyers had in savings before they paid any deposit for the property? + :field_70, # What is buyer 1’s gross annual income? + :field_72, # What is buyer 2’s gross annual income? + ].freeze + attribute :bulk_upload attribute :block_log_creation, :boolean, default: -> { false } @@ -470,6 +492,8 @@ class BulkUpload::Sales::Year2026::RowParser return true if blank_row? + normalise_case_insensitive_fields + super(:before_log) @before_errors = errors.dup @@ -542,6 +566,13 @@ class BulkUpload::Sales::Year2026::RowParser private + def normalise_case_insensitive_fields + CASE_INSENSITIVE_FIELDS.each do |field| + value = send(field) + send("#{field}=", value.upcase) if value.present? + end + end + def prevtenbuy2 case field_64 when "R" diff --git a/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb index e8fe5cf8e..fcc4e9f46 100644 --- a/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2025/row_parser_spec.rb @@ -541,6 +541,20 @@ RSpec.describe BulkUpload::Lettings::Year2025::RowParser do end end end + + context "and case insensitive fields are set to lowercase" do + let(:case_insensitive_fields) { %w[field_43 field_49 field_53 field_57 field_61 field_65 field_69 field_73] } + let(:case_insensitive_integer_fields_with_r_option) { %w[field_42 field_48 field_52 field_56 field_60 field_64 field_68 field_72] } + let(:attributes) do + valid_attributes + .merge(case_insensitive_fields.each_with_object({}) { |field, h| h[field.to_sym] = valid_attributes[field.to_sym]&.downcase }) + .merge(case_insensitive_integer_fields_with_r_option.each_with_object({}) { |field, h| h[field.to_sym] = "r" }) + end + + it "is still valid" do + expect(parser).to be_valid + end + end end context "when valid row with valid decimal (integer) field_11" do diff --git a/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb index d2e7fb797..27c8b7672 100644 --- a/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb @@ -434,6 +434,20 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do end end end + + context "and case insensitive fields are set to lowercase" do + let(:case_insensitive_fields) { %w[field_42 field_50 field_56 field_62 field_68 field_74 field_80 field_86] } + let(:case_insensitive_integer_fields_with_r_option) { %w[field_41 field_48 field_54 field_60 field_66 field_72 field_78 field_84] } + let(:attributes) do + valid_attributes + .merge(case_insensitive_fields.each_with_object({}) { |field, h| h[field.to_sym] = valid_attributes[field.to_sym]&.downcase }) + .merge(case_insensitive_integer_fields_with_r_option.each_with_object({}) { |field, h| h[field.to_sym] = "r" }) + end + + it "is still valid" do + expect(parser).to be_valid + end + end end context "when valid row with valid decimal (integer) field_11" do diff --git a/spec/services/bulk_upload/sales/year2025/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2025/row_parser_spec.rb index 6306249eb..ebebc38b8 100644 --- a/spec/services/bulk_upload/sales/year2025/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2025/row_parser_spec.rb @@ -292,6 +292,20 @@ RSpec.describe BulkUpload::Sales::Year2025::RowParser do expect(questions.map(&:id).size).to eq(0) expect(questions.map(&:id)).to eql([]) end + + context "and case insensitive fields are set to lowercase" do + let(:case_insensitive_fields) { %w[field_29 field_36 field_44 field_48 field_52 field_56] } + let(:case_insensitive_integer_fields_with_r_option) { %w[field_28 field_35 field_43 field_47 field_51 field_55 field_64 field_75 field_70 field_72] } + let(:attributes) do + valid_attributes + .merge(case_insensitive_fields.each_with_object({}) { |field, h| h[field.to_sym] = valid_attributes[field.to_sym]&.downcase }) + .merge(case_insensitive_integer_fields_with_r_option.each_with_object({}) { |field, h| h[field.to_sym] = "r" }) + end + + it "is still valid" do + expect(parser).to be_valid + end + end end describe "#validate_nulls" do diff --git a/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb index 9b93f7413..3b991ac26 100644 --- a/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2026/row_parser_spec.rb @@ -299,6 +299,20 @@ RSpec.describe BulkUpload::Sales::Year2026::RowParser do expect(questions.map(&:id).size).to eq(0) expect(questions.map(&:id)).to eql([]) end + + context "and case insensitive fields are set to lowercase" do + let(:case_insensitive_fields) { %w[field_122 field_123 field_124 field_125 field_126 field_127] } + let(:case_insensitive_integer_fields_with_r_option) { %w[field_28 field_35 field_43 field_47 field_51 field_55 field_64 field_75 field_70 field_72] } + let(:attributes) do + valid_attributes + .merge(case_insensitive_fields.each_with_object({}) { |field, h| h[field.to_sym] = valid_attributes[field.to_sym]&.downcase }) + .merge(case_insensitive_integer_fields_with_r_option.each_with_object({}) { |field, h| h[field.to_sym] = "r" }) + end + + it "is still valid" do + expect(parser).to be_valid + end + end end describe "#validate_nulls" do