Skip to content

Commit d0b39a7

Browse files
committed
add tests to get the OpenAPI schema
1 parent 01e24f2 commit d0b39a7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/live/documentation.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from "vitest";
2+
3+
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
4+
5+
test("Get OpenAPI JSON", async () => {
6+
const response = await fetch(`${baseEndpoint}/api/documentation/json`);
7+
expect(response.status).toBe(200);
8+
9+
const responseDataJson = await response.json();
10+
expect(responseDataJson).toHaveProperty("openapi");
11+
expect(responseDataJson["openapi"]).toEqual("3.0.3");
12+
});
13+
14+
test("Get OpenAPI UI", async () => {
15+
const response = await fetch(`${baseEndpoint}/api/documentation`);
16+
expect(response.status).toBe(200);
17+
const contentType = response.headers.get("content-type");
18+
expect(contentType).toContain("text/html");
19+
});

tests/unit/documentation.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { afterAll, expect, test } from "vitest";
2+
import init from "../../src/api/index.js";
3+
4+
const app = await init();
5+
test("Test getting OpenAPI JSON", async () => {
6+
const response = await app.inject({
7+
method: "GET",
8+
url: "/api/documentation/json",
9+
});
10+
expect(response.statusCode).toBe(200);
11+
const responseDataJson = await response.json();
12+
expect(responseDataJson).toHaveProperty("openapi");
13+
expect(responseDataJson["openapi"]).toEqual("3.0.3");
14+
});
15+
afterAll(async () => {
16+
await app.close();
17+
});
18+
19+
test("Test getting OpenAPI UI", async () => {
20+
const response = await app.inject({
21+
method: "GET",
22+
url: "/api/documentation",
23+
});
24+
expect(response.statusCode).toBe(200);
25+
const contentType = response.headers["content-type"];
26+
expect(contentType).toContain("text/html");
27+
});
28+
afterAll(async () => {
29+
await app.close();
30+
});

0 commit comments

Comments
 (0)