From 3f4cbc2010eb93381d273b6c88504ed29b838afb Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:20:20 +0000 Subject: [PATCH] Do not assign invalid postcode (#2855) * Do not assign invalid postcode * Make postcode full required if routed to * Update tests --- app/models/lettings_log.rb | 3 +-- app/models/log.rb | 2 +- app/models/sales_log.rb | 3 +-- spec/features/lettings_log_spec.rb | 27 +++++++++++++++++++++++++++ spec/features/sales_log_spec.rb | 27 +++++++++++++++++++++++++++ spec/models/lettings_log_spec.rb | 14 -------------- spec/models/sales_log_spec.rb | 16 ---------------- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index d1ff6f738..67cafb75b 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -779,8 +779,7 @@ private not_required << "previous_la_known" if postcode_known? not_required << "tshortfall" if tshortfall_unknown? not_required << "tenancylength" if tenancylength_optional? - - not_required |= %w[address_line2 county postcode_full] if startdate && collection_start_year_for_date(startdate) >= 2023 + not_required += %w[address_line2 county] not_required end diff --git a/app/models/log.rb b/app/models/log.rb index 5a9bde77e..94f0ff58d 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -110,7 +110,7 @@ class Log < ApplicationRecord self.address_line2 = nil self.town_or_city = nil self.county = nil - self.postcode_full = postcode_full_input + self.postcode_full = postcode_full_input if postcode_full_input.match(POSTCODE_REGEXP) process_postcode_changes! else self.uprn = uprn_selection diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 361aab6f6..3064cba31 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -132,8 +132,7 @@ class SalesLog < Log not_required << "mortlen" if mortlen_optional? not_required << "frombeds" if frombeds_optional? not_required << "deposit" if form.start_year_2024_or_later? && stairowned_100? - - not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023 + not_required += %w[address_line2 county] not_required end diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index b10dfc6e5..525dee9ff 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -1018,6 +1018,33 @@ RSpec.describe "Lettings Log Features" do end end + context "and the user selects 'address_not_listed' when partial postcode is entered" do + before do + fill_in("lettings_log[address_line1_input]", with: "Address line 1") + fill_in("lettings_log[postcode_full_input]", with: "AA1") + click_button("Search") + choose "The address is not listed, I want to enter the address manually" + click_button("Save and continue") + end + + it "sets correct address fields" do + lettings_log.reload + expect(lettings_log.uprn_known).to eq(0) # no + expect(lettings_log.uprn).to eq(nil) + expect(lettings_log.uprn_confirmed).to eq(nil) + expect(lettings_log.uprn_selection).to eq("uprn_not_listed") + expect(lettings_log.postcode_known).to eq(nil) + expect(lettings_log.postcode_full).to eq(nil) + expect(lettings_log.address_line1).to eq("Address line 1") + expect(lettings_log.address_line2).to eq(nil) + expect(lettings_log.town_or_city).to eq(nil) + expect(lettings_log.address_line1_input).to eq("Address line 1") + expect(lettings_log.postcode_full_input).to eq("AA1") + expect(lettings_log.address_search_value_check).to eq(nil) + expect(lettings_log.la).to eq(nil) + end + end + context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do before do fill_in("lettings_log[address_line1_input]", with: "Address line 1") diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index d418bcb37..663a4f7ac 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -599,6 +599,33 @@ RSpec.describe "Sales Log Features" do end end + context "and the user selects 'address_not_listed' when partial postcode is given" do + before do + fill_in("sales_log[address_line1_input]", with: "Address line 1") + fill_in("sales_log[postcode_full_input]", with: "1AA") + click_button("Search") + choose "The address is not listed, I want to enter the address manually" + click_button("Save and continue") + end + + it "sets correct address fields" do + sales_log.reload + expect(sales_log.uprn_known).to eq(0) # no + expect(sales_log.uprn).to eq(nil) + expect(sales_log.uprn_confirmed).to eq(nil) + expect(sales_log.uprn_selection).to eq("uprn_not_listed") + expect(sales_log.pcodenk).to eq(nil) + expect(sales_log.postcode_full).to eq(nil) + expect(sales_log.address_line1).to eq("Address line 1") + expect(sales_log.address_line2).to eq(nil) + expect(sales_log.town_or_city).to eq(nil) + expect(sales_log.address_line1_input).to eq("Address line 1") + expect(sales_log.postcode_full_input).to eq("1AA") + expect(sales_log.address_search_value_check).to eq(nil) + expect(sales_log.la).to eq(nil) + end + end + context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do before do fill_in("sales_log[address_line1_input]", with: "Address line 1") diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 17cad1c5e..e9493a017 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -861,19 +861,6 @@ RSpec.describe LettingsLog do end end - context "when startdate is before 2023" do - let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) } - - it "returns optional fields" do - expect(lettings_log.optional_fields).to eq(%w[ - tenancycode - propcode - chcharge - tenancylength - ]) - end - end - context "when startdate is after 2023" do let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } @@ -885,7 +872,6 @@ RSpec.describe LettingsLog do tenancylength address_line2 county - postcode_full ]) end end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 9fe5a02a9..0c854c221 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -76,21 +76,6 @@ RSpec.describe SalesLog, type: :model do end describe "#optional_fields" do - context "when saledate is before 2023" do - let(:sales_log) { build(:sales_log, saledate: Time.zone.parse("2022-07-01")) } - - it "returns optional fields" do - expect(sales_log.optional_fields).to eq(%w[ - purchid - othtype - buyers_organisations - proplen - mortlen - frombeds - ]) - end - end - context "when saledate is after 2023" do let(:sales_log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) } @@ -101,7 +86,6 @@ RSpec.describe SalesLog, type: :model do buyers_organisations address_line2 county - postcode_full ]) end end