Browse Source

Do not assign invalid postcode (#2855)

* Do not assign invalid postcode

* Make postcode full required if routed to

* Update tests
CLDC-3790-continued v0.4.90
kosiakkatrina 1 week ago committed by GitHub
parent
commit
3f4cbc2010
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/models/lettings_log.rb
  2. 2
      app/models/log.rb
  3. 3
      app/models/sales_log.rb
  4. 27
      spec/features/lettings_log_spec.rb
  5. 27
      spec/features/sales_log_spec.rb
  6. 14
      spec/models/lettings_log_spec.rb
  7. 16
      spec/models/sales_log_spec.rb

3
app/models/lettings_log.rb

@ -779,8 +779,7 @@ private
not_required << "previous_la_known" if postcode_known? not_required << "previous_la_known" if postcode_known?
not_required << "tshortfall" if tshortfall_unknown? not_required << "tshortfall" if tshortfall_unknown?
not_required << "tenancylength" if tenancylength_optional? not_required << "tenancylength" if tenancylength_optional?
not_required += %w[address_line2 county]
not_required |= %w[address_line2 county postcode_full] if startdate && collection_start_year_for_date(startdate) >= 2023
not_required not_required
end end

2
app/models/log.rb

@ -110,7 +110,7 @@ class Log < ApplicationRecord
self.address_line2 = nil self.address_line2 = nil
self.town_or_city = nil self.town_or_city = nil
self.county = 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! process_postcode_changes!
else else
self.uprn = uprn_selection self.uprn = uprn_selection

3
app/models/sales_log.rb

@ -132,8 +132,7 @@ class SalesLog < Log
not_required << "mortlen" if mortlen_optional? not_required << "mortlen" if mortlen_optional?
not_required << "frombeds" if frombeds_optional? not_required << "frombeds" if frombeds_optional?
not_required << "deposit" if form.start_year_2024_or_later? && stairowned_100? not_required << "deposit" if form.start_year_2024_or_later? && stairowned_100?
not_required += %w[address_line2 county]
not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023
not_required not_required
end end

27
spec/features/lettings_log_spec.rb

@ -1018,6 +1018,33 @@ RSpec.describe "Lettings Log Features" do
end end
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 context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do
before do before do
fill_in("lettings_log[address_line1_input]", with: "Address line 1") fill_in("lettings_log[address_line1_input]", with: "Address line 1")

27
spec/features/sales_log_spec.rb

@ -599,6 +599,33 @@ RSpec.describe "Sales Log Features" do
end end
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 context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do
before do before do
fill_in("sales_log[address_line1_input]", with: "Address line 1") fill_in("sales_log[address_line1_input]", with: "Address line 1")

14
spec/models/lettings_log_spec.rb

@ -861,19 +861,6 @@ RSpec.describe LettingsLog do
end end
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 context "when startdate is after 2023" do
let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) }
@ -885,7 +872,6 @@ RSpec.describe LettingsLog do
tenancylength tenancylength
address_line2 address_line2
county county
postcode_full
]) ])
end end
end end

16
spec/models/sales_log_spec.rb

@ -76,21 +76,6 @@ RSpec.describe SalesLog, type: :model do
end end
describe "#optional_fields" do 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 context "when saledate is after 2023" do
let(:sales_log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) } 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 buyers_organisations
address_line2 address_line2
county county
postcode_full
]) ])
end end
end end

Loading…
Cancel
Save