From ea59d036d298860b94245057216ad663e0c2fac4 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 17 May 2023 15:08:57 +0100 Subject: [PATCH] CLDC-2347 Set monthly charges for bulk upload (#1629) * Infer has mscharge as no if it's 0 for 22/23 * Infer has mscharge as no if it's 0 for 23/24 --- .../bulk_upload/sales/year2022/row_parser.rb | 4 +-- .../bulk_upload/sales/year2023/row_parser.rb | 4 +-- .../sales/year2022/row_parser_spec.rb | 30 +++++++++++++++++++ .../sales/year2023/row_parser_spec.rb | 30 +++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index d1f31ecd7..4fba0d53a 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -592,8 +592,8 @@ private attributes["deposit"] = deposit attributes["cashdis"] = field_73 attributes["mrent"] = field_74 - attributes["has_mscharge"] = mscharge.present? ? 1 : 0 - attributes["mscharge"] = mscharge + attributes["mscharge"] = mscharge if mscharge&.positive? + attributes["has_mscharge"] = attributes["mscharge"].present? ? 1 : 0 attributes["grant"] = field_78 attributes["discount"] = field_79 diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 741536f61..cb65fa94c 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -803,8 +803,8 @@ private attributes["cashdis"] = field_112 attributes["mrent"] = field_113 - attributes["has_mscharge"] = mscharge.present? ? 1 : 0 - attributes["mscharge"] = mscharge + attributes["mscharge"] = mscharge if mscharge&.positive? + attributes["has_mscharge"] = attributes["mscharge"].present? ? 1 : 0 attributes["grant"] = field_117 attributes["discount"] = field_118 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 1fc85ebb5..8ff75852e 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -646,5 +646,35 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do expect(log["wheel"]).to eq(1) end end + + context "when mscharge is given, but is set to 0 for shared ownership" do + let(:attributes) { valid_attributes.merge(field_75: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end + + context "when mscharge is given, but is set to 0 for discounted ownership" do + let(:attributes) { valid_attributes.merge(field_113: "2", field_76: "8", field_83: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end + + context "when mscharge is given, but is set to 0 for outright sale" do + let(:attributes) { valid_attributes.merge(field_113: "3", field_91: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end end 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 ecbd457fb..d49d78f4d 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -852,5 +852,35 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(parser.log.proplen).to be_nil end end + + context "when mscharge is given, but is set to 0 for shared ownership" do + let(:attributes) { valid_attributes.merge(field_114: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end + + context "when mscharge is given, but is set to 0 for discounted ownership" do + let(:attributes) { valid_attributes.merge(field_7: "2", field_126: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end + + context "when mscharge is given, but is set to 0 for outright sale" do + let(:attributes) { valid_attributes.merge(field_7: "3", field_135: "0") } + + it "does not override variables correctly" do + log = parser.log + expect(log["has_mscharge"]).to eq(0) # no + expect(log["mscharge"]).to be_nil + end + end end end