Browse Source

CLDC-2988 Update routing for address pages (#2102)

* Update uprn pages routing

* Update tests and stubs
pull/2109/head
kosiakkatrina 12 months ago committed by GitHub
parent
commit
2111af18ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/form/lettings/pages/address.rb
  2. 5
      app/models/form/lettings/pages/uprn.rb
  3. 9
      app/models/form/sales/pages/address.rb
  4. 4
      app/models/form/sales/pages/uprn.rb
  5. 41
      spec/lib/tasks/correct_address_from_csv_spec.rb
  6. 132
      spec/lib/tasks/send_missing_addresses_csv_spec.rb
  7. 42
      spec/models/form/lettings/pages/address_spec.rb
  8. 26
      spec/models/form/lettings/pages/uprn_confirmation_spec.rb
  9. 20
      spec/models/form/lettings/pages/uprn_spec.rb
  10. 8
      spec/models/form/lettings/questions/uprn_confirmation_spec.rb
  11. 5
      spec/models/form/lettings/questions/uprn_spec.rb
  12. 43
      spec/models/form/sales/pages/address_spec.rb
  13. 6
      spec/models/form/sales/questions/uprn_spec.rb
  14. 64
      spec/request_helper.rb
  15. 18
      spec/requests/duplicate_logs_controller_spec.rb
  16. 36
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  17. 55
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  18. 39
      spec/services/csv/missing_addresses_csv_service_spec.rb
  19. 4
      spec/shared/shared_log_examples.rb

11
app/models/form/lettings/pages/address.rb

@ -3,6 +3,11 @@ class Form::Lettings::Pages::Address < ::Form::Page
super super
@id = "address" @id = "address"
@header = "Q12 - What is the property's address?" @header = "Q12 - What is the property's address?"
@depends_on = [
{ "is_supported_housing?" => false, "uprn_known" => nil },
{ "is_supported_housing?" => false, "uprn_known" => 0 },
{ "is_supported_housing?" => false, "uprn_confirmed" => 0 },
]
end end
def questions def questions
@ -14,10 +19,4 @@ class Form::Lettings::Pages::Address < ::Form::Page
Form::Lettings::Questions::PostcodeForFullAddress.new(nil, nil, self), Form::Lettings::Questions::PostcodeForFullAddress.new(nil, nil, self),
] ]
end end
def routed_to?(log, _current_user = nil)
return false if log.is_supported_housing?
log.uprn_known.nil? || log.uprn_known.zero? || log.uprn_confirmed&.zero?
end
end end

5
app/models/form/lettings/pages/uprn.rb

@ -2,6 +2,7 @@ class Form::Lettings::Pages::Uprn < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "uprn" @id = "uprn"
@depends_on = [{ "is_supported_housing?" => false }]
end end
def questions def questions
@ -11,10 +12,6 @@ class Form::Lettings::Pages::Uprn < ::Form::Page
] ]
end end
def routed_to?(log, _current_user = nil)
!log.is_supported_housing?
end
def skip_text def skip_text
"Enter address instead" "Enter address instead"
end end

9
app/models/form/sales/pages/address.rb

@ -3,6 +3,11 @@ class Form::Sales::Pages::Address < ::Form::Page
super super
@id = "address" @id = "address"
@header = "Q15 - What is the property's address?" @header = "Q15 - What is the property's address?"
@depends_on = [
{ "uprn_known" => nil },
{ "uprn_known" => 0 },
{ "uprn_confirmed" => 0 },
]
end end
def questions def questions
@ -14,8 +19,4 @@ class Form::Sales::Pages::Address < ::Form::Page
Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self), Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self),
] ]
end end
def routed_to?(log, _current_user = nil)
log.uprn_known.nil? || log.uprn_known.zero? || log.uprn_confirmed&.zero?
end
end end

4
app/models/form/sales/pages/uprn.rb

@ -11,10 +11,6 @@ class Form::Sales::Pages::Uprn < ::Form::Page
] ]
end end
def routed_to?(_log, _current_user)
true
end
def skip_text def skip_text
"Enter address instead" "Enter address instead"
end end

41
spec/lib/tasks/correct_address_from_csv_spec.rb

