WIP
This commit is contained in:
+45
-2
@@ -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),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user