Browse Source

Update tests and stubs

pull/2102/head
Kat 2 years ago
parent
commit
8b82dfa58b
  1. 63
      spec/lib/tasks/correct_address_from_csv_spec.rb
  2. 132
      spec/lib/tasks/send_missing_addresses_csv_spec.rb
  3. 23
      spec/models/form/lettings/questions/uprn_confirmation_spec.rb
  4. 17
      spec/models/form/lettings/questions/uprn_spec.rb
  5. 17
      spec/models/form/sales/questions/uprn_spec.rb
  6. 64
      spec/request_helper.rb
  7. 18
      spec/requests/duplicate_logs_controller_spec.rb
  8. 36
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  9. 55
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  10. 39
      spec/services/csv/missing_addresses_csv_service_spec.rb
  11. 4
      spec/shared/shared_log_examples.rb

63
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: {})
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: {})
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
describe ":import_lettings_addresses_from_csv", type: :task do
@ -73,19 +57,22 @@ RSpec.describe "data_import" do
end
let!(:lettings_logs) do
create_list(:lettings_log,
3,
uprn_known: 1,
uprn: "1",
uprn_confirmed: nil,
address_line1: "wrong address line1",
address_line2: "wrong address 2",
town_or_city: "wrong town",
county: "wrong city",
postcode_known: 1,
postcode_full: "A1 1AA",
la: "E06000064",
is_la_inferred: true)
logs = build_list(:lettings_log,
3,
:setup_completed,
uprn_known: 1,
uprn: "121",
uprn_confirmed: nil,
address_line1: "wrong address line1",
address_line2: "wrong address 2",
town_or_city: "wrong town",
county: "wrong city",
postcode_known: 1,
postcode_full: "A1 1AA",
la: "E06000064",
is_la_inferred: true)
logs.each { |log| log.save!(validate: false) }
logs
end
before do
@ -135,7 +122,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path)
lettings_logs[1].reload
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].address_line1).to eq("wrong address line1")
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)
lettings_logs[2].reload
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].address_line1).to eq("wrong address line1")
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)
lettings_logs[1].reload
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].address_line1).to eq("wrong address line1")
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)
lettings_logs[2].reload
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].address_line1).to eq("wrong address line1")
expect(lettings_logs[2].address_line2).to eq("wrong address 2")
@ -323,7 +310,7 @@ RSpec.describe "data_import" do
is_la_inferred: true)
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
allow(storage_service).to receive(:get_file_io)
@ -372,7 +359,7 @@ RSpec.describe "data_import" do
task.invoke(addresses_csv_path)
sales_logs[1].reload
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].address_line1).to eq("Wrong Address Line1")
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)
sales_logs[2].reload
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].address_line1).to eq("Wrong Address Line1")
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)
sales_logs[1].reload
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].address_line1).to eq("Wrong Address Line1")
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)
sales_logs[2].reload
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].address_line1).to eq("Wrong Address Line1")
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::Task.define_task(:environment)
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
context "when the rake task is run" do
@ -62,7 +32,7 @@ RSpec.describe "correct_addresses" do
before do
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
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") }
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
it "enqueues the job with correct organisations" do
@ -96,9 +66,11 @@ RSpec.describe "correct_addresses" do
end
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
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, 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, 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: data_provider)
end
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
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
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") }
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
it "enqueues the job with correct organisations" do
@ -146,9 +118,11 @@ RSpec.describe "correct_addresses" do
end
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
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, 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, 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: data_provider)
end
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
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
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") }
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
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") }
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, 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, 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, :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
it "enqueues the job with correct organisations" do
@ -216,8 +190,10 @@ RSpec.describe "correct_addresses" do
end
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
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
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") }
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), 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), 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: data_provider)
end
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") }
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
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::Task.define_task(:environment)
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
context "when the rake task is run" do
@ -307,7 +253,7 @@ RSpec.describe "correct_addresses" do
before do
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
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") }
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
it "enqueues the job with correct organisations" do
@ -341,9 +287,11 @@ RSpec.describe "correct_addresses" do
end
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
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, 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, 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: data_provider)
end
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
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
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") }
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
it "enqueues the job with correct organisations" do
@ -391,9 +339,11 @@ RSpec.describe "correct_addresses" do
end
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
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, 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, 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: data_provider)
end
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
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
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") }
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
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") }
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, 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, 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: data_provider)
end
it "enqueues the job with correct organisations" do
@ -461,8 +411,10 @@ RSpec.describe "correct_addresses" do
end
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
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
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") }
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
it "does enqueues the job with correct skip_uprn_issue_organisations" do

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

