Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.5 KiB

CLDC-2810 Send missing addresses template (#1952) * Add missing addresses csv job * Update missing addresses csv service methods * Add rake task * Update the job to send missing town or city templates * Update service to create mising town or city templates * Add send missing town or city csv rake task * Add IDs to the CSVs * Put all log in the same csv * Add issue type column * Write wrong uprn logs to csv * Add mailer methods * Skip uprn issue for specified orgs * Add sales csv rake task * set SKIP_UPRN_ISSUE_ORG_IDS on review apps * test * Update notify template IDs for testing * Initialize service with organisation instead of a hash * Add expiration time to url * Add optional tags and remove LA from csv * Extract log to csv methods * Update casing * Update old IDs in factories * Move constant * Extract some repeating scopes * Pass in organisations to skip instead of using an env var * update template id for sales * Update link expiry time and headers * Lower the threshold for testing * Add issue explanation to the email * Add how to fix * update emails * CLDC-2810 Create all addresses CSV (#1953) * Add rake tasks for creating all addresses CSV * Write headers if logs don't exist, update header names * Rename method * CLDC-2810 Correct addresses from csv (#1957) * Updating importing lettings addresses form csv * Add import_sales_addresses_from_csv rake * Allow correcting addresses from both templates * escape . * Reinfer LA if the postcode hasn't changed * Update labels and email content * Update missing addresses threshold * Remove unused env var
1 year ago
require "rails_helper"
describe EmailMissingAddressesCsvJob do
include Helpers
test_url = :test_url
let(:job) { described_class.new }
let(:storage_service) { instance_double(Storage::S3Service) }
let(:mailer) { instance_double(CsvDownloadMailer) }
let(:missing_addresses_csv_service) { instance_double(Csv::MissingAddressesCsvService) }
let(:organisation) { build(:organisation) }
let(:users) { create_list(:user, 2) }
before do
allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(storage_service).to receive(:write_file)
allow(storage_service).to receive(:get_presigned_url).and_return(test_url)
allow(Csv::MissingAddressesCsvService).to receive(:new).and_return(missing_addresses_csv_service)
allow(missing_addresses_csv_service).to receive(:create_missing_lettings_addresses_csv).and_return("")
allow(missing_addresses_csv_service).to receive(:create_missing_sales_addresses_csv).and_return("")
allow(CsvDownloadMailer).to receive(:new).and_return(mailer)
allow(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail)
allow(mailer).to receive(:send_missing_sales_addresses_csv_download_mail)
end
context "when sending missing lettings logs csv" do
it "uses an appropriate filename in S3" do
expect(storage_service).to receive(:write_file).with(/missing-lettings-logs-addresses-#{organisation.name}-.*\.csv/, anything)
job.perform(users.map(&:id), organisation, "lettings", %w[missing_address wrong_uprn], [1, 2])
end
it "creates a MissingAddressesCsvService with the correct organisation and calls create missing lettings logs adresses csv" do
expect(Csv::MissingAddressesCsvService).to receive(:new).with(organisation, [1, 2])
expect(missing_addresses_csv_service).to receive(:create_missing_lettings_addresses_csv)
job.perform(users.map(&:id), organisation, "lettings", %w[missing_address wrong_uprn], [1, 2])
end
it "sends emails to all the provided users" do
expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[0], test_url, instance_of(Integer), %w[missing_address wrong_uprn])
expect(mailer).to receive(:send_missing_lettings_addresses_csv_download_mail).with(users[1], test_url, instance_of(Integer), %w[missing_address wrong_uprn])
job.perform(users.map(&:id), organisation, "lettings", %w[missing_address wrong_uprn], [1, 2])
end
end
context "when sending missing sales logs csv" do
it "uses an appropriate filename in S3" do
expect(storage_service).to receive(:write_file).with(/missing-sales-logs-addresses-#{organisation.name}-.*\.csv/, anything)
job.perform(users.map(&:id), organisation, "sales", %w[missing_town], [2, 3])
end
it "creates a MissingAddressesCsvService with the correct organisation and calls create missing sales logs adresses csv" do
expect(Csv::MissingAddressesCsvService).to receive(:new).with(organisation, [2, 3])
expect(missing_addresses_csv_service).to receive(:create_missing_sales_addresses_csv)
job.perform(users.map(&:id), organisation, "sales", %w[missing_town], [2, 3])
end
it "sends emails to all the provided users" do
expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[0], test_url, instance_of(Integer), %w[missing_town])
expect(mailer).to receive(:send_missing_sales_addresses_csv_download_mail).with(users[1], test_url, instance_of(Integer), %w[missing_town])
job.perform(users.map(&:id), organisation, "sales", %w[missing_town], [2, 3])
end
end
end