|
|
|
|
@ -16,31 +16,6 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
let(:non_confidential_scheme) { create(:scheme, sensitive: "No", owning_organisation:) } |
|
|
|
|
let(:location) { create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
let(:cleared_fields) do |
|
|
|
|
%w[ |
|
|
|
|
uprn |
|
|
|
|
uprn_known |
|
|
|
|
uprn_confirmed |
|
|
|
|
uprn_selection |
|
|
|
|
address_line1 |
|
|
|
|
address_line2 |
|
|
|
|
town_or_city |
|
|
|
|
county |
|
|
|
|
postcode_full |
|
|
|
|
postcode_known |
|
|
|
|
address_line1_input |
|
|
|
|
postcode_full_input |
|
|
|
|
address_line1_as_entered |
|
|
|
|
address_line2_as_entered |
|
|
|
|
town_or_city_as_entered |
|
|
|
|
county_as_entered |
|
|
|
|
postcode_full_as_entered |
|
|
|
|
la_as_entered |
|
|
|
|
address_search_value_check |
|
|
|
|
la |
|
|
|
|
] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def create_log_with_address_data(scheme:, location:, startdate:) |
|
|
|
|
log = create( |
|
|
|
|
:lettings_log, |
|
|
|
|
@ -57,24 +32,9 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
# address/UPRN data collected before the confidential address feature existed. |
|
|
|
|
log.update_columns( |
|
|
|
|
uprn: "123456789012", |
|
|
|
|
uprn_known: 1, |
|
|
|
|
uprn_confirmed: 1, |
|
|
|
|
uprn_selection: "123456789012", |
|
|
|
|
address_line1: "1 Secret Street", |
|
|
|
|
address_line2: "Flat 2", |
|
|
|
|
town_or_city: "Secretville", |
|
|
|
|
county: "Secretshire", |
|
|
|
|
postcode_full: "SW1A 1AA", |
|
|
|
|
postcode_known: 1, |
|
|
|
|
address_line1_input: "1 Secret Street", |
|
|
|
|
postcode_full_input: "SW1A1AA", |
|
|
|
|
address_line1_as_entered: "1 Secret Street", |
|
|
|
|
address_line2_as_entered: "Flat 2", |
|
|
|
|
town_or_city_as_entered: "Secretville", |
|
|
|
|
county_as_entered: "Secretshire", |
|
|
|
|
postcode_full_as_entered: "SW1A 1AA", |
|
|
|
|
la_as_entered: "E09000003", |
|
|
|
|
address_search_value_check: 1, |
|
|
|
|
la: "E09000003", |
|
|
|
|
) |
|
|
|
|
log |
|
|
|
|
@ -93,15 +53,6 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
expect(log.postcode_known).to be_nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "clears every field the task targets" do |
|
|
|
|
task.invoke |
|
|
|
|
log.reload |
|
|
|
|
|
|
|
|
|
cleared_fields.each do |field| |
|
|
|
|
expect(log[field]).to be_nil, "expected #{field} to be nil but was #{log[field].inspect}" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "keeps the log's status unchanged when the location's LA can be inferred" do |
|
|
|
|
task.invoke |
|
|
|
|
expect(log.reload.status).to eq("completed") |
|
|
|
|
@ -115,20 +66,6 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
expect(log[:la]).to be_nil |
|
|
|
|
expect(log.is_la_inferred).to be true |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not affect the scheme or location associations" do |
|
|
|
|
task.invoke |
|
|
|
|
log.reload |
|
|
|
|
|
|
|
|
|
expect(log.scheme_id).to eq(scheme.id) |
|
|
|
|
expect(log.location_id).to eq(location.id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "is idempotent" do |
|
|
|
|
task.invoke |
|
|
|
|
task.reenable |
|
|
|
|
expect { task.invoke }.not_to(change { log.reload.updated_at }) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the scheme's location has no resolvable local authority" do |
|
|
|
|
@ -151,12 +88,7 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
|
|
|
|
|
it "does not clear the address fields" do |
|
|
|
|
task.invoke |
|
|
|
|
log.reload |
|
|
|
|
|
|
|
|
|
expect(log.address_line1).to eq("1 Secret Street") |
|
|
|
|
expect(log.town_or_city).to eq("Secretville") |
|
|
|
|
expect(log.uprn).to eq("123456789012") |
|
|
|
|
expect(log.postcode_known).to eq(1) |
|
|
|
|
expect(log.reload.address_line1).to eq("1 Secret Street") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -165,12 +97,7 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
|
|
|
|
|
it "does not clear the address fields" do |
|
|
|
|
task.invoke |
|
|
|
|
log.reload |
|
|
|
|
|
|
|
|
|
expect(log.address_line1).to eq("1 Secret Street") |
|
|
|
|
expect(log.town_or_city).to eq("Secretville") |
|
|
|
|
expect(log.uprn).to eq("123456789012") |
|
|
|
|
expect(log.postcode_known).to eq(1) |
|
|
|
|
expect(log.reload.address_line1).to eq("1 Secret Street") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -192,5 +119,23 @@ RSpec.describe "clear_confidential_address_data" do
|
|
|
|
|
expect { task.invoke }.not_to(change { log.reload.updated_at }) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not affect the scheme or location associations" do |
|
|
|
|
log = create_log_with_address_data(scheme:, location:, startdate: Time.zone.local(2026, 5, 1)) |
|
|
|
|
|
|
|
|
|
task.invoke |
|
|
|
|
log.reload |
|
|
|
|
|
|
|
|
|
expect(log.scheme_id).to eq(scheme.id) |
|
|
|
|
expect(log.location_id).to eq(location.id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "is idempotent" do |
|
|
|
|
log = create_log_with_address_data(scheme:, location:, startdate: Time.zone.local(2026, 5, 1)) |
|
|
|
|
|
|
|
|
|
task.invoke |
|
|
|
|
task.reenable |
|
|
|
|
expect { task.invoke }.not_to(change { log.reload.updated_at }) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|