Skip to content

Commit

Permalink
Fix ticket confirmations & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviupadhyayula committed Oct 9, 2024
1 parent 221ee1b commit 0275dcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5620,17 +5620,19 @@ def _give_tickets(user, order_info, cart, reconciliation_id):
buyer_phone=order_info["billTo"].get("phoneNumber", None),
buyer_email=order_info["billTo"]["email"],
)

tickets.update(owner=user, holder=None, transaction_record=transaction_record)
cart.tickets.clear()
for ticket in tickets:
ticket.send_confirmation_email()

cart.tickets.clear()
Ticket.objects.update_holds()

cart.checkout_context = None
cart.save()

tickets = Ticket.objects.filter(
owner=user, transaction_record=transaction_record
)
for ticket in tickets:
ticket.send_confirmation_email()

@staticmethod
def _place_hold_on_tickets(user, tickets):
"""
Expand Down
13 changes: 13 additions & 0 deletions backend/tests/clubs/test_ticketing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import freezegun
from django.contrib.auth import get_user_model
from django.core import mail
from django.db.models import Count
from django.db.models.deletion import ProtectedError
from django.test import TestCase
Expand Down Expand Up @@ -1019,6 +1020,18 @@ def test_give_tickets(self):
).exists()
self.assertTrue(record_exists)

# Check that confirmation emails were sent
self.assertEqual(len(mail.outbox), len(tickets_to_add))
for msg in mail.outbox:
self.assertIn(
f"Ticket confirmation for {self.user1.first_name} "
f"{self.user1.last_name}",
msg.subject,
)
self.assertIn(self.user1.first_name, msg.body)
self.assertIn(self.event1.name, msg.body)
self.assertIsNotNone(msg.attachments)

def test_initiate_checkout_non_free_tickets(self):
self.client.login(username=self.user1.username, password="test")

Expand Down

0 comments on commit 0275dcb

Please sign in to comment.