40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { normalizeIncoming, TELEGRAM_CAPABILITIES } from "../src/channels/telegram/formatters/messages.js";
|
|
import type { IncomingMessage } from "../src/core/messages.js";
|
|
|
|
describe("normalizeIncoming", () => {
|
|
it("maps a Telegram text message to the normalized contract", () => {
|
|
const ctx = {
|
|
from: { id: 42, first_name: "Ali", language_code: "en" },
|
|
chat: { id: 7 },
|
|
message: { text: "hello there" },
|
|
} as never;
|
|
|
|
const result = normalizeIncoming(ctx as never) as IncomingMessage;
|
|
expect(result.channel).toBe("telegram");
|
|
expect(result.externalUserId).toBe("42");
|
|
expect(result.externalConversationId).toBe("7");
|
|
expect(result.text).toBe("hello there");
|
|
});
|
|
|
|
it("captures photo attachments", () => {
|
|
const ctx = {
|
|
from: { id: 1 },
|
|
chat: { id: 1 },
|
|
message: { photo: [{ file_id: "last" }, { file_id: "big" }] },
|
|
} as never;
|
|
const result = normalizeIncoming(ctx as never) as IncomingMessage;
|
|
expect(result.attachments).toHaveLength(1);
|
|
expect(result.attachments?.[0].fileId).toBe("big");
|
|
});
|
|
});
|
|
|
|
describe("TELEGRAM_CAPABILITIES", () => {
|
|
it("declares Telegram-specific capabilities", () => {
|
|
expect(TELEGRAM_CAPABILITIES.supportsButtons).toBe(true);
|
|
expect(TELEGRAM_CAPABILITIES.supportsAttachments).toBe(true);
|
|
expect(TELEGRAM_CAPABILITIES.supportsRichText).toBe(true);
|
|
expect(TELEGRAM_CAPABILITIES.supportsCommands).toBe(true);
|
|
});
|
|
});
|