hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { parseBoardWsMessage, parseExamWsMessage } from "@/lib/websocket-messages"; |
| 3 | |
| 4 | describe("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 | }); |