forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

websocket-messages.test.ts16 lines, 1007 bytesHistoryRawDownload
1import { describe, expect, it } from "vitest";
2import { parseBoardWsMessage, parseExamWsMessage } from "@/lib/websocket-messages";
3
4describe("websocket message parsers", () => {
5 it("accepts only a complete exam state frame", () => {
6 expect(parseExamWsMessage({ type: "state", status: "in_progress", deadline: null, remaining_ms: 1000, now: 1, answered: 0, question_count: 1 })).not.toBeNull();
7 expect(parseExamWsMessage({ type: "state", status: "open" })).toBeNull();
8 expect(parseExamWsMessage({ type: "saved", question_id: "q", updated_at: "now" })).toBeNull();
9 });
10
11 it("rejects malformed whiteboard frames before they reach the canvas", () => {
12 expect(parseBoardWsMessage({ type: "stroke", id: "s", author: "u", payload: "{}", epoch: 1 })).not.toBeNull();
13 expect(parseBoardWsMessage({ type: "stroke", id: "s", author: "u", payload: {}, epoch: 1 })).toBeNull();
14 expect(parseBoardWsMessage({ type: "participants", creator: "u", participants: ["a", 1] })).toBeNull();
15 });
16});