@ -7,25 +7,6 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
before do
body = {
results: [
{
DPA: {
"POSTCODE": "AA1 1AA",
"POST_TOWN": "Test Town",
"ORGANISATION_NAME": "1, Test Street",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1234")
.to_return(status: 200, body:, headers: {})
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1")
.to_return(status: 200, body:, headers: {})
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -69,12 +50,12 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
context "when address is present" do
it "returns formatted value" do
log = create(:lettings_log, :setup_completed, address_line1: "1, Test Street", town_or_city: "Test Town", 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(
{
heading: "1, Test Street\nAA1 1AA\nTest Town",
title: "UPRN: 1234",
title: "UPRN: 1",
},
)
end

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

@ -7,23 +7,6 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
before do
body = {
results: [
{
DPA: {
"POSTCODE": "AA1 1AA",
"POST_TOWN": "Test Town",
"ORGANISATION_NAME": "1, Test Street",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1")
.to_return(status: 200, body:, headers: {})
end
it "has correct page" do
expect(question.page).to eq(page)
end

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

@ -7,23 +7,6 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
before do
body = {
results: [
{
DPA: {
"POSTCODE": "AA1 1AA",
"POST_TOWN": "Test Town",
"ORGANISATION_NAME": "1, Test Street",
},
},
],
}.to_json
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=1")
.to_return(status: 200, body:, headers: {})
end
it "has correct page" do
expect(question.page).to eq(page)
end

64
spec/request_helper.rb

@ -19,6 +19,70 @@ module RequestHelper
.to_return(status: 200, body: "", headers: {})
WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/)
.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
def self.real_http_requests

18
spec/requests/duplicate_logs_controller_spec.rb

@ -29,24 +29,6 @@ RSpec.describe DuplicateLogsController, type: :request do
end
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
let(:support_user_org) { create(:organisation) }
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/)
.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?
end
@ -244,7 +229,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_4: "1",
field_18: "100023336956",
field_18: "12",
}
end
@ -693,7 +678,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#validate_nulls" 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
parser.valid?
@ -1484,20 +1469,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#field_18" do # UPRN
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
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
context "when neither UPRN nor address fields are given" do
let(:attributes) do
{
bulk_upload:,
field_1: "1",
}
end
let(:attributes) { setup_section_params }
it "adds appropriate errors" do
expect(parser.errors[:field_18]).to eql(["You must answer UPRN"])
@ -1652,16 +1632,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
describe "#uprn" do
let(:attributes) { { bulk_upload:, field_18: "100023336956" } }
let(:attributes) { { bulk_upload:, field_18: "12" } }
it "sets to given value" do
expect(parser.log.uprn).to eql("100023336956")
expect(parser.log.uprn).to eql("12")
end
end
describe "#uprn_known" 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
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_17: "1",
field_18: "1",
field_19: "100023336956",
field_19: "12",
field_24: "CR0",
field_25: "4BB",
field_26: "E09000008",
@ -187,43 +187,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
stub_request(:get, /api.postcodes.io/)
.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?
end
@ -744,14 +707,14 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
describe "#field_19" do # UPRN
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
expect(parser.errors[:field_19]).to be_blank
end
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_confirmed).to eq(1)
end
@ -774,7 +737,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
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
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
context "when UPRN present" 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
expect(parser.errors[data[:field]]).to be_blank
@ -797,7 +760,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
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
expect(parser.errors[data[:field]]).to be_present
@ -949,16 +912,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
describe "#log" 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
expect(parser.log.uprn).to eql("100023336956")
expect(parser.log.uprn).to eql("12")
end
end
describe "#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
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(: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|
Timecop.freeze(Time.zone.local(2023, 4, 5)) do
Singleton.__init__(FormHandler)
@ -84,6 +52,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_wrong_uprn) do
create(:lettings_log,
:completed,
tenancycode: "tenancycode",
propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5),
@ -136,7 +105,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
before do
lettings_log.update!(address_line1: "existing address", 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
it "returns a csv with relevant logs" do
@ -374,6 +343,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_wrong_uprn) do
create(:lettings_log,
:completed,
tenancycode: "tenancycode",
propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5),
@ -388,6 +358,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
let!(:lettings_log_not_imported) do
create(:lettings_log,
:completed,
tenancycode: "tenancycode",
propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5),
@ -400,7 +371,7 @@ RSpec.describe Csv::MissingAddressesCsvService do
end
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.save!(validate: false)
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
context "when UPRN set to a value" do
let(:log) do
create(
log = build(
log_type,
uprn: "123456789",
uprn_confirmed: 1,
@ -59,6 +59,8 @@ RSpec.shared_examples "shared log examples" do |log_type|
county: "county",
postcode_full: nil,
)
log.save!(validate: false)
log
end
it "updates log fields" do

Loading…
Cancel
Save