feat(comments) : add newest and oldest sorting to admin inbox
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ list: vi.fn(), viewer: vi.fn(), admin: vi.fn() }));
|
||||
vi.mock("@/lib/comments/repository", () => ({ listComments: mocks.list, requireCommentViewer: mocks.viewer, requireCommentAdmin: mocks.admin }));
|
||||
import { GET } from "./route";
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.viewer.mockResolvedValue({ id: "admin", admin: true });
|
||||
mocks.list.mockResolvedValue({ items: [], nextCursor: null, viewer: { id: "admin", admin: true } });
|
||||
});
|
||||
|
||||
describe("admin inbox sort selection", () => {
|
||||
it.each([undefined, "newest", "oldest", "invalid"])("normalizes sort %s while forwarding filters and pagination", async (sort) => {
|
||||
const query = new URLSearchParams({ grouped: "true", target: "guide:test", status: "hidden", unanswered: "true", cursor: "cursor" });
|
||||
if (sort) query.set("sort", sort);
|
||||
const response = await GET(new Request(`https://guide.example.test/api/admin/comments?${query}`));
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
|
||||
expect(mocks.admin).toHaveBeenCalledWith({ id: "admin", admin: true });
|
||||
expect(mocks.list).toHaveBeenCalledWith(expect.objectContaining({ sort: sort === "oldest" ? "oldest" : "newest",
|
||||
target: "guide:test", status: "hidden", unanswered: true, grouped: true, cursor: "cursor" }));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user