diff --git a/app/models/form/lettings/pages/address.rb b/app/models/form/lettings/pages/address.rb index 389ce172a..916b2f2ca 100644 --- a/app/models/form/lettings/pages/address.rb +++ b/app/models/form/lettings/pages/address.rb @@ -3,6 +3,11 @@ class Form::Lettings::Pages::Address < ::Form::Page super @id = "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 def questions @@ -14,10 +19,4 @@ class Form::Lettings::Pages::Address < ::Form::Page Form::Lettings::Questions::PostcodeForFullAddress.new(nil, nil, self), ] 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 diff --git a/app/models/form/lettings/pages/uprn.rb b/app/models/form/lettings/pages/uprn.rb index f50111798..eb59e4a24 100644 --- a/app/models/form/lettings/pages/uprn.rb +++ b/app/models/form/lettings/pages/uprn.rb @@ -2,6 +2,7 @@ class Form::Lettings::Pages::Uprn < ::Form::Page def initialize(id, hsh, subsection) super @id = "uprn" + @depends_on = [{ "is_supported_housing?" => false }] end def questions @@ -11,10 +12,6 @@ class Form::Lettings::Pages::Uprn < ::Form::Page ] end - def routed_to?(log, _current_user = nil) - !log.is_supported_housing? - end - def skip_text "Enter address instead" end diff --git a/app/models/form/sales/pages/address.rb b/app/models/form/sales/pages/address.rb index 134dcdccc..3078dfe1e 100644 --- a/app/models/form/sales/pages/address.rb +++ b/app/models/form/sales/pages/address.rb @@ -3,6 +3,11 @@ class Form::Sales::Pages::Address < ::Form::Page super @id = "address" @header = "Q15 - What is the property's address?" + @depends_on = [ + { "uprn_known" => nil }, + { "uprn_known" => 0 }, + { "uprn_confirmed" => 0 }, + ] end def questions @@ -14,8 +19,4 @@ class Form::Sales::Pages::Address < ::Form::Page Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self), ] end - - def routed_to?(log, _current_user = nil) - log.uprn_known.nil? || log.uprn_known.zero? || log.uprn_confirmed&.zero? - end end diff --git a/app/models/form/sales/pages/uprn.rb b/app/models/form/sales/pages/uprn.rb index 6df3aaab7..c4ae5b357 100644 --- a/app/models/form/sales/pages/uprn.rb +++ b/app/models/form/sales/pages/uprn.rb @@ -11,10 +11,6 @@ class Form::Sales::Pages::Uprn < ::Form::Page ] end - def routed_to?(_log, _current_user) - true - end - def skip_text "Enter address instead" end diff --git a/spec/lib/tasks/correct_address_from_csv_spec.rb b/spec/lib/tasks/correct_address_from_csv_spec.rb index fca5b79fb..d510babca 100644 --- a/spec/lib/tasks/correct_address_from_csv_spec.rb +++ b/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") diff --git a/spec/lib/tasks/send_missing_addresses_csv_spec.rb b/spec/lib/tasks/send_missing_addresses_csv_spec.rb index 640faf374..b6e2b2958 100644 --- a/spec/lib/tasks/send_missing_addresses_csv_spec.rb +++ b/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 diff --git a/spec/models/form/lettings/pages/address_spec.rb b/spec/models/form/lettings/pages/address_spec.rb index 71f61d2e8..78034f824 100644 --- a/spec/models/form/lettings/pages/address_spec.rb +++ b/spec/models/form/lettings/pages/address_spec.rb @@ -28,46 +28,6 @@ RSpec.describe Form::Lettings::Pages::Address, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to be_nil - 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 + 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 end diff --git a/spec/models/form/lettings/pages/uprn_confirmation_spec.rb b/spec/models/form/lettings/pages/uprn_confirmation_spec.rb index e1c6a587d..66e55979a 100644 --- a/spec/models/form/lettings/pages/uprn_confirmation_spec.rb +++ b/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 expect(page.depends_on).to be_nil 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 diff --git a/spec/models/form/lettings/pages/uprn_spec.rb b/spec/models/form/lettings/pages/uprn_spec.rb index d7ddec73f..009f7b392 100644 --- a/spec/models/form/lettings/pages/uprn_spec.rb +++ b/spec/models/form/lettings/pages/uprn_spec.rb @@ -28,31 +28,13 @@ RSpec.describe Form::Lettings::Pages::Uprn, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to be_nil + expect(page.depends_on).to eq([{ "is_supported_housing?" => false }]) end it "has correct skip_text" do expect(page.skip_text).to eq("Enter address instead") 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 context "when log is nil" do it "is nil" do diff --git a/spec/models/form/lettings/questions/uprn_confirmation_spec.rb b/spec/models/form/lettings/questions/uprn_confirmation_spec.rb index 2bf34e4a9..92563b322 100644 --- a/spec/models/form/lettings/questions/uprn_confirmation_spec.rb +++ b/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 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( { - heading: "1, Test Street\nAA1 1AA\nTest Town\nTest County", - title: "UPRN: 1234", + heading: "1, Test Street\nAA1 1AA\nTest Town", + title: "UPRN: 1", }, ) end @@ -72,7 +72,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do end 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 expect(question.hidden_in_check_answers?(log)).to eq(false) diff --git a/spec/models/form/lettings/questions/uprn_spec.rb b/spec/models/form/lettings/questions/uprn_spec.rb index 98599b99f..21d997446 100644 --- a/spec/models/form/lettings/questions/uprn_spec.rb +++ b/spec/models/form/lettings/questions/uprn_spec.rb @@ -56,6 +56,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do let(:log) do create( :lettings_log, + :completed, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", @@ -77,11 +78,11 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do context "when uprn known" do let(:uprn_known) { 1 } - let(:uprn) { 123_456_789 } + let(:uprn) { 1 } it "returns formatted value" do 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 diff --git a/spec/models/form/sales/pages/address_spec.rb b/spec/models/form/sales/pages/address_spec.rb index 9bdd5f432..c20ac207a 100644 --- a/spec/models/form/sales/pages/address_spec.rb +++ b/spec/models/form/sales/pages/address_spec.rb @@ -28,47 +28,6 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to be_nil - 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 + expect(page.depends_on).to eq([{ "uprn_known" => nil }, { "uprn_known" => 0 }, { "uprn_confirmed" => 0 }]) end end diff --git a/spec/models/form/sales/questions/uprn_spec.rb b/spec/models/form/sales/questions/uprn_spec.rb index e1a1491ad..e08ac4d07 100644 --- a/spec/models/form/sales/questions/uprn_spec.rb +++ b/spec/models/form/sales/questions/uprn_spec.rb @@ -56,9 +56,9 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do let(:log) do create( :sales_log, + :completed, address_line1: "1, Test Street", town_or_city: "Test Town", - county: "Test County", postcode_full: "AA1 1AA", la: "E09000003", uprn_known:, @@ -77,11 +77,11 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do context "when uprn known" do let(:uprn_known) { 1 } - let(:uprn) { 123_456_789 } + let(:uprn) { 1 } it "returns formatted value" do 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 diff --git a/spec/request_helper.rb b/spec/request_helper.rb index 694a97e22..8c5759bec 100644 --- a/spec/request_helper.rb +++ b/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 diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb index 960b43a22..822d74fdb 100644 --- a/spec/requests/duplicate_logs_controller_spec.rb +++ b/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) } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 45ff3e6d1..b1dfb676d 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/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? @@ -1515,20 +1500,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"]) @@ -1683,16 +1663,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) diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 4853afb6f..9cbdc7cdc 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/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) diff --git a/spec/services/csv/missing_addresses_csv_service_spec.rb b/spec/services/csv/missing_addresses_csv_service_spec.rb index 91d538b60..b597a2e9a 100644 --- a/spec/services/csv/missing_addresses_csv_service_spec.rb +++ b/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 diff --git a/spec/shared/shared_log_examples.rb b/spec/shared/shared_log_examples.rb index f9cc59633..354a8b1ee 100644 --- a/spec/shared/shared_log_examples.rb +++ b/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