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