e2e/tests/3.event.test.ts (view raw)
1import { EVENT, EVENT_ID, EVENT_UUID } from "../constants";
2import { EventInput } from "../graphql";
3import { sdk } from "../lib/gqlSdk";
4
5test("createEvent returns created event with minimal parameters", async () => {
6 const event: EventInput = {
7 email: "test+event@octree.ch",
8 name: "Test event",
9 };
10 const request = sdk.createEvent(event);
11
12 await expect(request).resolves.toMatchObject({
13 createEvent: {
14 event: {
15 id: expect.stringMatching(/\d/),
16 waitingPassengers: [],
17 ...event,
18 },
19 },
20 });
21});
22
23test("createEvent returns created event with all parameters", async () => {
24 const event: EventInput = {
25 email: "test+event@octree.ch",
26 name: "Test event",
27 address: "Test address",
28 date: "2032-10-03",
29 description: "Test event description",
30 };
31 const request = sdk.createEvent(event);
32
33 await expect(request).resolves.toMatchObject({
34 createEvent: {
35 event: {
36 id: expect.stringMatching(/\d/),
37 waitingPassengers: [],
38 ...event,
39 },
40 },
41 });
42});
43
44test("updateEvent returns updated event", async () => {
45 const updatedName = "My Caroster event";
46 const request = sdk.updateEvent({
47 uuid: EVENT_UUID,
48 eventUpdate: {
49 name: updatedName,
50 },
51 });
52
53 await expect(request).resolves.toMatchObject({
54 updateEventByUUID: {
55 event: {
56 id: EVENT_ID,
57 description: EVENT.description,
58 name: updatedName,
59 },
60 },
61 });
62});
63
64test("updateEvent returns no event if UUID doesn´t exist", async () => {
65 const request = sdk.updateEvent({
66 uuid: "uuid-that-not-exists",
67 eventUpdate: {
68 name: "random name",
69 },
70 });
71
72 await expect(request).resolves.toMatchObject({
73 updateEventByUUID: {
74 event: null,
75 },
76 });
77});
78
79test("eventByUUID returns event corresponding to UUID", async () => {
80 const request = sdk.eventByUUID({
81 uuid: EVENT_UUID,
82 });
83
84 await expect(request).resolves.toMatchObject({
85 eventByUUID: {
86 id: EVENT_ID,
87 },
88 });
89});
90
91test("eventByUUID fails if UUID doesn't exist", async () => {
92 const request = sdk.eventByUUID({
93 uuid: "uuid-that-not-exists",
94 });
95
96 await expect(request).rejects.toThrow(
97 "Cannot return null for non-nullable field Event.id"
98 );
99});