ticket.deleted is published

This commit is contained in:
Eric Schultz 2021-02-03 16:44:24 -06:00 committed by Eric Schultz
parent b7a8f16de6
commit d47c80594c
4 changed files with 95 additions and 11 deletions

View file

@ -4,8 +4,8 @@
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
class TicketMailingListener < ApplicationListener
def self.ticket_purchase_created(ticket_purchase)
tickets_ids = ticket_purchase.tickets_to_legacy_tickets.joins(:ticket).map {|i| i.ticket.id}
charge = ticket_purchase.tickets_to_legacy_tickets.joins(:ticket).first.charge
tickets_ids = ticket_purchase.ticket_to_legacy_tickets.joins(:ticket).map {|i| i.ticket.id}
charge = ticket_purchase.ticket_to_legacy_tickets.joins(:ticket).first.charge
TicketMailer.followup(tickets_ids, charge && charge.id).deliver_later
TicketMailer.receipt_admin(tickets_ids, nil).deliver_later
end

View file

@ -65,4 +65,14 @@ class TicketToLegacyTicket < ApplicationRecord
:event_discount).attributes!)
end
def publish_deleted
Houdini.event_publisher.announce(:ticket_deleted, to_event('ticket.deleted',
:ticket_purchase,
:ticket_level,
:supporter,
:event,
:nonprofit,
:event_discount).attributes!)
end
end

View file

@ -55,12 +55,13 @@ module UpdateTickets
end
def self.delete(event_id, ticket_id)
Qx.update(:tickets)
.set(deleted: true)
.timestamps
.where(id: ticket_id)
.and_where(event_id: event_id)
.execute
Ticket.transaction do
ticket = Event.find(event_id).tickets.find(ticket_id)
ticket.deleted = true
ticket.save!
ticket.ticket_to_legacy_tickets.each {|i| i.publish_deleted}
end
end
def self.delete_card_for_ticket(event_id, ticket_id)

View file

@ -29,7 +29,7 @@ describe UpdateTickets do
let(:general_ticket) do
{
quantity: 1,
quantity: 2,
supporter: supporter,
payment: payment,
charge: charge,
@ -50,7 +50,7 @@ describe UpdateTickets do
let(:general_expected) do
{
id: ticket.id,
quantity: 1,
quantity: 2,
supporter_id: supporter.id,
payment_id: payment.id,
charge_id: charge.id,
@ -233,11 +233,84 @@ describe UpdateTickets do
end
describe '.delete' do
include_context :shared_rd_donation_value_context
let(:trx) {create(:transaction, supporter: supporter)}
let(:basic_valid_ticket_input) do
{ ticket_id: ticket.id, event_id: event.id }
end
let(:include_fake_token) do
basic_valid_ticket_input.merge(token: fake_uuid)
end
let(:include_valid_token) do
basic_valid_ticket_input.merge(token: source_token.token)
end
let(:general_ticket) do
{
quantity: 2,
supporter: supporter,
payment: payment,
charge: charge,
event_discount: event_discount,
created_at: Time.now,
updated_at: Time.now,
checked_in: false,
bid_id: 1,
card_id: nil,
profile_id: nil,
note: nil,
deleted: false,
source_token_id: nil,
ticket_level_id: ticket_level.id
}
end
let(:general_expected) do
{
id: ticket.id,
quantity: 2,
supporter_id: supporter.id,
payment_id: payment.id,
charge_id: charge.id,
event_discount_id: event_discount.id,
created_at: Time.now,
updated_at: Time.now,
checked_in: false,
bid_id: 1,
card_id: nil,
profile_id: nil,
note: nil,
deleted: false,
source_token_id: nil,
event_id: event.id,
ticket_level_id: ticket_level.id
}.with_indifferent_access
end
let(:payment) { force_create(:payment) }
let(:charge) { force_create(:charge) }
let(:ticket) do
tp = trx.ticket_purchases.create(event: event)
ticket = force_create(:ticket,
general_ticket.merge(event: event))
ticket.quantity.times do
ticket.ticket_to_legacy_tickets.create(ticket_purchase: tp)
end
ticket
end
it 'marks the given ticket as deleted=true' do
allow(Houdini.event_publisher).to receive(:announce)
expect(Houdini.event_publisher).to_not receive(:announce).with(:ticket_updated, any_args)
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_deleted, any_args).exactly(ticket.quantity).times
UpdateTickets.delete(ticket['event_id'], ticket['id'])
ticket.reload
expect(ticket['deleted']).to eq(true)
expect(ticket.ticket_to_legacy_tickets.all? {|i| i.deleted}).to eq true
expect(Ticket.count).to eq(1)
end
end