test(telegram): cover caption and forum service helpers

This commit is contained in:
Vincent Koc
2026-03-22 15:58:33 -07:00
parent bd8ca6dbd7
commit 377be1329d
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { splitTelegramCaption, TELEGRAM_MAX_CAPTION_LENGTH } from "./caption.js";
describe("splitTelegramCaption", () => {
it("returns empty parts for blank captions", () => {
expect(splitTelegramCaption(" ")).toEqual({
caption: undefined,
followUpText: undefined,
});
});
it("keeps short captions inline", () => {
expect(splitTelegramCaption(" hello ")).toEqual({
caption: "hello",
followUpText: undefined,
});
});
it("moves oversized captions into follow-up text", () => {
const text = "x".repeat(TELEGRAM_MAX_CAPTION_LENGTH + 1);
expect(splitTelegramCaption(text)).toEqual({
caption: undefined,
followUpText: text,
});
});
});

View File

@@ -0,0 +1,19 @@
import { describe, expect, it } from "vitest";
import {
isTelegramForumServiceMessage,
TELEGRAM_FORUM_SERVICE_FIELDS,
} from "./forum-service-message.js";
describe("isTelegramForumServiceMessage", () => {
it("returns true for any Telegram forum service field", () => {
for (const field of TELEGRAM_FORUM_SERVICE_FIELDS) {
expect(isTelegramForumServiceMessage({ [field]: {} })).toBe(true);
}
});
it("returns false for normal messages and non-objects", () => {
expect(isTelegramForumServiceMessage({ text: "hello" })).toBe(false);
expect(isTelegramForumServiceMessage(null)).toBe(false);
expect(isTelegramForumServiceMessage("topic created")).toBe(false);
});
});