mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 22:52:03 +00:00
test(telegram): cover caption and forum service helpers
This commit is contained in:
26
extensions/telegram/src/caption.test.ts
Normal file
26
extensions/telegram/src/caption.test.ts
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
19
extensions/telegram/src/forum-service-message.test.ts
Normal file
19
extensions/telegram/src/forum-service-message.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user