-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.ts
More file actions
47 lines (41 loc) · 1.44 KB
/
server.test.ts
File metadata and controls
47 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { expect, test, describe, beforeAll, afterAll } from "bun:test";
import { join } from "node:path";
import { rm, mkdir, writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import { serverOptions } from "./server";
const TEST_PROJECT_DIR = "test-project";
const TEST_FILE = join(TEST_PROJECT_DIR, "index.html");
describe("A-Frame Git Editor Server", () => {
let server: any;
beforeAll(async () => {
if (existsSync(TEST_PROJECT_DIR)) {
await rm(TEST_PROJECT_DIR, { recursive: true });
}
await mkdir(TEST_PROJECT_DIR, { recursive: true });
await writeFile(TEST_FILE, "<html><body><a-scene></a-scene></body></html>");
// Start in-process server for testing
server = Bun.serve({
...serverOptions,
port: 0
});
});
afterAll(async () => {
server.stop();
await rm(TEST_PROJECT_DIR, { recursive: true });
});
test("Save endpoint returns 200 OK by default (insecure)", async () => {
const response = await fetch(`${server.url.origin}/save`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
updates: [{
selector: "a-scene",
components: { "background": "color: red" }
}]
})
});
// It might fail because of sync() trying to write to disk or git not being init
// but the authentication check should pass.
expect(response.status).not.toBe(401);
});
});