mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-24 00:11:31 +00:00
test(telegram): cover normalization and status issues
This commit is contained in:
25
extensions/telegram/src/normalize.test.ts
Normal file
25
extensions/telegram/src/normalize.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { looksLikeTelegramTargetId, normalizeTelegramMessagingTarget } from "./normalize.js";
|
||||
|
||||
describe("telegram target normalization", () => {
|
||||
it("normalizes telegram prefixes, group targets, and topic suffixes", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:123456")).toBe("telegram:123456");
|
||||
expect(normalizeTelegramMessagingTarget("tg:group:-100123")).toBe(
|
||||
"telegram:group:-100123",
|
||||
);
|
||||
expect(normalizeTelegramMessagingTarget("telegram:-100123:topic:99")).toBe(
|
||||
"telegram:-100123:topic:99",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns undefined for invalid telegram recipients", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:")).toBeUndefined();
|
||||
expect(normalizeTelegramMessagingTarget(" ")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects valid telegram target identifiers", () => {
|
||||
expect(looksLikeTelegramTargetId("telegram:123456")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("tg:group:-100123")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("hello world")).toBe(false);
|
||||
});
|
||||
});
|
||||
77
extensions/telegram/src/status-issues.test.ts
Normal file
77
extensions/telegram/src/status-issues.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
|
||||
import { collectTelegramStatusIssues } from "./status-issues.js";
|
||||
|
||||
describe("collectTelegramStatusIssues", () => {
|
||||
it("reports privacy-mode and wildcard unmentioned-group configuration risks", () => {
|
||||
const issues = collectTelegramStatusIssues([
|
||||
{
|
||||
accountId: "main",
|
||||
enabled: true,
|
||||
configured: true,
|
||||
allowUnmentionedGroups: true,
|
||||
audit: {
|
||||
hasWildcardUnmentionedGroups: true,
|
||||
unresolvedGroups: 2,
|
||||
},
|
||||
} as ChannelAccountSnapshot,
|
||||
]);
|
||||
|
||||
expect(issues).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
channel: "telegram",
|
||||
accountId: "main",
|
||||
kind: "config",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(issues.some((issue) => issue.message.includes("privacy mode"))).toBe(true);
|
||||
expect(issues.some((issue) => issue.message.includes('uses "*"'))).toBe(true);
|
||||
expect(issues.some((issue) => issue.message.includes("unresolvedGroups=2"))).toBe(true);
|
||||
});
|
||||
|
||||
it("reports unreachable groups with match metadata", () => {
|
||||
const issues = collectTelegramStatusIssues([
|
||||
{
|
||||
accountId: "main",
|
||||
enabled: true,
|
||||
configured: true,
|
||||
audit: {
|
||||
groups: [
|
||||
{
|
||||
chatId: "-100123",
|
||||
ok: false,
|
||||
status: "left",
|
||||
error: "403",
|
||||
matchKey: "alerts",
|
||||
matchSource: "channels.telegram.groups",
|
||||
},
|
||||
],
|
||||
},
|
||||
} as ChannelAccountSnapshot,
|
||||
]);
|
||||
|
||||
expect(issues).toHaveLength(1);
|
||||
expect(issues[0]).toMatchObject({
|
||||
channel: "telegram",
|
||||
accountId: "main",
|
||||
kind: "runtime",
|
||||
});
|
||||
expect(issues[0]?.message).toContain("Group -100123 not reachable");
|
||||
expect(issues[0]?.message).toContain("alerts");
|
||||
expect(issues[0]?.message).toContain("channels.telegram.groups");
|
||||
});
|
||||
|
||||
it("ignores accounts that are not both enabled and configured", () => {
|
||||
expect(
|
||||
collectTelegramStatusIssues([
|
||||
{
|
||||
accountId: "main",
|
||||
enabled: false,
|
||||
configured: true,
|
||||
} as ChannelAccountSnapshot,
|
||||
]),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user