@ -21,22 +21,6 @@ RSpec.describe "data_import" do
.to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) .to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {})
WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/B11BB/) WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/B11BB/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {}) .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "LS16 6FT",
"POST_TOWN": "Westminster",
"PO_BOX_NUMBER": "Wrong Address Line1",
"DOUBLE_DEPENDENT_LOCALITY": "Double Dependent Locality",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key&uprn=1")
.to_return(status: 200, body:, headers: {})
end end
describe ":import_lettings_addresses_from_csv", type: :task do describe ":import_lettings_addresses_from_csv", type: :task do
@ -73,10 +57,11 @@ RSpec.describe "data_import" do
end end
let!(:lettings_logs) do let!(:lettings_logs) do
create_list(:lettings_log, logs = build_list(:lettings_log,
3, 3,
:setup_completed,
uprn_known: 1, uprn_known: 1,
uprn: "1", uprn: "121",
uprn_confirmed: nil, uprn_confirmed: nil,
address_line1: "wrong address line1", address_line1: "wrong address line1",
address_line2: "wrong address 2", address_line2: "wrong address 2",
@ -86,6 +71,8 @@ RSpec.describe "data_import" do
postcode_full: "A1 1AA", postcode_full: "A1 1AA",
la: "E06000064", la: "E06000064",
is_la_inferred: true) is_la_inferred: true)
logs.each { |log| log.save!(validate: false) }
logs
end end
before do before do
@ -135,7 +122,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path) task.invoke(addresses_csv_path)
lettings_logs[1].reload lettings_logs[1].reload
expect(lettings_logs[1].uprn_known).to eq(1) expect(lettings_logs[1].uprn_known).to eq(1)
expect(lettings_logs[1].uprn).to eq("1") expect(lettings_logs[1].uprn).to eq("121")
expect(lettings_logs[1].uprn_confirmed).to eq(nil) expect(lettings_logs[1].uprn_confirmed).to eq(nil)
expect(lettings_logs[1].address_line1).to eq("wrong address line1") expect(lettings_logs[1].address_line1).to eq("wrong address line1")
expect(lettings_logs[1].address_line2).to eq("wrong address 2") expect(lettings_logs[1].address_line2).to eq("wrong address 2")
@ -150,7 +137,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path) task.invoke(addresses_csv_path)
lettings_logs[2].reload lettings_logs[2].reload
expect(lettings_logs[2].uprn_known).to eq(1) expect(lettings_logs[2].uprn_known).to eq(1)
expect(lettings_logs[2].uprn).to eq("1") expect(lettings_logs[2].uprn).to eq("121")
expect(lettings_logs[2].uprn_confirmed).to eq(nil) expect(lettings_logs[2].uprn_confirmed).to eq(nil)
expect(lettings_logs[2].address_line1).to eq("wrong address line1") expect(lettings_logs[2].address_line1).to eq("wrong address line1")
expect(lettings_logs[2].address_line2).to eq("wrong address 2") expect(lettings_logs[2].address_line2).to eq("wrong address 2")
@ -231,7 +218,7 @@ RSpec.describe "data_import" do
task.invoke(all_addresses_csv_path) task.invoke(all_addresses_csv_path)
lettings_logs[1].reload lettings_logs[1].reload
expect(lettings_logs[1].uprn_known).to eq(1) expect(lettings_logs[1].uprn_known).to eq(1)
expect(lettings_logs[1].uprn).to eq("1") expect(lettings_logs[1].uprn).to eq("121")
expect(lettings_logs[1].uprn_confirmed).to eq(nil) expect(lettings_logs[1].uprn_confirmed).to eq(nil)
expect(lettings_logs[1].address_line1).to eq("wrong address line1") expect(lettings_logs[1].address_line1).to eq("wrong address line1")
expect(lettings_logs[1].address_line2).to eq("wrong address 2") expect(lettings_logs[1].address_line2).to eq("wrong address 2")
@ -246,7 +233,7 @@ RSpec.describe "data_import" do
task.invoke(all_addresses_csv_path) task.invoke(all_addresses_csv_path)
lettings_logs[2].reload lettings_logs[2].reload
expect(lettings_logs[2].uprn_known).to eq(1) expect(lettings_logs[2].uprn_known).to eq(1)
expect(lettings_logs[2].uprn).to eq("1") expect(lettings_logs[2].uprn).to eq("121")
expect(lettings_logs[2].uprn_confirmed).to eq(nil) expect(lettings_logs[2].uprn_confirmed).to eq(nil)
expect(lettings_logs[2].address_line1).to eq("wrong address line1") expect(lettings_logs[2].address_line1).to eq("wrong address line1")
expect(lettings_logs[2].address_line2).to eq("wrong address 2") expect(lettings_logs[2].address_line2).to eq("wrong address 2")
@ -323,7 +310,7 @@ RSpec.describe "data_import" do
is_la_inferred: true) is_la_inferred: true)
end end
let!(:sales_logs) { create_list(:sales_log, 3, :completed, uprn_known: 1, uprn: "1", la: "E06000064", is_la_inferred: true) } let!(:sales_logs) { create_list(:sales_log, 3, :completed, uprn_known: 1, uprn: "121", la: "E06000064", is_la_inferred: true) }
before do before do
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
@ -372,7 +359,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path) task.invoke(addresses_csv_path)
sales_logs[1].reload sales_logs[1].reload
expect(sales_logs[1].uprn_known).to eq(1) expect(sales_logs[1].uprn_known).to eq(1)
expect(sales_logs[1].uprn).to eq("1") expect(sales_logs[1].uprn).to eq("121")
expect(sales_logs[1].uprn_confirmed).to eq(nil) expect(sales_logs[1].uprn_confirmed).to eq(nil)
expect(sales_logs[1].address_line1).to eq("Wrong Address Line1") expect(sales_logs[1].address_line1).to eq("Wrong Address Line1")
expect(sales_logs[1].address_line2).to eq("Double Dependent Locality") expect(sales_logs[1].address_line2).to eq("Double Dependent Locality")
@ -387,7 +374,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path) task.invoke(addresses_csv_path)
sales_logs[2].reload sales_logs[2].reload
expect(sales_logs[2].uprn_known).to eq(1) expect(sales_logs[2].uprn_known).to eq(1)
expect(sales_logs[2].uprn).to eq("1") expect(sales_logs[2].uprn).to eq("121")
expect(sales_logs[2].uprn_confirmed).to eq(nil) expect(sales_logs[2].uprn_confirmed).to eq(nil)
expect(sales_logs[2].address_line1).to eq("Wrong Address Line1") expect(sales_logs[2].address_line1).to eq("Wrong Address Line1")
expect(sales_logs[2].address_line2).to eq("Double Dependent Locality") expect(sales_logs[2].address_line2).to eq("Double Dependent Locality")
@ -468,7 +455,7 @@ RSpec.describe "data_import" do
task.invoke(all_addresses_csv_path) task.invoke(all_addresses_csv_path)
sales_logs[1].reload sales_logs[1].reload
expect(sales_logs[1].uprn_known).to eq(1) expect(sales_logs[1].uprn_known).to eq(1)
expect(sales_logs[1].uprn).to eq("1") expect(sales_logs[1].uprn).to eq("121")
expect(sales_logs[1].uprn_confirmed).to eq(nil) expect(sales_logs[1].uprn_confirmed).to eq(nil)
expect(sales_logs[1].address_line1).to eq("Wrong Address Line1") expect(sales_logs[1].address_line1).to eq("Wrong Address Line1")
expect(sales_logs[1].address_line2).to eq("Double Dependent Locality") expect(sales_logs[1].address_line2).to eq("Double Dependent Locality")
@ -483,7 +470,7 @@ RSpec.describe "data_import" do
task.invoke(all_addresses_csv_path) task.invoke(all_addresses_csv_path)
sales_logs[2].reload sales_logs[2].reload
expect(sales_logs[2].uprn_known).to eq(1) expect(sales_logs[2].uprn_known).to eq(1)
expect(sales_logs[2].uprn).to eq("1") expect(sales_logs[2].uprn).to eq("121")
expect(sales_logs[2].uprn_confirmed).to eq(nil) expect(sales_logs[2].uprn_confirmed).to eq(nil)
expect(sales_logs[2].address_line1).to eq("Wrong Address Line1") expect(sales_logs[2].address_line1).to eq("Wrong Address Line1")
expect(sales_logs[2].address_line2).to eq("Double Dependent Locality") expect(sales_logs[2].address_line2).to eq("Double Dependent Locality")

