Add TicketCreateJob
This commit is contained in:
parent
e3a10f0980
commit
1fa53e65f2
5 changed files with 12 additions and 36 deletions
7
app/jobs/ticket_create_job.rb
Normal file
7
app/jobs/ticket_create_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class TicketCreateJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(ticket_ids, charge)
|
||||||
|
TicketMailer.followup(ticket_ids, charge_id).deliver_now
|
||||||
|
end
|
||||||
|
end
|
|
@ -100,8 +100,8 @@ module InsertTickets
|
||||||
ticket_ids = result['tickets'].map(&:id)
|
ticket_ids = result['tickets'].map(&:id)
|
||||||
charge_id = result['charge'] ? result['charge'].id : nil
|
charge_id = result['charge'] ? result['charge'].id : nil
|
||||||
|
|
||||||
|
TicketCreateJob.perform_later(ticket_ids, charge_id && Charge.find(result['charge']&.id))
|
||||||
EmailJobQueue.queue(JobTypes::TicketMailerReceiptAdminJob, ticket_ids)
|
EmailJobQueue.queue(JobTypes::TicketMailerReceiptAdminJob, ticket_ids)
|
||||||
EmailJobQueue.queue(JobTypes::TicketMailerFollowupJob, ticket_ids, charge_id)
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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 TicketMailerFollowupJob < EmailJob
|
|
||||||
attr_reader :ticket_ids, :charge_id
|
|
||||||
|
|
||||||
def initialize(ticket_ids, charge_id)
|
|
||||||
@ticket_ids = ticket_ids
|
|
||||||
@charge_id = charge_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform
|
|
||||||
TicketMailer.followup(@ticket_ids, @charge_id).deliver
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -106,8 +106,6 @@ describe InsertTickets do
|
||||||
ticket_ids = tickets.map(&:id)
|
ticket_ids = tickets.map(&:id)
|
||||||
expect(InsertActivities).to receive(:for_tickets).with(ticket_ids)
|
expect(InsertActivities).to receive(:for_tickets).with(ticket_ids)
|
||||||
expect_email_queued.with(JobTypes::TicketMailerReceiptAdminJob, ticket_ids).once
|
expect_email_queued.with(JobTypes::TicketMailerReceiptAdminJob, ticket_ids).once
|
||||||
# TODO: the `anything` should be the charge_id but don't have an obvious way of getting that now.
|
|
||||||
expect_email_queued.with(JobTypes::TicketMailerFollowupJob, ticket_ids, anything).once
|
|
||||||
tickets
|
tickets
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -287,7 +285,10 @@ describe InsertTickets do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
success_expectations
|
success_expectations
|
||||||
expect(QueryRoles).to receive(:is_authorized_for_nonprofit?).with(user.id, nonprofit.id).and_return true
|
expect(QueryRoles).to receive(:is_authorized_for_nonprofit?).with(user.id, nonprofit.id).and_return true
|
||||||
result = InsertTickets.create(tickets: [{ quantity: 1, ticket_level_id: ticket_level.id }], nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: event.id, kind: 'offsite', offsite_payment: { kind: 'check', check_number: 'fake_checknumber' }, current_user: user)
|
result = nil
|
||||||
|
expect {
|
||||||
|
result = InsertTickets.create(tickets: [{ quantity: 1, ticket_level_id: ticket_level.id }], nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: event.id, kind: 'offsite', offsite_payment: { kind: 'check', check_number: 'fake_checknumber' }, current_user: user)
|
||||||
|
}.to have_enqueued_job(TicketCreateJob)
|
||||||
expected = generate_expected_tickets(payment_id: result['payment'].id,
|
expected = generate_expected_tickets(payment_id: result['payment'].id,
|
||||||
nonprofit: nonprofit,
|
nonprofit: nonprofit,
|
||||||
supporter: supporter,
|
supporter: supporter,
|
||||||
|
|
|
@ -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::TicketMailerFollowupJob do
|
|
||||||
describe '.perform' do
|
|
||||||
it 'calls the correct active mailer' do
|
|
||||||
expect(TicketMailer).to receive(:followup).with(1, 2).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer }
|
|
||||||
|
|
||||||
job = JobTypes::TicketMailerFollowupJob.new(1, 2)
|
|
||||||
job.perform
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue