From 6b394d835db81b33ae94300f6cf94d2143e9f73b Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Mon, 2 Feb 2026 11:49:53 +0000 Subject: [PATCH] CLDC-4190: Add tests --- .../lettings/year2026/row_parser_spec.rb | 246 +++++++++++++++++- 1 file changed, 236 insertions(+), 10 deletions(-) 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 ff5df6bc4..c2f54c18c 100644 --- a/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2026/row_parser_spec.rb @@ -222,9 +222,6 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do field_115: "2", field_116: "1", - field_130: "1", - field_131: "1", - field_132: "1", field_117: "1", field_118: "2", @@ -623,12 +620,12 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do end context "when an invalid value error has been added" do - let(:attributes) { setup_section_params.merge({ field_116: "100" }) } + let(:attributes) { setup_section_params.merge({ field_115: "100" }) } it "does not add an additional error" do parser.valid? - expect(parser.errors[:field_116].length).to eq(1) - expect(parser.errors[:field_116]).to include(match I18n.t("validations.lettings.2026.bulk_upload.invalid_option", question: "")) + expect(parser.errors[:field_115].length).to eq(1) + expect(parser.errors[:field_115]).to include(match I18n.t("validations.lettings.2026.bulk_upload.invalid_option", question: "")) end end end @@ -1135,10 +1132,239 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do end end - # TODO: CLDC-4191: Add tests for the new referral fields - # describe "#field_116" do # referral - # - # end + describe "#field_116, field_130, field_131, field_132" do # referral + context "when org is LA" do + let(:owning_org) { create(:organisation, :la, :with_old_visible_id) } + + let(:org_attributes) { { bulk_upload:, field_1: owning_org.old_visible_id } } + + context "and not renewal" do + let(:renewal_attributes) { org_attributes.merge({ field_7: nil }) } + + context "and field_116 is valid" do + let(:attributes) { renewal_attributes.merge({ field_116: 1 }) } + + it "does not add an error" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + end + + context "and field_116 is invalid" do + let(:attributes) { renewal_attributes.merge({ field_116: 5 }) } # PRP option + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_116 is blank" do + let(:attributes) { renewal_attributes.merge({ field_116: nil }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and other fields are given" do + let(:attributes) { renewal_attributes.merge({ field_116: 1, field_130: 5, field_131: 1, field_132: 1 }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + end + + context "and is renewal" do + let(:attributes) { org_attributes.merge({ field_7: 1, field_116: 1, field_130: 5, field_131: 1, field_132: 1 }) } + + it "does not add an error for referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + end + end + + context "when org is PRP" do + let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) } + + let(:org_attributes) { { bulk_upload:, field_1: owning_org.old_visible_id } } + + context "and not renewal" do + let(:renewal_attributes) { org_attributes.merge({ field_7: nil }) } + + context "and field_130 is valid" do + let(:attributes) { renewal_attributes.merge({ field_130: 5 }) } + + it "does not add an error" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + + context "and later fields are given" do + let(:attributes) { renewal_attributes.merge({ field_130: 5, field_131: 1, field_132: 1 }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + end + + context "and field_130 is invalid" do + let(:attributes) { renewal_attributes.merge({ field_130: 1 }) } # LA option + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_130 is blank" do + let(:attributes) { renewal_attributes.merge({ field_130: nil }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_130 expects an answer for field_131" do + let(:field_130_attributes) { renewal_attributes.merge({ field_130: 6 }) } + + context "and field_131 is valid" do + let(:attributes) { field_130_attributes.merge({ field_131: 2 }) } + + it "does not add an error" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + + context "and later fields are given" do + let(:attributes) { field_130_attributes.merge({ field_131: 2, field_132: 1 }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + end + + context "and field_131 is invalid" do + let(:attributes) { field_130_attributes.merge({ field_131: 5 }) } # needs field_130 to be 7 + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_131 is blank" do + let(:attributes) { field_130_attributes.merge({ field_131: nil }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_131 expects an answer for field_132" do + let(:field_131_attributes) { field_130_attributes.merge({ field_131: 1 }) } + + context "and field_132 is valid" do + let(:attributes) { field_131_attributes.merge({ field_132: 1 }) } + + it "does not add an error" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + end + + context "and field_132 is invalid" do + let(:attributes) { field_131_attributes.merge({ field_132: 11 }) } # needs field_131 to be 7 + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + + context "and field_132 is blank" do + let(:attributes) { field_131_attributes.merge({ field_132: nil }) } + + it "adds errors to all referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_present + expect(parser.errors[:field_130]).to be_present + expect(parser.errors[:field_131]).to be_present + expect(parser.errors[:field_132]).to be_present + end + end + end + end + end + + context "and is renewal" do + let(:attributes) { org_attributes.merge({ field_7: 1, field_116: 1, field_130: 5, field_131: 1, field_132: 1 }) } + + it "does not add an error for referral fields" do + parser.valid? + expect(parser.errors[:field_116]).to be_blank + expect(parser.errors[:field_130]).to be_blank + expect(parser.errors[:field_131]).to be_blank + expect(parser.errors[:field_132]).to be_blank + end + end + end + end describe "fields 7, 8, 9 => startdate" do context "when any one of these fields is blank" do