59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { assertEquals } from "jsr:@std/assert";
|
|
import { createSession } from "#/server/handler.ts";
|
|
import handler from "./handler.ts";
|
|
import { close, connect, flush, hostname, port, setup } from "./testSetup.ts";
|
|
|
|
const href = `ws://${hostname}:${port}`;
|
|
|
|
Deno.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),
|
|
);
|