Skip to content

Commit

Permalink
Do not assign invalid postcode (#2855)
Browse files Browse the repository at this point in the history
* Do not assign invalid postcode

* Make postcode full required if routed to

* Update tests
  • Loading branch information
kosiakkatrina authored Dec 18, 2024
1 parent 32ea130 commit 3f4cbc2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
3 changes: 1 addition & 2 deletions app/models/lettings_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ def dynamically_not_required
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def process_address_change!
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
Expand Down
3 changes: 1 addition & 2 deletions app/models/sales_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def dynamically_not_required
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
Expand Down
27 changes: 27 additions & 0 deletions spec/features/lettings_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,33 @@
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")
Expand Down
27 changes: 27 additions & 0 deletions spec/features/sales_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,33 @@
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")
Expand Down
14 changes: 0 additions & 14 deletions spec/models/lettings_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,19 +861,6 @@ def previous_postcode_fields
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")) }

Expand All @@ -885,7 +872,6 @@ def previous_postcode_fields
tenancylength
address_line2
county
postcode_full
])
end
end
Expand Down
16 changes: 0 additions & 16 deletions spec/models/sales_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@
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")) }

Expand All @@ -101,7 +86,6 @@
buyers_organisations
address_line2
county
postcode_full
])
end
end
Expand Down

0 comments on commit 3f4cbc2

Please sign in to comment.