|
1 | 1 | import { expect, test } from "vitest"; |
2 | 2 | import { EventsGetResponse } from "../../src/api/routes/events.js"; |
| 3 | +import { createJwt } from "./utils.js"; |
3 | 4 |
|
4 | 5 | const baseEndpoint = `https://infra-core-api.aws.qa.acmuiuc.org`; |
5 | | - |
| 6 | +let createdEventUuid; |
6 | 7 | test("getting events", async () => { |
7 | 8 | const response = await fetch(`${baseEndpoint}/api/v1/events`); |
8 | 9 | expect(response.status).toBe(200); |
9 | 10 | const responseJson = (await response.json()) as EventsGetResponse; |
10 | 11 | expect(responseJson.length).greaterThan(0); |
11 | 12 | }); |
| 13 | + |
| 14 | +test("creating an event", async () => { |
| 15 | + const token = await createJwt(); |
| 16 | + const response = await fetch(`${baseEndpoint}/api/v1/events`, { |
| 17 | + method: "POST", |
| 18 | + headers: { |
| 19 | + Authorization: `Bearer ${token}`, |
| 20 | + "Content-Type": "application/json", |
| 21 | + }, |
| 22 | + body: JSON.stringify({ |
| 23 | + title: "Testing Event", |
| 24 | + description: "An event of all time", |
| 25 | + start: "2024-12-31T02:00:00", |
| 26 | + end: "2024-12-31T03:30:00", |
| 27 | + location: "ACM Room (Siebel 1104)", |
| 28 | + host: "ACM", |
| 29 | + featured: true, |
| 30 | + }), |
| 31 | + }); |
| 32 | + expect(response.status).toBe(200); |
| 33 | + const responseJson = await response.json(); |
| 34 | + expect(responseJson).toHaveProperty("id"); |
| 35 | + expect(responseJson).toHaveProperty("resource"); |
| 36 | + createdEventUuid = responseJson.id; |
| 37 | +}); |
| 38 | + |
| 39 | +test.runIf(createdEventUuid)( |
| 40 | + "deleting a previously-created event", |
| 41 | + async () => { |
| 42 | + const token = await createJwt(); |
| 43 | + const response = await fetch( |
| 44 | + `${baseEndpoint}/api/v1/events/${createdEventUuid}`, |
| 45 | + { |
| 46 | + method: "DELETE", |
| 47 | + headers: { |
| 48 | + Authorization: `Bearer ${token}`, |
| 49 | + }, |
| 50 | + }, |
| 51 | + ); |
| 52 | + expect(response.status).toBe(201); |
| 53 | + }, |
| 54 | +); |
| 55 | + |
| 56 | +test.runIf(createdEventUuid)( |
| 57 | + "check that deleted events cannot be found", |
| 58 | + async () => { |
| 59 | + const response = await fetch( |
| 60 | + `${baseEndpoint}/api/v1/events/${createdEventUuid}`, |
| 61 | + { |
| 62 | + method: "GET", |
| 63 | + }, |
| 64 | + ); |
| 65 | + expect(response.status).toBe(404); |
| 66 | + }, |
| 67 | +); |
0 commit comments