132
spec/lib/tasks/send_missing_addresses_csv_spec.rb

@ -17,36 +17,6 @@ RSpec.describe "correct_addresses" do
Rake.application.rake_require("tasks/send_missing_addresses_csv") Rake.application.rake_require("tasks/send_missing_addresses_csv")
Rake::Task.define_task(:environment) Rake::Task.define_task(:environment)
task.reenable task.reenable
body_1 = {
results: [
{
DPA: {
"POSTCODE": "BS1 1AD",
"POST_TOWN": "Bristol",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
body_2 = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
.to_return(status: 200, body: body_1, headers: {})
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=12")
.to_return(status: 200, body: body_2, headers: {})
end end
context "when the rake task is run" do context "when the rake task is run" do
@ -62,7 +32,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:lettings_log, 7, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_1", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 7, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_1", owning_organisation: organisation, managing_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -81,7 +51,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -96,9 +66,11 @@ RSpec.describe "correct_addresses" do
end end
context "when org has less than 5 missing addresses" do context "when org has less than 5 missing addresses" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:lettings_log, 3, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 3, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
create_list(:lettings_log, 2, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 2, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job with organisations that is missing less addresses than threshold amount" do it "does not enqueue the job with organisations that is missing less addresses than threshold amount" do
@ -112,7 +84,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:lettings_log, 7, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, needstype: 1, old_form_id: "form_1", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 7, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, needstype: 1, old_form_id: "form_1", owning_organisation: organisation, managing_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -131,7 +103,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -146,9 +118,11 @@ RSpec.describe "correct_addresses" do
end end
context "when org has less than 5 missing town or city" do context "when org has less than 5 missing town or city" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:lettings_log, 3, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "address", town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 3, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "address", town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
create_list(:lettings_log, 2, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "address", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 2, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: "address", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job with organisations that is missing less town or city data than threshold amount" do it "does not enqueue the job with organisations that is missing less town or city data than threshold amount" do
@ -162,7 +136,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:lettings_log, 7, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "123", town_or_city: "Bristol", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 7, :imported, :setup_completed, startdate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "123", town_or_city: "Bristol", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -181,7 +155,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, :setup_completed, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -200,8 +174,8 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 3, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "123", town_or_city: "Bristol", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 3, :imported, :setup_completed, startdate: Time.zone.local(2023, 9, 9), uprn: "123", town_or_city: "Bristol", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
create_list(:lettings_log, 2, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", tenancycode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 2, :imported, :setup_completed, startdate: Time.zone.local(2023, 9, 9), uprn: "12", tenancycode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -216,8 +190,10 @@ RSpec.describe "correct_addresses" do
end end
context "when org is included in skip_uprn_issue_organisations list" do context "when org is included in skip_uprn_issue_organisations list" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job" do it "does not enqueue the job" do
@ -230,8 +206,8 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, needstype: 1, old_form_id: "form_2", owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job" do it "does not enqueue the job" do
@ -244,7 +220,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:lettings_log, 5, :imported, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: organisation.users.first) create_list(:lettings_log, 5, :imported, :setup_completed, startdate: Time.zone.local(2023, 9, 9), uprn: "12", propcode: "12", needstype: 1, owning_organisation: organisation, managing_organisation: organisation, created_by: data_provider)
end end
it "does enqueues the job with correct skip_uprn_issue_organisations" do it "does enqueues the job with correct skip_uprn_issue_organisations" do
@ -262,36 +238,6 @@ RSpec.describe "correct_addresses" do
Rake.application.rake_require("tasks/send_missing_addresses_csv") Rake.application.rake_require("tasks/send_missing_addresses_csv")
Rake::Task.define_task(:environment) Rake::Task.define_task(:environment)
task.reenable task.reenable
body_1 = {
results: [
{
DPA: {
"POSTCODE": "BS1 1AD",
"POST_TOWN": "Bristol",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
body_2 = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
.to_return(status: 200, body: body_1, headers: {})
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=12")
.to_return(status: 200, body: body_2, headers: {})
end end
context "when the rake task is run" do context "when the rake task is run" do
@ -307,7 +253,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_1", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_1", owning_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -326,7 +272,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -341,9 +287,11 @@ RSpec.describe "correct_addresses" do
end end
context "when org has less than 5 missing addresses" do context "when org has less than 5 missing addresses" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: data_provider)
create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: nil, owning_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job with organisations that is missing less addresses than threshold amount" do it "does not enqueue the job with organisations that is missing less addresses than threshold amount" do
@ -357,7 +305,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, old_form_id: "form_1", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, old_form_id: "form_1", owning_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -376,7 +324,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "exists", town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -391,9 +339,11 @@ RSpec.describe "correct_addresses" do
end end
context "when org has less than 5 missing town or city" do context "when org has less than 5 missing town or city" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "address", town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "address", town_or_city: nil, old_form_id: "form_2", owning_organisation: organisation, created_by: data_provider)
create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "address", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), address_line1: "address", owning_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job with organisations that is missing less town or city data than threshold amount" do it "does not enqueue the job with organisations that is missing less town or city data than threshold amount" do
@ -407,7 +357,7 @@ RSpec.describe "correct_addresses" do
before do before do
create(:user, :data_provider, organisation:, email: "data_provider1@example.com") create(:user, :data_provider, organisation:, email: "data_provider1@example.com")
create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "123", town_or_city: "Bristol", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 7, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "123", town_or_city: "Bristol", owning_organisation: organisation, created_by: data_coordinator)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -426,7 +376,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -445,8 +395,8 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "123", town_or_city: "Bristol", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 3, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "123", town_or_city: "Bristol", owning_organisation: organisation, created_by: data_provider)
create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 2, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: data_provider)
end end
it "enqueues the job with correct organisations" do it "enqueues the job with correct organisations" do
@ -461,8 +411,10 @@ RSpec.describe "correct_addresses" do
end end
context "when org is included in skip_uprn_issue_organisations list" do context "when org is included in skip_uprn_issue_organisations list" do
let!(:data_provider) { create(:user, :data_provider, organisation:, email: "data_provider3@example.com") }
before do before do
create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: data_provider)
end end
it "does not enqueue the job" do it "does not enqueue the job" do
@ -475,7 +427,7 @@ RSpec.describe "correct_addresses" do
let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") } let!(:data_provider2) { create(:user, :data_provider, organisation:, email: "data_provider4@example.com") }
before do before do
create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: organisation.users.first) create_list(:sales_log, 5, :completed, :imported, saledate: Time.zone.local(2023, 9, 9), uprn_known: 1, uprn: "12", purchid: "12", owning_organisation: organisation, created_by: data_provider)
end end
it "does enqueues the job with correct skip_uprn_issue_organisations" do it "does enqueues the job with correct skip_uprn_issue_organisations" do

42
spec/models/form/lettings/pages/address_spec.rb

@ -28,46 +28,6 @@ RSpec.describe Form::Lettings::Pages::Address, type: :model do
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to be_nil expect(page.depends_on).to eq([{ "is_supported_housing?" => false, "uprn_known" => nil }, { "is_supported_housing?" => false, "uprn_known" => 0 }, { "is_supported_housing?" => false, "uprn_confirmed" => 0 }])
end
describe "has correct routed_to?" do
context "when uprn_known == nil" do
let(:log) { create(:lettings_log, uprn_known: nil) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed != 1" do
let(:log) do
create(:lettings_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 0)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_known == 0" do
let(:log) do
create(:lettings_log, uprn_known: 0, uprn_confirmed: 0)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed == 1 && uprn_known != 0" do
let(:log) do
create(:lettings_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1)
end
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
end end
end end

26
spec/models/form/lettings/pages/uprn_confirmation_spec.rb

@ -30,30 +30,4 @@ RSpec.describe Form::Lettings::Pages::UprnConfirmation, type: :model do
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to be_nil expect(page.depends_on).to be_nil
end end
describe "has correct routed_to?" do
context "when uprn present && uprn_known == 1 " do
let(:log) { create(:lettings_log, uprn_known: 1, uprn: "123456789") }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn = nil" do
let(:log) { create(:lettings_log, uprn_known: 1, uprn: nil) }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
context "when uprn_known == 0" do
let(:log) { create(:lettings_log, uprn_known: 0, uprn: "123456789") }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
end end

20
spec/models/form/lettings/pages/uprn_spec.rb

@ -28,31 +28,13 @@ RSpec.describe Form::Lettings::Pages::Uprn, type: :model do
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to be_nil expect(page.depends_on).to eq([{ "is_supported_housing?" => false }])
end end
it "has correct skip_text" do it "has correct skip_text" do
expect(page.skip_text).to eq("Enter address instead") expect(page.skip_text).to eq("Enter address instead")
end end
describe "has correct routed_to?" do
context "when uprn_known == 1" do
let(:log) { create(:lettings_log, uprn_known: 1) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when needstype == 2" do
let(:log) { create(:lettings_log, uprn_known: 1, needstype: 2) }
it "returns true" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
describe "has correct skip_href" do describe "has correct skip_href" do
context "when log is nil" do context "when log is nil" do
it "is nil" do it "is nil" do

8
spec/models/form/lettings/questions/uprn_confirmation_spec.rb

@ -50,12 +50,12 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
context "when address is present" do context "when address is present" do
it "returns formatted value" do it "returns formatted value" do
log = create(:lettings_log, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA", uprn: "1234", uprn_known: 1) log = create(:lettings_log, :setup_completed, address_line1: "1, Test Street", town_or_city: "Test Town", postcode_full: "AA1 1AA", uprn: "1", uprn_known: 1)
expect(question.notification_banner(log)).to eq( expect(question.notification_banner(log)).to eq(
{ {
heading: "1, Test Street\nAA1 1AA\nTest Town\nTest County", heading: "1, Test Street\nAA1 1AA\nTest Town",
title: "UPRN: 1234", title: "UPRN: 1",
}, },
) )
end end
@ -72,7 +72,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
end end
context "when uprn_known == 1 && uprn_confirmed == nil" do context "when uprn_known == 1 && uprn_confirmed == nil" do
let(:log) { create(:lettings_log, uprn_known: 1, uprn_confirmed: nil) } let(:log) { create(:lettings_log, :completed, uprn_known: 1, uprn: 1, uprn_confirmed: nil) }
it "returns false" do it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(false) expect(question.hidden_in_check_answers?(log)).to eq(false)

5
spec/models/form/lettings/questions/uprn_spec.rb

@ -56,6 +56,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
let(:log) do let(:log) do
create( create(
:lettings_log, :lettings_log,
:completed,
address_line1: "1, Test Street", address_line1: "1, Test Street",
town_or_city: "Test Town", town_or_city: "Test Town",
county: "Test County", county: "Test County",
@ -77,11 +78,11 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
context "when uprn known" do context "when uprn known" do
let(:uprn_known) { 1 } let(:uprn_known) { 1 }
let(:uprn) { 123_456_789 } let(:uprn) { 1 }
it "returns formatted value" do it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to eq( expect(question.get_extra_check_answer_value(log)).to eq(
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster", "\n\n1, Test Street\nTest Town\nAA1 1AA\nWestminster",
) )
end end
end end

43
spec/models/form/sales/pages/address_spec.rb

@ -28,47 +28,6 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to be_nil expect(page.depends_on).to eq([{ "uprn_known" => nil }, { "uprn_known" => 0 }, { "uprn_confirmed" => 0 }])
end
describe "has correct routed_to?" do
context "when uprn_known == nil" do
let(:log) { create(:sales_log, uprn_known: nil) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed != 1" do
let(:log) do
create(:sales_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 0)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_known == 0" do
let(:log) do
create(:sales_log, uprn_confirmed: 0)
end
it "returns true" do
log.uprn_known = 0
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed == 1 && uprn_known != 0" do
let(:log) do
create(:sales_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1)
end
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
end end
end end

6
spec/models/form/sales/questions/uprn_spec.rb

@ -56,9 +56,9 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
let(:log) do let(:log) do
create( create(
:sales_log, :sales_log,
:completed,
address_line1: "1, Test Street", address_line1: "1, Test Street",
town_or_city: "Test Town", town_or_city: "Test Town",
county: "Test County",
postcode_full: "AA1 1AA", postcode_full: "AA1 1AA",
la: "E09000003", la: "E09000003",
uprn_known:, uprn_known:,
@ -77,11 +77,11 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
context "when uprn known" do context "when uprn known" do
let(:uprn_known) { 1 } let(:uprn_known) { 1 }
let(:uprn) { 123_456_789 } let(:uprn) { 1 }
it "returns formatted value" do it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to eq( expect(question.get_extra_check_answer_value(log)).to eq(
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster", "\n\n1, Test Street\nTest Town\nAA1 1AA\nWestminster",
) )
end end
end end

64
spec/request_helper.rb

@ -19,6 +19,70 @@ module RequestHelper
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "", headers: {})
WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/)
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "", headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "AA1 1AA",
"POST_TOWN": "Test Town",
"ORGANISATION_NAME": "1, Test Street",
},
},
],
}.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1")
.to_return(status: 200, body:, headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "LS16 6FT",
"POST_TOWN": "Westminster",
"PO_BOX_NUMBER": "Wrong Address Line1",
"DOUBLE_DEPENDENT_LOCALITY": "Double Dependent Locality",
},
},
],
}.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key&uprn=121")
.to_return(status: 200, body:, headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "BS1 1AD",
"POST_TOWN": "Bristol",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
.to_return(status: 200, body:, headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=12")
.to_return(status: 200, body:, headers: {})
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1234567890123")
.to_return(status: 404, body: "", headers: {})
end end
def self.real_http_requests def self.real_http_requests

18
spec/requests/duplicate_logs_controller_spec.rb

@ -29,24 +29,6 @@ RSpec.describe DuplicateLogsController, type: :request do
end end
context "when user is signed in" do context "when user is signed in" do
before do
body = {
results: [
{
DPA: {
"POSTCODE": "LS16 6FT",
"POST_TOWN": "Westminster",
"PO_BOX_NUMBER": "321",
"DOUBLE_DEPENDENT_LOCALITY": "Double Dependent Locality",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
.to_return(status: 200, body:, headers: {})
end
context "when user is support" do context "when user is support" do
let(:support_user_org) { create(:organisation) } let(:support_user_org) { create(:organisation) }
let(:user) { create(:user, :support, organisation: support_user_org) } let(:user) { create(:user, :support, organisation: support_user_org) }

36
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -87,21 +87,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
stub_request(:get, /api.postcodes.io/) stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=100023336956")
.to_return(status: 200, body:, headers: {})
parser.valid? parser.valid?
end end
@ -244,7 +229,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_4: "1", field_4: "1",
field_18: "100023336956", field_18: "12",
} }
end end
@ -693,7 +678,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#validate_nulls" do describe "#validate_nulls" do
context "when non-setup questions are null" do context "when non-setup questions are null" do
let(:attributes) { { bulk_upload:, field_1: "a", field_18: "", field_19: "", field_21: "" } } let(:attributes) { setup_section_params.merge({ field_18: "", field_19: "", field_21: "" }) }
it "fetches the question's check_answer_label if it exists, otherwise it gets the question's header" do it "fetches the question's check_answer_label if it exists, otherwise it gets the question's header" do
parser.valid? parser.valid?
@ -1515,20 +1500,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#field_18" do # UPRN describe "#field_18" do # UPRN
context "when over 12 characters" do context "when over 12 characters" do
let(:attributes) { { bulk_upload:, field_18: "1234567890123" } } let(:attributes) { setup_section_params.merge({ field_18: "1234567890123" }) }
it "adds an appropriate error" do it "adds an appropriate error" do
expect(parser.errors[:field_18]).to eql(["UPRN must be 12 digits or less"]) expect(parser.errors[:field_18]).to eql(["UPRN is not recognised. Check the number, or enter the address"])
end end
end end
context "when neither UPRN nor address fields are given" do context "when neither UPRN nor address fields are given" do
let(:attributes) do let(:attributes) { setup_section_params }
{
bulk_upload:,
field_1: "1",
}
end
it "adds appropriate errors" do it "adds appropriate errors" do
expect(parser.errors[:field_18]).to eql(["You must answer UPRN"]) expect(parser.errors[:field_18]).to eql(["You must answer UPRN"])
@ -1683,16 +1663,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
describe "#uprn" do describe "#uprn" do
let(:attributes) { { bulk_upload:, field_18: "100023336956" } } let(:attributes) { { bulk_upload:, field_18: "12" } }
it "sets to given value" do it "sets to given value" do
expect(parser.log.uprn).to eql("100023336956") expect(parser.log.uprn).to eql("12")
end end
end end
describe "#uprn_known" do describe "#uprn_known" do
context "when uprn specified" do context "when uprn specified" do
let(:attributes) { { bulk_upload:, field_18: "100023336956" } } let(:attributes) { { bulk_upload:, field_18: "12" } }
it "sets to 1" do it "sets to 1" do
expect(parser.log.uprn_known).to be(1) expect(parser.log.uprn_known).to be(1)

55
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -41,7 +41,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
field_16: "2", field_16: "2",
field_17: "1", field_17: "1",
field_18: "1", field_18: "1",
field_19: "100023336956", field_19: "12",
field_24: "CR0", field_24: "CR0",
field_25: "4BB", field_25: "4BB",
field_26: "E09000008", field_26: "E09000008",
@ -187,43 +187,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
stub_request(:get, /api.postcodes.io/) stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
body = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=100023336956")
.to_return(status: 200, body:, headers: {})
body = {
header: {
uri: "https://api.os.uk/search/places/v1/uprn?uprn=2",
query: "uprn=2",
offset: 0,
totalresults: 0,
format: "JSON",
dataset: "DPA",
lr: "EN,CY",
maxresults: 100,
epoch: "101",
lastupdate: "2023-05-11",
output_srs: "EPSG:27700",
},
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=2")
.to_return(status: 200, body:, headers: {})
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=3")
.to_return(status: 404, body:, headers: {})
parser.valid? parser.valid?
end end
@ -744,14 +707,14 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
describe "#field_19" do # UPRN describe "#field_19" do # UPRN
context "when UPRN known and lookup found" do context "when UPRN known and lookup found" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) } let(:attributes) { setup_section_params.merge({ field_19: "12" }) }
it "is valid" do it "is valid" do
expect(parser.errors[:field_19]).to be_blank expect(parser.errors[:field_19]).to be_blank
end end
it "sets UPRN and UPRN known" do it "sets UPRN and UPRN known" do
expect(parser.log.uprn).to eq("100023336956") expect(parser.log.uprn).to eq("12")
expect(parser.log.uprn_known).to eq(1) expect(parser.log.uprn_known).to eq(1)
expect(parser.log.uprn_confirmed).to eq(1) expect(parser.log.uprn_confirmed).to eq(1)
end end
@ -774,7 +737,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
context "when UPRN entered but no lookup found" do context "when UPRN entered but no lookup found" do
let(:attributes) { setup_section_params.merge({ field_19: "2" }) } let(:attributes) { setup_section_params.merge({ field_19: "1234567890123" }) }
it "is not valid" do it "is not valid" do
expect(parser.errors[:field_19]).to be_present expect(parser.errors[:field_19]).to be_present
@ -789,7 +752,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
describe "##{data[:field]} (#{data[:name]})" do describe "##{data[:field]} (#{data[:name]})" do
context "when UPRN present" do context "when UPRN present" do
context "when UPRN valid" do context "when UPRN valid" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956", data[:field] => nil }) } let(:attributes) { setup_section_params.merge({ field_19: "12", data[:field] => nil }) }
it "can be blank" do it "can be blank" do
expect(parser.errors[data[:field]]).to be_blank expect(parser.errors[data[:field]]).to be_blank
@ -797,7 +760,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
context "when UPRN invalid" do context "when UPRN invalid" do
let(:attributes) { setup_section_params.merge({ field_19: "3", data[:field] => nil }) } let(:attributes) { setup_section_params.merge({ field_19: "1234567890123", data[:field] => nil }) }
it "cannot be blank" do it "cannot be blank" do
expect(parser.errors[data[:field]]).to be_present expect(parser.errors[data[:field]]).to be_present
@ -949,16 +912,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
describe "#log" do describe "#log" do
describe "#uprn" do describe "#uprn" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) } let(:attributes) { setup_section_params.merge({ field_19: "12" }) }
it "is correctly set" do it "is correctly set" do
expect(parser.log.uprn).to eql("100023336956") expect(parser.log.uprn).to eql("12")
end end
end end
describe "#uprn_known" do describe "#uprn_known" do
context "when uprn known" do context "when uprn known" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) } let(:attributes) { setup_section_params.merge({ field_19: "12" }) }
it "is correctly set" do it "is correctly set" do
expect(parser.log.uprn_known).to be(1) expect(parser.log.uprn_known).to be(1)

