diff --git a/app/jobs/email_csv_job.rb b/app/jobs/email_csv_job.rb index 55db39bb6..7b9e28aec 100644 --- a/app/jobs/email_csv_job.rb +++ b/app/jobs/email_csv_job.rb @@ -1,4 +1,5 @@ class EmailCsvJob < ApplicationJob + include Rails.application.routes.url_helpers queue_as :default BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 @@ -22,9 +23,9 @@ class EmailCsvJob < ApplicationJob storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"]) storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) - CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type: log_type) + csv_download = CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type: log_type) - url = storage_service.get_presigned_url(filename, EXPIRATION_TIME) + url = download_csv_download_path(csv_download.id) CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME) end diff --git a/app/jobs/scheme_email_csv_job.rb b/app/jobs/scheme_email_csv_job.rb index 764c68882..1b2786684 100644 --- a/app/jobs/scheme_email_csv_job.rb +++ b/app/jobs/scheme_email_csv_job.rb @@ -1,4 +1,5 @@ class SchemeEmailCsvJob < ApplicationJob + include Rails.application.routes.url_helpers queue_as :default BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 @@ -25,9 +26,9 @@ class SchemeEmailCsvJob < ApplicationJob storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"]) storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) - CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type:) + csv_download = CsvDownload.create!(user:, organisation: user.organisation, filename:, download_type:) - url = storage_service.get_presigned_url(filename, EXPIRATION_TIME) + url = download_csv_download_path(csv_download.id) CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME) end diff --git a/spec/jobs/email_csv_job_spec.rb b/spec/jobs/email_csv_job_spec.rb index d60bf2f63..7808e69ff 100644 --- a/spec/jobs/email_csv_job_spec.rb +++ b/spec/jobs/email_csv_job_spec.rb @@ -3,8 +3,6 @@ require "rails_helper" describe EmailCsvJob do include Helpers - test_url = :test_url - let(:job) { described_class.new } let(:user) { FactoryBot.create(:user) } let(:storage_service) { instance_double(Storage::S3Service) } @@ -22,7 +20,6 @@ describe EmailCsvJob do 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::SalesLogCsvService).to receive(:new).and_return(sales_log_csv_service) allow(sales_log_csv_service).to receive(:prepare_csv).and_return("") @@ -123,7 +120,7 @@ describe EmailCsvJob do end it "sends an E-mail with the presigned URL and duration" do - expect(mailer).to receive(:send_csv_download_mail).with(user, test_url, instance_of(Integer)) + expect(mailer).to receive(:send_csv_download_mail).with(user, /csv-downloads/, instance_of(Integer)) job.perform(user) end end diff --git a/spec/jobs/scheme_email_csv_job_spec.rb b/spec/jobs/scheme_email_csv_job_spec.rb index f2eb33233..f3e96014c 100644 --- a/spec/jobs/scheme_email_csv_job_spec.rb +++ b/spec/jobs/scheme_email_csv_job_spec.rb @@ -3,10 +3,8 @@ require "rails_helper" describe SchemeEmailCsvJob do include Helpers - test_url = :test_url - let(:job) { described_class.new } - let(:storage_service) { instance_double(Storage::S3Service, write_file: nil, get_presigned_url: test_url) } + let(:storage_service) { instance_double(Storage::S3Service, write_file: nil) } let(:mailer) { instance_double(CsvDownloadMailer, send_csv_download_mail: nil) } let(:user) { FactoryBot.create(:user) } @@ -144,7 +142,7 @@ describe SchemeEmailCsvJob do end it "sends an E-mail with the presigned URL and duration" do - expect(mailer).to receive(:send_csv_download_mail).with(user, test_url, instance_of(Integer)) + expect(mailer).to receive(:send_csv_download_mail).with(user, /csv-downloads/, instance_of(Integer)) job.perform(user) end end