Files
dc-recorder/tests/routes/syncRoutes.test.ts
MythEclipse ed438e6fc0 feat: split text and voice channel selection
Separate text moderation and voice recording guild/channel state so each workflow can persist and operate independently.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 15:58:38 +07:00

48 lines
1.3 KiB
TypeScript

import type { Request, Response } from "express";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createSyncRoutes } from "../../src/routes/syncRoutes";
const syncSelectedChannelBacklog = vi.hoisted(() => vi.fn());
vi.mock("../../src/moderation/backlogSync", () => ({
syncSelectedChannelBacklog,
}));
describe("createSyncRoutes", () => {
beforeEach(() => {
syncSelectedChannelBacklog.mockReset();
});
it("syncs the selected guild and channel from the request", async () => {
syncSelectedChannelBacklog.mockResolvedValue(3);
const router = createSyncRoutes({} as never);
const route = router.stack.find(
(layer) => layer.route?.path === "/backlog-sync",
);
const handler = route?.route?.stack[0]?.handle;
const json = vi.fn();
const next = vi.fn();
await handler?.(
{
body: { guildId: "selected-guild", channelId: "selected-channel" },
} as Request,
{ json } as unknown as Response,
next,
);
expect(syncSelectedChannelBacklog).toHaveBeenCalledWith(
{},
"selected-guild",
"selected-channel",
);
expect(json).toHaveBeenCalledWith({
success: true,
channelId: "selected-channel",
messagesSync: 3,
});
expect(next).not.toHaveBeenCalled();
});
});