39
spec/services/csv/missing_addresses_csv_service_spec.rb

@ -6,38 +6,6 @@ RSpec.describe Csv::MissingAddressesCsvService do
let(:service) { described_class.new(organisation, skip_uprn_issue_organisations) } let(:service) { described_class.new(organisation, skip_uprn_issue_organisations) }
let(:skip_uprn_issue_organisations) { [100, 200] } let(:skip_uprn_issue_organisations) { [100, 200] }
before do
body_1 = {
results: [
{
DPA: {
"POSTCODE": "BS1 1AD",
"POST_TOWN": "Bristol",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
body_2 = {
results: [
{
DPA: {
"POSTCODE": "EC1N 2TD",
"POST_TOWN": "Newcastle",
"ORGANISATION_NAME": "Some place",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
.to_return(status: 200, body: body_1, headers: {})
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=12")
.to_return(status: 200, body: body_2, headers: {})
end
around do |example| around do |example|
Timecop.freeze(Time.zone.local(2023, 4, 5)) do Timecop.freeze(Time.zone.local(2023, 4, 5)) do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
@ -84,6 +52,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_wrong_uprn) do let!(:lettings_log_wrong_uprn) do
create(:lettings_log, create(:lettings_log,
:completed,
tenancycode: "tenancycode", tenancycode: "tenancycode",
propcode: "propcode", propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5), startdate: Time.zone.local(2023, 4, 5),
@ -136,7 +105,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
before do before do
lettings_log.update!(address_line1: "existing address", town_or_city: "towncity") lettings_log.update!(address_line1: "existing address", town_or_city: "towncity")
lettings_log_missing_town.update!(town_or_city: "towncity") lettings_log_missing_town.update!(town_or_city: "towncity")
lettings_log_wrong_uprn.update!(uprn: "12", propcode: "12") lettings_log_wrong_uprn.update!(uprn_known: 1, uprn: "12", propcode: "12")
end end
it "returns a csv with relevant logs" do it "returns a csv with relevant logs" do
@ -374,6 +343,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_wrong_uprn) do let!(:lettings_log_wrong_uprn) do
create(:lettings_log, create(:lettings_log,
:completed,
tenancycode: "tenancycode", tenancycode: "tenancycode",
propcode: "propcode", propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5), startdate: Time.zone.local(2023, 4, 5),
@ -388,6 +358,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_not_imported) do let!(:lettings_log_not_imported) do
create(:lettings_log, create(:lettings_log,
:completed,
tenancycode: "tenancycode", tenancycode: "tenancycode",
propcode: "propcode", propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5), startdate: Time.zone.local(2023, 4, 5),
@ -400,7 +371,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
end end
before do before do
lettings_log = create(:lettings_log, managing_organisation: organisation, old_id: "exists") lettings_log = create(:lettings_log, :completed, managing_organisation: organisation, old_id: "exists")
lettings_log.startdate = Time.zone.local(2022, 4, 5) lettings_log.startdate = Time.zone.local(2022, 4, 5)
lettings_log.save!(validate: false) lettings_log.save!(validate: false)
end end

4
spec/shared/shared_log_examples.rb

@ -51,7 +51,7 @@ RSpec.shared_examples "shared log examples" do |log_type|
describe "#process_uprn_change!" do describe "#process_uprn_change!" do
context "when UPRN set to a value" do context "when UPRN set to a value" do
let(:log) do let(:log) do
create( log = build(
log_type, log_type,
uprn: "123456789", uprn: "123456789",
uprn_confirmed: 1, uprn_confirmed: 1,
@ -59,6 +59,8 @@ RSpec.shared_examples "shared log examples" do |log_type|
county: "county", county: "county",
postcode_full: nil, postcode_full: nil,
) )
log.save!(validate: false)
log
end end
it "updates log fields" do it "updates log fields" do

Loading…
Cancel
Save