Files
buzz-sheet/components/comments/client.test.ts
T
gunshiz a04a76fd70
CI / Verify (push) Successful in 1m47s
CI / Build immutable images and deploy (push) Successful in 2m47s
feat : use only thai
2026-10-08 23:37:19 +07:00

23 lines
1.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { commentRequest, COMMENT_ERRORS } from "./client";
afterEach(() => vi.unstubAllGlobals());
describe("comment error language", () => {
it("supplies Thai messages for every error code", () => {
for (const message of Object.values(COMMENT_ERRORS)) expect(message).toMatch(/[\u0e00-\u0e7f]/);
});
it("shows Thai server errors and preserves uncached requests", async () => {
const fetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({ error: "comment-edited-reload" }), { status: 409 }));
vi.stubGlobal("fetch", fetch);
await expect(commentRequest("/api/comments/test")).rejects.toThrow("ข้อความร่างของคุณยังอยู่");
expect(fetch).toHaveBeenCalledWith("/api/comments/test", { cache: "no-store" });
});
it("uses a Thai fallback when an error response is not JSON", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response("Unavailable", { status: 503 })));
await expect(commentRequest("/api/comments")).rejects.toThrow("ไม่สามารถทำรายการได้ กรุณาลองใหม่");
});
});