feat : comment feature
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user