Add BankAccountCreateJob

This commit is contained in:
Eric Schultz 2019-11-07 13:58:09 -06:00
parent 7c9524ee21
commit 283ebc553b
5 changed files with 9 additions and 33 deletions

View file

@ -58,7 +58,7 @@ module Nonprofits
def resend_confirmation def resend_confirmation
npo = current_nonprofit npo = current_nonprofit
ba = npo.bank_account ba = npo.bank_account
NonprofitMailer.delay.new_bank_account_notification(ba) if ba.valid? BankAccountCreateJob.perform_later(ba) if ba.valid?
respond_to { |format| format.json { render json: {} } } respond_to { |format| format.json { render json: {} } }
end end

View file

@ -0,0 +1,7 @@
class BankAccountCreateJob < ApplicationJob
queue_as :default
def perform(bank_account)
NonprofitMailer.new_bank_account_notification(bank_account).deliver
end
end

View file

@ -53,7 +53,7 @@ module InsertBankAccount
pending_verification: true pending_verification: true
) )
NonprofitMailer.delay.new_bank_account_notification(bank_account) BankAccountCreateJob.perform_later(bank_account)
return bank_account return bank_account
rescue Stripe::StripeError => error rescue Stripe::StripeError => error
params[:failure_message] = "Failed to connect the bank account: #{error.inspect}" params[:failure_message] = "Failed to connect the bank account: #{error.inspect}"

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 NonprofitNewBankAccountJob < EmailJob
attr_reader :ba
def initialize(ba)
@ba = ba
end
def perform
NonprofitMailer.new_bank_account_notification(@ba).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::NonprofitNewBankAccountJob do
describe '.perform' do
it 'calls the correct active mailer' do
expect(NonprofitMailer).to receive(:new_bank_account_notification).with(1).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer }
job = JobTypes::NonprofitNewBankAccountJob.new(1)
job.perform
end
end
end