Browse Source

Send correct download link

pull/2785/head
Kat 7 months ago
parent
commit
3981ffd318
  1. 5
      app/jobs/email_csv_job.rb
  2. 5
      app/jobs/scheme_email_csv_job.rb
  3. 5
      spec/jobs/email_csv_job_spec.rb
  4. 6
      spec/jobs/scheme_email_csv_job_spec.rb

5
app/jobs/email_csv_job.rb

@ -1,4 +1,5 @@
class EmailCsvJob < ApplicationJob class EmailCsvJob < ApplicationJob
include Rails.application.routes.url_helpers
queue_as :default queue_as :default
BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 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 = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) 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) CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME)
end end

5
app/jobs/scheme_email_csv_job.rb

@ -1,4 +1,5 @@
class SchemeEmailCsvJob < ApplicationJob class SchemeEmailCsvJob < ApplicationJob
include Rails.application.routes.url_helpers
queue_as :default queue_as :default
BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 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 = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["BULK_UPLOAD_BUCKET"])
storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) 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) CsvDownloadMailer.new.send_csv_download_mail(user, url, EXPIRATION_TIME)
end end

5
spec/jobs/email_csv_job_spec.rb

@ -3,8 +3,6 @@ require "rails_helper"
describe EmailCsvJob do describe EmailCsvJob do
include Helpers include Helpers
test_url = :test_url
let(:job) { described_class.new } let(:job) { described_class.new }
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:storage_service) { instance_double(Storage::S3Service) } let(:storage_service) { instance_double(Storage::S3Service) }
@ -22,7 +20,6 @@ describe EmailCsvJob do
before do before do
allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(storage_service).to receive(:write_file) 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(Csv::SalesLogCsvService).to receive(:new).and_return(sales_log_csv_service)
allow(sales_log_csv_service).to receive(:prepare_csv).and_return("") allow(sales_log_csv_service).to receive(:prepare_csv).and_return("")
@ -123,7 +120,7 @@ describe EmailCsvJob do
end end
it "sends an E-mail with the presigned URL and duration" do 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) job.perform(user)
end end
end end

6
spec/jobs/scheme_email_csv_job_spec.rb

@ -3,10 +3,8 @@ require "rails_helper"
describe SchemeEmailCsvJob do describe SchemeEmailCsvJob do
include Helpers include Helpers
test_url = :test_url
let(:job) { described_class.new } 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(:mailer) { instance_double(CsvDownloadMailer, send_csv_download_mail: nil) }
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
@ -144,7 +142,7 @@ describe SchemeEmailCsvJob do
end end
it "sends an E-mail with the presigned URL and duration" do 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) job.perform(user)
end end
end end

Loading…
Cancel
Save