refactor: add inbound context helpers
This commit is contained in:
21
test/helpers/inbound-contract.ts
Normal file
21
test/helpers/inbound-contract.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { normalizeChatType } from "../../src/channels/chat-type.js";
|
||||
import { resolveConversationLabel } from "../../src/channels/conversation-label.js";
|
||||
import { validateSenderIdentity } from "../../src/channels/sender-identity.js";
|
||||
import type { MsgContext } from "../../src/auto-reply/templating.js";
|
||||
|
||||
export function expectInboundContextContract(ctx: MsgContext) {
|
||||
expect(validateSenderIdentity(ctx)).toEqual([]);
|
||||
|
||||
expect(ctx.Body).toBeTypeOf("string");
|
||||
expect(ctx.BodyForAgent).toBeTypeOf("string");
|
||||
expect(ctx.BodyForCommands).toBeTypeOf("string");
|
||||
|
||||
const chatType = normalizeChatType(ctx.ChatType);
|
||||
if (chatType && chatType !== "direct") {
|
||||
const label = ctx.ConversationLabel?.trim() || resolveConversationLabel(ctx);
|
||||
expect(label).toBeTruthy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user