Browse Source

Move constant

pull/1953/head
Kat 3 years ago
parent
commit
193e7fe1ed
  1. 1
      app/jobs/email_missing_addresses_csv_job.rb
  2. 11
      lib/tasks/send_missing_addresses_csv.rake
  3. 4
      spec/lib/tasks/send_missing_addresses_csv_spec.rb

1
app/jobs/email_missing_addresses_csv_job.rb

@ -3,6 +3,7 @@ class EmailMissingAddressesCsvJob < ApplicationJob
BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8
EXPIRATION_TIME = 72.hours.to_i
MISSING_ADDRESSES_THRESHOLD = 50
def perform(user_ids, organisation, log_type)
csv_service = Csv::MissingAddressesCsvService.new(organisation)

11
lib/tasks/send_missing_addresses_csv.rake

@ -1,8 +1,4 @@
namespace :correct_addresses do
# rubocop:disable Lint/ConstantDefinitionInBlock
MISSING_ADDRESSES_THRESHOLD = 50
# rubocop:enable Lint/ConstantDefinitionInBlock
desc "Send missing lettings addresses csv"
task :send_missing_addresses_lettings_csv, %i[] => :environment do |_task, _args|
Organisation.all.each do |organisation|
@ -29,7 +25,9 @@ namespace :correct_addresses do
.where.not(uprn: nil)
.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?
missing_addresses_threshold = EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD
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
users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active
EmailMissingAddressesCsvJob.perform_later(users_to_contact.map(&:id), organisation, "lettings")
@ -65,7 +63,8 @@ namespace :correct_addresses do
.where.not(uprn: nil)
.where("uprn = purchid 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?
missing_addresses_threshold = EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD
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
users_to_contact = data_coordinators.any? ? data_coordinators : organisation.users.filter_by_active
EmailMissingAddressesCsvJob.perform_later(users_to_contact.map(&:id), organisation, "sales")

4
spec/lib/tasks/send_missing_addresses_csv_spec.rb

@ -46,7 +46,7 @@ RSpec.describe "correct_addresses" do
let(:organisation) { create(:organisation, name: "test organisation") }
before do
stub_const("MISSING_ADDRESSES_THRESHOLD", 5)
stub_const("EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD", 5)
end
context "when org has more than 5 missing addresses and data coordinators" do
@ -265,7 +265,7 @@ RSpec.describe "correct_addresses" do
let(:organisation) { create(:organisation, name: "test organisation") }
before do
stub_const("MISSING_ADDRESSES_THRESHOLD", 5)
stub_const("EmailMissingAddressesCsvJob::MISSING_ADDRESSES_THRESHOLD", 5)
end
context "when org has more than 5 missing addresses and data coordinators" do

Loading…
Cancel
Save