Skip to content

Commit 8dd05fb

Browse files
committed
Updates
1 parent 589ab1b commit 8dd05fb

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

backend/api/participants/queries.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from typing import Optional
32
from django.conf import settings
43
import strawberry
54
from strawberry.tools import create_type
@@ -15,9 +14,7 @@
1514

1615

1716
@strawberry.field
18-
def participant(
19-
info: Info, id: strawberry.ID, conference: str
20-
) -> Optional[Participant]:
17+
def participant(info: Info, id: strawberry.ID, conference: str) -> Participant | None:
2118
decoded_id = decode_hashid(id, salt=settings.USER_ID_HASH_SALT, min_length=6)
2219
participant = ParticipantModel.objects.filter(
2320
conference__code=conference, id=decoded_id
@@ -32,7 +29,7 @@ def participant(
3229
@strawberry.field
3330
def ticket_id_to_user_hashid(
3431
ticket_id: strawberry.ID, conference_code: str
35-
) -> Optional[str]:
32+
) -> str | None:
3633
conference = Conference.objects.filter(code=conference_code).first()
3734
decoded_ticket_id = decode_hashid(ticket_id)
3835
order_position = pretix.get_order_position(conference, decoded_ticket_id)

backend/api/participants/tests/__init__.py

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from conferences.tests.factories import ConferenceFactory
2+
from participants.tests.factories import ParticipantFactory
3+
4+
5+
def test_query_participant(graphql_client):
6+
participant = ParticipantFactory()
7+
8+
response = graphql_client.query(
9+
"""
10+
query Participant($id: ID!, $conference: String!) {
11+
participant(id: $id, conference: $conference) {
12+
id
13+
fullname
14+
}
15+
}
16+
""",
17+
variables={"id": participant.hashid, "conference": participant.conference.code},
18+
)
19+
20+
assert response["data"]["participant"]["id"] == participant.hashid
21+
assert response["data"]["participant"]["fullname"] == participant.user.fullname
22+
23+
24+
def test_query_participant_with_wrong_conference(graphql_client):
25+
participant = ParticipantFactory()
26+
27+
response = graphql_client.query(
28+
"""
29+
query Participant($id: ID!, $conference: String!) {
30+
participant(id: $id, conference: $conference) {
31+
id
32+
fullname
33+
}
34+
}
35+
""",
36+
variables={"id": participant.hashid, "conference": ConferenceFactory().code},
37+
)
38+
39+
assert response["data"]["participant"] is None
40+
41+
42+
def test_query_participant_with_non_existent_id(graphql_client):
43+
response = graphql_client.query(
44+
"""
45+
query Participant($id: ID!, $conference: String!) {
46+
participant(id: $id, conference: $conference) {
47+
id
48+
fullname
49+
}
50+
}
51+
""",
52+
variables={"id": "abcabc", "conference": ConferenceFactory().code},
53+
)
54+
55+
assert response["data"]["participant"] is None

0 commit comments

Comments
 (0)