Skip to content

Commit

Permalink
fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
arminpatel committed Mar 31, 2024
1 parent 7d7fecd commit 1bcab7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions backend/tickets/serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from rest_framework import serializers
from .models import Ticket
from events.serializers import EventSerializer
from events.models import Event

class TicketSerializer(serializers.ModelSerializer) :
event = EventSerializer(read_only=True)
event_id = serializers.PrimaryKeyRelatedField(
queryset=Event.objects.all(), source='event', write_only=True)
class Meta:
model = Ticket
fields = [
'id',
'event',
'event_id',
'buyer',
'response',
'purchase_date',
Expand Down
20 changes: 11 additions & 9 deletions backend/tickets/test_tickets_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

ticket_data = {
"event": 1,
"event_id": 1,
"buyer": 1,
"response": "{}",
"purchase_date": "2021-01-01",
Expand Down Expand Up @@ -60,7 +60,7 @@ def testTicketCreation_byUnauthenticatedUser_shouldThrowUnauthorized(test_user,
# Arrange
unauthenticated_client = APIClient()
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event.id
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = test_user.id

# Act
Expand All @@ -75,9 +75,11 @@ def testTicketCreation_byUnauthenticatedUser_shouldThrowUnauthorized(test_user,
def testTicketCreation_byAuthenticatedUser_withValidDetails_shouldCreateTicket(authenticated_client, test_event, test_user):
# Arrange
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event.id
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = test_user.id

print(ticket_data_copy)

# Act
response = authenticated_client.post("/api/tickets/", ticket_data_copy)

Expand All @@ -93,7 +95,7 @@ def testTicketCreation_byAuthenticatedUser_withValidDetails_shouldCreateTicket(a
def testTicketCreation_byAuthenticatedUser_withInvalidEventId_shouldThrowBadRequest(authenticated_client, test_user):
# Arrange
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = 1
ticket_data_copy['event_id'] = 1
ticket_data_copy['buyer'] = test_user.id

# Act
Expand All @@ -108,7 +110,7 @@ def testTicketCreation_byAuthenticatedUser_withInvalidEventId_shouldThrowBadRequ
def testTicketCreation_byAuthenticatedUser_whenBuyerNotEqualsRequestUser_shouldThrowBadRequest(authenticated_client, test_event):
# Arrange
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event.id
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = 2

# Act
Expand All @@ -135,15 +137,15 @@ def testListTicket_byUnauthenticatedUser_shouldThrowUnauthorized():
def testListTicket_byAuthenticatedUser_listsOnlyUsersTickets(authenticated_client, test_user, test_event):
# Arrange
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = test_user

account_data_copy = account_data.copy()
account_data_copy['email'] = 'test@test.test'
test_user2 = Account.objects.create(**account_data_copy)

ticket_data_copy2 = ticket_data.copy()
ticket_data_copy2['event'] = test_event
ticket_data_copy2['event_id'] = test_event.id
ticket_data_copy2['buyer'] = test_user2

Ticket.objects.create(**ticket_data_copy)
Expand All @@ -162,7 +164,7 @@ def testListTicket_byAuthenticatedUser_listsOnlyUsersTickets(authenticated_clien
def testRetrieveTicket_byTicketOwner_shouldReturnSuccessfully(authenticated_client, test_user, test_event):
# Arrange
ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = test_user

ticket = Ticket.objects.create(**ticket_data_copy)
Expand All @@ -183,7 +185,7 @@ def testRetrieveTicket_notByTicketOwner_shouldThrowForbidden(authenticated_clien
test_user2 = Account.objects.create(**account_data_copy)

ticket_data_copy = ticket_data.copy()
ticket_data_copy['event'] = test_event
ticket_data_copy['event_id'] = test_event.id
ticket_data_copy['buyer'] = test_user2

ticket = Ticket.objects.create(**ticket_data_copy)
Expand Down
2 changes: 1 addition & 1 deletion frontend/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const useAuthStore = defineStore('auth', {
});
if (status.value === "success") {
this.access = data.value.access;
this.refresh = data.value.refresh; value
this.refresh = data.value.refresh;
this.user = email;
await navigateTo('/');
toast.success("Login successful", {
Expand Down

0 comments on commit 1bcab7a

Please sign in to comment.