Add ExportSupporterNotesFailedJob

This commit is contained in:
Eric Schultz 2019-11-07 13:20:56 -06:00
parent ad2b701f69
commit 2bceb3389c
5 changed files with 10 additions and 34 deletions

View file

@ -0,0 +1,7 @@
class ExportSupporterNotesFailedJob < ApplicationJob
queue_as :default
def perform(export)
ExportMailer.export_supporter_notes_failed_notification(export).deliver_now
end
end

View file

@ -67,7 +67,7 @@ module ExportSupporterNotes
export.ended = Time.now export.ended = Time.now
export.save! export.save!
if user if user
EmailJobQueue.queue(JobTypes::ExportSupporterNotesFailedJob, export) ExportSupporterNotesFailedJob.perform_later export
end end
raise e raise e
end end

View file

@ -1,16 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
module JobTypes
class ExportSupporterNotesFailedJob < EmailJob
attr_reader :export
def initialize(export)
@export = export
end
def perform
ExportMailer.export_supporter_notes_failed_notification(@export).deliver
end
end
end

View file

@ -182,9 +182,9 @@ describe ExportSupporterNotes do
it 'handles exception in upload properly' do it 'handles exception in upload properly' do
Timecop.freeze(2020, 4, 5) do Timecop.freeze(2020, 4, 5) do
@export = force_create(:export, user: user) @export = force_create(:export, user: user)
expect_email_queued.with(JobTypes::ExportSupporterNotesFailedJob, @export)
CHUNKED_UPLOADER.raise_error CHUNKED_UPLOADER.raise_error
Timecop.freeze(2020, 4, 6) do Timecop.freeze(2020, 4, 6) do
expect {
expect { ExportSupporterNotes.run_export(nonprofit.id, {}.to_json, user.id, @export.id) }.to(raise_error do |error| expect { ExportSupporterNotes.run_export(nonprofit.id, {}.to_json, user.id, @export.id) }.to(raise_error do |error|
expect(error).to be_a StandardError expect(error).to be_a StandardError
expect(error.message).to eq TestChunkedUploader::TEST_ERROR_MESSAGE expect(error.message).to eq TestChunkedUploader::TEST_ERROR_MESSAGE
@ -195,6 +195,7 @@ describe ExportSupporterNotes do
expect(@export.ended).to eq Time.now expect(@export.ended).to eq Time.now
expect(@export.updated_at).to eq Time.now expect(@export.updated_at).to eq Time.now
end) end)
}.to have_enqueued_job(ExportSupporterNotesFailedJob).with(@export)
end end
end end
end end

View file

@ -1,16 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper.rb'
describe JobTypes::ExportSupporterNotesFailedJob do
describe '.perform' do
it 'calls the correct active mailer' do
input = 1
expect(ExportMailer).to receive(:export_supporter_notes_failed_notification).with(input).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer }
job = JobTypes::ExportSupporterNotesFailedJob.new(1)
job.perform
end
end
end