Add DirectDebitCreateJob

This commit is contained in:
Eric Schultz 2019-11-07 12:12:25 -06:00
parent 860848eb35
commit 052474ac80
7 changed files with 28 additions and 35 deletions

View file

@ -0,0 +1,8 @@
class DirectDebitCreateJob < ApplicationJob
queue_as :default
def perform(donation_id, locale)
DirectDebitCreateNotifyDonorJob.perform_later donation_id, locale
DirectDebitCreateNotifyNonprofitJob.perform_later donation_id, locale
end
end

View file

@ -0,0 +1,7 @@
class DirectDebitCreateNotifyDonorJob < ApplicationJob
queue_as :default
def perform(donation_id, locale)
DonationMailer.donor_direct_debit_notification(donation_id, locale).deliver_now
end
end

View file

@ -0,0 +1,7 @@
class DirectDebitCreateNotifyNonprofitJob < ApplicationJob
queue_as :default
def perform(*args)
# Do something later
end
end

View file

@ -106,8 +106,8 @@ module InsertDonation
result['donation'] = insert_donation(data, entities)
update_donation_keys(result)
DirectDebitCreateJob.perform_later(result['donation'].id, locale_for_supporter(result['donation'].supporter.id))
EmailJobQueue.queue(JobTypes::NonprofitPaymentNotificationJob, result['donation'].id)
EmailJobQueue.queue(JobTypes::DonorDirectDebitNotificationJob, result['donation'].id, locale_for_supporter(result['donation'].supporter.id))
QueueDonations.delay.execute_for_donation(result['donation'].id)
# do this for making test consistent

View file

@ -1,17 +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 DonorDirectDebitNotificationJob < EmailJob
attr_reader :donation_id
def initialize(donation_id, locale = I18n.locale)
@donation_id = donation_id
@locale = locale
end
def perform
DonationMailer.donor_direct_debit_notification(@donation_id, @locale).deliver
end
end
end

View file

@ -1,15 +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::DonorDirectDebitNotificationJob do
describe '.perform' do
it 'calls the correct active mailer' do
expect(DonationMailer).to receive(:donor_direct_debit_notification).with(1, 2).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer }
job = JobTypes::DonorDirectDebitNotificationJob.new(1, 2)
job.perform
end
end
end

View file

@ -371,10 +371,13 @@ RSpec.shared_context :shared_rd_donation_value_context do
def before_each_sepa_success
expect(InsertDonation).to receive(:insert_donation).and_wrap_original do |m, *args|
result = m.call(*args)
expect {
result = m.call(*args)
}.to have_enqueued_job(DirectDebitCreateJob).with(result.id, supporter.local)
@donation_id = result.id
expect_email_queued.with(JobTypes::NonprofitPaymentNotificationJob, @donation_id)
expect_email_queued.with(JobTypes::DonorDirectDebitNotificationJob, @donation_id, supporter.locale)
expect(QueueDonations).to receive(:execute_for_donation).with(@donation_id)
result
end