From 3f69e1a6836ac86b796f04a81bd0410e2886b4e2 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Mon, 5 Feb 2024 11:08:44 +0000 Subject: [PATCH] Explicitly ensure soctenant nil for non shared ownership in bulk upload --- .../bulk_upload/sales/year2024/row_parser.rb | 2 + .../sales/year2024/row_parser_spec.rb | 50 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 906785ed1..368ec0b56 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -1119,6 +1119,8 @@ private end def infer_soctenant_from_prevten_and_prevtenbuy2 + return unless shared_ownership? + if [1, 2].include?(field_61) || [1, 2].include?(field_71.to_i) 1 else 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 a6049c12a..61e5edb61 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1136,36 +1136,54 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end describe "#soctenant" do - context "when prevten is a social housing type" do - let(:attributes) { valid_attributes.merge({ field_61: "1" }) } + context "when discounted ownership" do + let(:attributes) { valid_attributes.merge({ field_8: "2" }) } - it "is set to yes" do - expect(parser.log.soctenant).to be(1) + it "is set to nil" do + expect(parser.log.soctenant).to be_nil end end - context "when prevten is not a social housing type" do - context "and prevtenbuy2 is a social housing type" do - let(:attributes) { valid_attributes.merge({ field_61: "3", field_71: "2" }) } + context "when outright sale" do + let(:attributes) { valid_attributes.merge({ field_8: "3" }) } + + it "is set to nil" do + expect(parser.log.soctenant).to be_nil + end + end + + context "when shared ownership" do + context "when prevten is a social housing type" do + let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "1" }) } it "is set to yes" do expect(parser.log.soctenant).to be(1) end end - context "and prevtenbuy2 is not a social housing type" do - let(:attributes) { valid_attributes.merge({ field_61: "3", field_71: "4" }) } + context "when prevten is not a social housing type" do + context "and prevtenbuy2 is a social housing type" do + let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: "2" }) } - it "is set to no" do - expect(parser.log.soctenant).to be(2) + it "is set to yes" do + expect(parser.log.soctenant).to be(1) + end end - end - context "and prevtenbuy2 is blank" do - let(:attributes) { valid_attributes.merge({ field_61: "3", field_71: nil }) } + context "and prevtenbuy2 is not a social housing type" do + let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: "4" }) } - it "is set to no" do - expect(parser.log.soctenant).to be(2) + it "is set to no" do + expect(parser.log.soctenant).to be(2) + end + end + + context "and prevtenbuy2 is blank" do + let(:attributes) { valid_attributes.merge({ field_8: "1", field_61: "3", field_71: nil }) } + + it "is set to no" do + expect(parser.log.soctenant).to be(2) + end end end end