Browse Source

Fix failing test

CLDC-4461-hide-confidential-addresses
oscric 2 days ago
parent
commit
dc75a30546
  1. 65
      spec/models/lettings_log_derived_fields_spec.rb

65
spec/models/lettings_log_derived_fields_spec.rb

@ -1585,10 +1585,8 @@ RSpec.describe LettingsLog, type: :model do
end end
end end
describe "deriving address fields and LA for a confidential scheme", metadata: { year: 26 } do describe "address field behaviour for confidential schemes", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) } let(:startdate) { collection_start_date_for_year(2026) }
let(:confidential_scheme) { create(:scheme, sensitive: 1) }
let(:location) { create(:location, scheme: confidential_scheme) }
let(:uprn) { "123456789" } let(:uprn) { "123456789" }
let(:uprn_known) { 1 } let(:uprn_known) { 1 }
@ -1609,20 +1607,22 @@ RSpec.describe LettingsLog, type: :model do
before do before do
log.needstype = 2 log.needstype = 2
log.assign_attributes(uprn:, uprn_known:, uprn_confirmed:, address_line1:, address_line2:, town_or_city:, county:, postcode_full:, la:)
end
context "when the scheme has confidential information" do
let(:confidential_scheme) { create(:scheme, sensitive: 1) }
let(:location) { create(:location, scheme: confidential_scheme) }
before do
log.scheme = confidential_scheme log.scheme = confidential_scheme
log.location = location log.location = location
log.assign_attributes(uprn:, uprn_known:, uprn_confirmed:, address_line1:, address_line2:, town_or_city:, county:, postcode_full:, la:)
end end
it "does not ask the address or UPRN question" do it "does not ask the address or UPRN question" do
expect(log.is_address_asked?).to be false expect(log.is_address_asked?).to be false
end end
it "still asks the address question when the scheme is not confidential" do
log.scheme = create(:scheme, sensitive: 0)
expect(log.is_address_asked?).to be true
end
it "resets all the address and UPRN fields to nil" do it "resets all the address and UPRN fields to nil" do
expect { log.set_derived_fields! } expect { log.set_derived_fields! }
.to change { log.read_attribute(:uprn) }.from(uprn).to(nil) .to change { log.read_attribute(:uprn) }.from(uprn).to(nil)
@ -1635,29 +1635,7 @@ RSpec.describe LettingsLog, type: :model do
.and change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil) .and change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil)
end end
context "when the location postcode resolves to a local authority" do context "when the log is a new-build first let" do
it "derives the LA from the location and marks it as inferred" do
log.set_derived_fields!
expect(log.read_attribute(:la)).to eq(location.location_code)
expect(log.is_la_inferred).to be true
end
end
context "when the location postcode does not resolve to a local authority" do
before do
location.update_column(:location_code, nil)
end
it "leaves the LA blank and not inferred" do
log.set_derived_fields!
expect(log.read_attribute(:la)).to be_nil
expect(log.is_la_inferred).to be false
end
end
context "when the log is also a new-build first let" do
before do before do
log.rsnvac = 15 log.rsnvac = 15
end end
@ -1666,34 +1644,30 @@ RSpec.describe LettingsLog, type: :model do
expect(log.is_address_asked?).to be false expect(log.is_address_asked?).to be false
end end
it "resets the address and UPRN fields to nil" do it "resets all the address and UPRN fields to nil" do
expect { log.set_derived_fields! } expect { log.set_derived_fields! }
.to change { log.read_attribute(:uprn) }.from(uprn).to(nil) .to change { log.read_attribute(:uprn) }.from(uprn).to(nil)
.and change { log.read_attribute(:uprn_known) }.from(uprn_known).to(nil)
.and change { log.read_attribute(:uprn_confirmed) }.from(uprn_confirmed).to(nil)
.and change { log.read_attribute(:address_line1) }.from(address_line1).to(nil) .and change { log.read_attribute(:address_line1) }.from(address_line1).to(nil)
.and(change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil)) .and change { log.read_attribute(:address_line2) }.from(address_line2).to(nil)
.and change { log.read_attribute(:town_or_city) }.from(town_or_city).to(nil)
.and change { log.read_attribute(:county) }.from(county).to(nil)
.and change { log.read_attribute(:postcode_full) }.from(postcode_full).to(nil)
end end
end end
end end
describe "address behaviour for a non-confidential supported housing log continues as normal", metadata: { year: 26 } do context "when the scheme does not have confidential information" do
let(:startdate) { collection_start_date_for_year(2026) }
let(:non_confidential_scheme) { create(:scheme, sensitive: 0) } let(:non_confidential_scheme) { create(:scheme, sensitive: 0) }
let(:location) { create(:location, scheme: non_confidential_scheme) } let(:location) { create(:location, scheme: non_confidential_scheme) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2026)) do
Singleton.__init__(FormHandler)
example.run
end
end
before do before do
log.needstype = 2
log.scheme = non_confidential_scheme log.scheme = non_confidential_scheme
log.location = location log.location = location
end end
it "still asks for the address or UPRN" do it "ask the address or UPRN question" do
expect(log.is_address_asked?).to be true expect(log.is_address_asked?).to be true
end end
@ -1704,6 +1678,7 @@ RSpec.describe LettingsLog, type: :model do
.to change(log, :manual_address_entry_selected).from(false).to(true) .to change(log, :manual_address_entry_selected).from(false).to(true)
end end
end end
end
describe "#infer_at_most_one_relationship!" do describe "#infer_at_most_one_relationship!" do
context "when 2025", metadata: { year: 25 } do context "when 2025", metadata: { year: 25 } do

Loading…
Cancel
Save