mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 03:56:45 +00:00
test: tighten channel summary coverage
This commit is contained in:
@@ -66,6 +66,64 @@ function makeSlackHttpSummaryPlugin(): ChannelPlugin {
|
||||
};
|
||||
}
|
||||
|
||||
function makeTelegramSummaryPlugin(params: {
|
||||
enabled: boolean;
|
||||
configured: boolean;
|
||||
linked?: boolean;
|
||||
authAgeMs?: number;
|
||||
allowFrom?: string[];
|
||||
}): ChannelPlugin {
|
||||
return {
|
||||
id: "telegram",
|
||||
meta: {
|
||||
id: "telegram",
|
||||
label: "Telegram",
|
||||
selectionLabel: "Telegram",
|
||||
docsPath: "/channels/telegram",
|
||||
blurb: "test",
|
||||
},
|
||||
capabilities: { chatTypes: ["direct"] },
|
||||
config: {
|
||||
listAccountIds: () => ["primary"],
|
||||
defaultAccountId: () => "primary",
|
||||
inspectAccount: () => ({
|
||||
accountId: "primary",
|
||||
name: "Main Bot",
|
||||
enabled: params.enabled,
|
||||
configured: params.configured,
|
||||
linked: params.linked,
|
||||
allowFrom: params.allowFrom ?? [],
|
||||
dmPolicy: "mutuals",
|
||||
tokenSource: "env",
|
||||
}),
|
||||
resolveAccount: () => ({
|
||||
accountId: "primary",
|
||||
name: "Main Bot",
|
||||
enabled: params.enabled,
|
||||
configured: params.configured,
|
||||
linked: params.linked,
|
||||
allowFrom: params.allowFrom ?? [],
|
||||
dmPolicy: "mutuals",
|
||||
tokenSource: "env",
|
||||
}),
|
||||
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
|
||||
isEnabled: (account) => Boolean((account as { enabled?: boolean }).enabled),
|
||||
formatAllowFrom: () => ["alice", "bob", "carol"],
|
||||
},
|
||||
status: {
|
||||
buildChannelSummary: async () => ({
|
||||
linked: params.linked,
|
||||
configured: params.configured,
|
||||
authAgeMs: params.authAgeMs,
|
||||
self: { e164: "+15551234567" },
|
||||
}),
|
||||
},
|
||||
actions: {
|
||||
listActions: () => ["send"],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildChannelSummary", () => {
|
||||
it("preserves Slack HTTP signing-secret unavailable state from source config", async () => {
|
||||
vi.mocked(listChannelPlugins).mockReturnValue([makeSlackHttpSummaryPlugin()]);
|
||||
@@ -81,4 +139,37 @@ describe("buildChannelSummary", () => {
|
||||
" - primary (Primary) (bot:config, signing:config, secret unavailable in this command path)",
|
||||
);
|
||||
});
|
||||
|
||||
it("shows disabled status without configured account detail lines", async () => {
|
||||
vi.mocked(listChannelPlugins).mockReturnValue([
|
||||
makeTelegramSummaryPlugin({ enabled: false, configured: false }),
|
||||
]);
|
||||
|
||||
const lines = await buildChannelSummary({ channels: {} } as never, {
|
||||
colorize: false,
|
||||
includeAllowFrom: true,
|
||||
});
|
||||
|
||||
expect(lines).toEqual(["Telegram: disabled +15551234567"]);
|
||||
});
|
||||
|
||||
it("includes linked summary metadata and truncates allow-from details", async () => {
|
||||
vi.mocked(listChannelPlugins).mockReturnValue([
|
||||
makeTelegramSummaryPlugin({
|
||||
enabled: true,
|
||||
configured: true,
|
||||
linked: true,
|
||||
authAgeMs: 300_000,
|
||||
allowFrom: ["alice", "bob", "carol"],
|
||||
}),
|
||||
]);
|
||||
|
||||
const lines = await buildChannelSummary({ channels: {} } as never, {
|
||||
colorize: false,
|
||||
includeAllowFrom: true,
|
||||
});
|
||||
|
||||
expect(lines).toContain("Telegram: linked +15551234567 auth 5m ago");
|
||||
expect(lines).toContain(" - primary (Main Bot) (dm:mutuals, token:env, allow:alice,bob)");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user