Browse Source

Skip uprn issue for specified orgs

pull/1953/head
Kat 3 years ago
parent
commit
669e76ceb8
  1. 1
      .env.test
  2. 13
      app/services/csv/missing_addresses_csv_service.rb
  3. 7
      lib/tasks/send_missing_addresses_csv.rake
  4. 11
      spec/lib/tasks/send_missing_addresses_csv_spec.rb
  5. 20
      spec/services/csv/missing_addresses_csv_service_spec.rb

1
.env.test

@ -1,2 +1,3 @@
APP_HOST="http://localhost:3000" APP_HOST="http://localhost:3000"
OS_DATA_KEY=OS_DATA_KEY OS_DATA_KEY=OS_DATA_KEY
SKIP_UPRN_ISSUE_ORG_IDS=[]

13
app/services/csv/missing_addresses_csv_service.rb

@ -18,12 +18,16 @@ module Csv
.where.not(old_form_id: nil) .where.not(old_form_id: nil)
.where.not(address_line1: nil) .where.not(address_line1: nil)
logs_with_wrong_uprn = @organisation.managed_lettings_logs logs_with_wrong_uprn = if JSON.parse(ENV["SKIP_UPRN_ISSUE_ORG_IDS"]).include?(@organisation.id)
[]
else
@organisation.managed_lettings_logs
.imported .imported
.filter_by_year(2023) .filter_by_year(2023)
.where(needstype: 1) .where(needstype: 1)
.where.not(uprn: nil) .where.not(uprn: nil)
.where("uprn = propcode OR uprn = tenancycode or town_or_city = 'Bristol'") .where("uprn = propcode OR uprn = tenancycode or town_or_city = 'Bristol'")
end
return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty? && logs_with_wrong_uprn.empty? return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty? && logs_with_wrong_uprn.empty?
@ -100,12 +104,15 @@ module Csv
.where.not(old_form_id: nil) .where.not(old_form_id: nil)
.where.not(address_line1: nil) .where.not(address_line1: nil)
logs_with_wrong_uprn = @organisation.sales_logs logs_with_wrong_uprn = if JSON.parse(ENV["SKIP_UPRN_ISSUE_ORG_IDS"]).include?(@organisation.id)
[]
else
@organisation.sales_logs
.imported .imported
.filter_by_year(2023) .filter_by_year(2023)
.where.not(uprn: nil) .where.not(uprn: nil)
.where("uprn = purchid or town_or_city = 'Bristol'") .where("uprn = purchid or town_or_city = 'Bristol'")
end
return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty? && logs_with_wrong_uprn.empty? return if logs_with_missing_addresses.empty? && logs_with_missing_town_or_city.empty? && logs_with_wrong_uprn.empty?
CSV.generate(headers: true) do |csv| CSV.generate(headers: true) do |csv|

7
lib/tasks/send_missing_addresses_csv.rake

@ -19,13 +19,16 @@ namespace :correct_addresses do
.where.not(old_form_id: nil) .where.not(old_form_id: nil)
.where.not(address_line1: nil).count .where.not(address_line1: nil).count
logs_impacted_by_uprn_issue = organisation.managed_lettings_logs logs_impacted_by_uprn_issue = if JSON.parse(ENV["SKIP_UPRN_ISSUE_ORG_IDS"]).include?(organisation.id)
[]
else
organisation.managed_lettings_logs
.imported .imported
.filter_by_year(2023) .filter_by_year(2023)
.where(needstype: 1) .where(needstype: 1)
.where.not(uprn: nil) .where.not(uprn: nil)
.where("uprn = propcode OR uprn = tenancycode or town_or_city = 'Bristol'") .where("uprn = propcode OR uprn = tenancycode or town_or_city = 'Bristol'")
end
if logs_impacted_by_missing_address >= MISSING_ADDRESSES_THRESHOLD || logs_impacted_by_missing_town_or_city >= MISSING_ADDRESSES_THRESHOLD || logs_impacted_by_uprn_issue.any? if logs_impacted_by_missing_address >= MISSING_ADDRESSES_THRESHOLD || logs_impacted_by_missing_town_or_city >= MISSING_ADDRESSES_THRESHOLD || logs_impacted_by_uprn_issue.any?
data_coordinators = organisation.users.where(role: 2).filter_by_active data_coordinators = organisation.users.where(role: 2).filter_by_active
users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active

11
spec/lib/tasks/send_missing_addresses_csv_spec.rb

@ -207,6 +207,17 @@ RSpec.describe "correct_addresses" do
task.invoke task.invoke
end end
end end
context "when org is included in SKIP_UPRN_ISSUE_ORG_IDS list" 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)
allow(ENV).to receive(:[]).with("SKIP_UPRN_ISSUE_ORG_IDS").and_return([organisation.id].to_json)
end
it "does not enqueue the job" do
expect { task.invoke }.not_to enqueue_job(EmailMissingAddressesCsvJob)
end
end
end end
end end
end end

20
spec/services/csv/missing_addresses_csv_service_spec.rb

@ -136,6 +136,16 @@ RSpec.describe Csv::MissingAddressesCsvService do
csv = service.create_missing_lettings_addresses_csv csv = service.create_missing_lettings_addresses_csv
expect(csv).to eq(expected_content) expect(csv).to eq(expected_content)
end end
context "and the organisation is in the SKIP_UPRN_ISSUE_ORG_IDS list" do
before do
allow(ENV).to receive(:[]).with("SKIP_UPRN_ISSUE_ORG_IDS").and_return([organisation.id].to_json)
end
it "returns nil" do
expect(service.create_missing_lettings_addresses_csv).to be_nil
end
end
end end
context "when the organisation only has supported housing logs with missing addresses or town or city" do context "when the organisation only has supported housing logs with missing addresses or town or city" do
@ -265,6 +275,16 @@ RSpec.describe Csv::MissingAddressesCsvService do
csv = service.create_missing_sales_addresses_csv csv = service.create_missing_sales_addresses_csv
expect(csv).to eq(expected_content) expect(csv).to eq(expected_content)
end end
context "and the organisation is in the SKIP_UPRN_ISSUE_ORG_IDS list" do
before do
allow(ENV).to receive(:[]).with("SKIP_UPRN_ISSUE_ORG_IDS").and_return([organisation.id].to_json)
end
it "returns nil" do
expect(service.create_missing_sales_addresses_csv).to be_nil
end
end
end end
context "when the organisation only has logs with missing addresses from 2022" do context "when the organisation only has logs with missing addresses from 2022" do

Loading…
Cancel
Save