This commit is contained in:
Schluffe
2026-09-27 14:09:50 +02:00
parent 9758ae6dad
commit a647cd5184
3 changed files with 46 additions and 6 deletions
+45 -2
View File
@@ -1,15 +1,58 @@
import { assertEquals } from "jsr:@std/assert";
import { createSession } from "#/server/handler.ts";
import handler from "./handler.ts";
import { close, connect, flush, href, setup } from "./testSetup.ts";
import { close, connect, flush, hostname, port, setup } from "./testSetup.ts";
const href = `ws://${hostname}:${port}`;
Deno.test(
"test",
"needs upgrade header",
setup(async () => {
const res = await fetch(`http://${hostname}:${port}`);
assertEquals(res.status, 426);
assertEquals(res.statusText, "Upgrade Required");
}, handler),
);
Deno.test(
"needs a session parameter",
setup(async () => {
const res = await connect(href).catch((reason) => {
return reason;
});
assertEquals(
res.message,
"NetworkError: failed to connect to WebSocket: Invalid status code: 400",
);
}, handler),
);
Deno.test(
"needs an existing session",
setup(async () => {
const res = await connect(`${href}?sessionId=DOES_NOT_EXISTS`).catch(
(reason) => {
return reason;
},
);
assertEquals(
res.message,
"NetworkError: failed to connect to WebSocket: Invalid status code: 401",
);
}, handler),
);
Deno.test(
"connects to an existing session",
setup(async () => {
const sessionId = createSession();
const [s1, m1] = await connect(`${href}?sessionId=${sessionId}`);
await flush();
assertEquals(m1, []);
await close(s1);
}, handler),
);