Skip to content

Commit b7c46a8

Browse files
committed
add a test for protected and tickets routes
1 parent 3da0d75 commit b7c46a8

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tests/live/protected.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect, test, describe } from "vitest";
2+
import { createJwt } from "./utils";
3+
import { allAppRoles } from "../../src/common/roles";
4+
5+
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
6+
7+
describe("Role checking live API tests", async () => {
8+
const token = await createJwt();
9+
test(
10+
"Test that auth is present on the GET route",
11+
{ timeout: 10000 },
12+
async () => {
13+
const response = await fetch(`${baseEndpoint}/api/v1/protected/`, {
14+
method: "GET",
15+
});
16+
expect(response.status).toBe(403);
17+
},
18+
);
19+
test("Test that getting metadata succeeds", { timeout: 10000 }, async () => {
20+
const response = await fetch(`${baseEndpoint}/api/v1/protected`, {
21+
method: "GET",
22+
headers: {
23+
Authorization: `Bearer ${token}`,
24+
},
25+
});
26+
expect(response.status).toBe(200);
27+
const responseBody = await response.json();
28+
expect(responseBody).toStrictEqual({
29+
username: "[email protected]",
30+
roles: allAppRoles,
31+
});
32+
});
33+
});

tests/live/tickets.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test, describe } from "vitest";
2+
import { createJwt } from "./utils";
3+
4+
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
5+
6+
describe("Tickets live API tests", async () => {
7+
const token = await createJwt();
8+
test(
9+
"Test that auth is present on the GET route",
10+
{ timeout: 10000 },
11+
async () => {
12+
const response = await fetch(`${baseEndpoint}/api/v1/tickets/`, {
13+
method: "GET",
14+
});
15+
expect(response.status).toBe(403);
16+
},
17+
);
18+
test("Test that getting metadata succeeds", { timeout: 10000 }, async () => {
19+
const response = await fetch(`${baseEndpoint}/api/v1/tickets`, {
20+
method: "GET",
21+
headers: {
22+
Authorization: `Bearer ${token}`,
23+
},
24+
});
25+
expect(response.status).toBe(200);
26+
const responseBody = await response.json();
27+
expect(responseBody).toHaveProperty("merch");
28+
expect(responseBody).toHaveProperty("tickets");
29+
expect(Array.isArray(responseBody["merch"])).toBe(true);
30+
expect(Array.isArray(responseBody["tickets"])).toBe(true);
31+
});
32+
});

tests/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2020",
44
"module": "NodeNext",
5+
"moduleResolution": "node",
56
"esModuleInterop": true,
67
"strict": true,
78
"skipLibCheck": true,

0 commit comments

Comments
 (0)