From 54cd4e038664df8b745081375a4ca4cd62ad0974 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Thu, 14 May 2026 19:28:56 +0700 Subject: [PATCH] fix: type llm moderation test fixtures --- tests/moderation/llmModerationClient.test.ts | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/moderation/llmModerationClient.test.ts b/tests/moderation/llmModerationClient.test.ts index 6ceb508..d9052cd 100644 --- a/tests/moderation/llmModerationClient.test.ts +++ b/tests/moderation/llmModerationClient.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it, vi, beforeEach } from "vitest"; +import type { MessageRecord } from "../../src/moderation/types"; import { parseModerationResponse, runModerationAnalysis, @@ -8,6 +9,33 @@ vi.mock("../../src/retry", () => ({ retryWithBackoff: vi.fn((fn) => fn()), })); +/** + * Helper to create a full MessageRecord fixture with sensible defaults. + * Only override fields that differ from defaults. + */ +function createMessageRecord( + overrides: Partial = {}, +): MessageRecord { + const now = Date.now(); + return { + id: "m1", + guild_id: "guild123", + channel_id: "channel123", + thread_id: null, + user_id: "user123", + username: "user1", + avatar_url: null, + content: "hello", + edited_content: null, + created_at: now, + edited_at: null, + deleted_at: null, + type: "text", + metadata: null, + ...overrides, + }; +} + describe("parseModerationResponse", () => { beforeEach(() => { vi.clearAllMocks(); @@ -255,7 +283,7 @@ describe("runModerationAnalysis", () => { }); const result = await runModerationAnalysis({ - targets: [{ id: "m1", username: "user1", content: "hello" }], + targets: [createMessageRecord()], contextText: "test context", }); @@ -273,7 +301,7 @@ describe("runModerationAnalysis", () => { await expect( runModerationAnalysis({ - targets: [{ id: "m1", username: "user1", content: "hello" }], + targets: [createMessageRecord()], contextText: "test context", }), ).rejects.toThrow(/LLM API error 500/); @@ -287,7 +315,7 @@ describe("runModerationAnalysis", () => { await expect( runModerationAnalysis({ - targets: [{ id: "m1", username: "user1", content: "hello" }], + targets: [createMessageRecord()], contextText: "test context", }), ).rejects.toThrow(/Invalid LLM response structure/); @@ -303,7 +331,7 @@ describe("runModerationAnalysis", () => { await expect( runModerationAnalysis({ - targets: [{ id: "m1", username: "user1", content: "hello" }], + targets: [createMessageRecord()], contextText: "test context", }), ).rejects.toThrow(/No content in LLM response/);