fix: unify panic room code format and validate room join id

This commit is contained in:
2026-03-03 12:04:00 +08:00
parent 4f4220652e
commit f3d8a58603
7 changed files with 277 additions and 15 deletions
+12 -2
View File
@@ -74,11 +74,11 @@ describe("POST /api/room/[id]/join", () => {
it("returns 404 when room not found", async () => {
mockAtomicUpdate.mockResolvedValue(null);
const req = createRequest("/api/room/NONEXIST/join", {
const req = createRequest("/api/room/ABC123/join", {
method: "POST",
body: { userId: "user-1" },
});
const ctx = createRouteContext({ id: "NONEXIST" });
const ctx = createRouteContext({ id: "ABC123" });
const res = await POST(req, ctx);
expect(res.status).toBe(404);
});
@@ -92,4 +92,14 @@ describe("POST /api/room/[id]/join", () => {
const res = await POST(req, ctx);
expect(res.status).toBe(401);
});
it("returns 400 when room id format is invalid", async () => {
const req = createRequest("/api/room/1234/join", {
method: "POST",
body: { userId: "user-1" },
});
const ctx = createRouteContext({ id: "1234" });
const res = await POST(req, ctx);
expect(res.status).toBe(400);
});
});