Files
buzz-sheet/lib/comments/events.test.ts
T
gunshiz 5812d99715
CI / Verify (push) Successful in 2m30s
CI / Build immutable images and deploy (push) Successful in 3m9s
feat : comment feature
2026-10-08 01:40:08 +07:00

18 lines
1008 B
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));
const redis = vi.hoisted(() => ({ publish: vi.fn(), get: vi.fn() }));
vi.mock("@/lib/redis/client", () => ({ getRedisClient: redis.get, redisEventChannel: (topic: string) => `test:${topic}` }));
import { notifyCommentChange } from "./events";
describe("comment invalidation events", () => {
beforeEach(() => { redis.publish.mockReset().mockResolvedValue(1); redis.get.mockReset().mockResolvedValue(redis); });
it("notifies the target and admin inbox without exposing comment content", async () => {
await notifyCommentChange("stygian:123");
expect(redis.publish.mock.calls).toEqual([["test:comments:stygian:123", "changed"], ["test:comments:admin", "changed"]]);
});
it("does not fail a committed mutation when Redis is unavailable", async () => {
redis.get.mockRejectedValue(new Error("offline"));
await expect(notifyCommentChange("stygian:123")).resolves.toBeUndefined();
});
});