test: cover whoami command

This commit is contained in:
Peter Steinberger
2026-01-11 04:20:34 +01:00
parent f74ead8d43
commit 76c5bff7d6
2 changed files with 29 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ describe("commands registry", () => {
const specs = listNativeCommandSpecs();
expect(specs.find((spec) => spec.name === "help")).toBeTruthy();
expect(specs.find((spec) => spec.name === "stop")).toBeTruthy();
expect(specs.find((spec) => spec.name === "whoami")).toBeTruthy();
expect(specs.find((spec) => spec.name === "compact")).toBeFalsy();
});
@@ -47,6 +48,8 @@ describe("commands registry", () => {
const detection = getCommandDetection();
expect(detection.exact.has("/commands")).toBe(true);
expect(detection.exact.has("/compact")).toBe(true);
expect(detection.exact.has("/whoami")).toBe(true);
expect(detection.exact.has("/id")).toBe(true);
for (const command of listChatCommands()) {
for (const alias of command.textAliases) {
expect(detection.exact.has(alias.toLowerCase())).toBe(true);

View File

@@ -5,7 +5,11 @@ import type { MsgContext } from "../templating.js";
import { buildCommandContext, handleCommands } from "./commands.js";
import { parseInlineDirectives } from "./directive-handling.js";
function buildParams(commandBody: string, cfg: ClawdbotConfig) {
function buildParams(
commandBody: string,
cfg: ClawdbotConfig,
ctxOverrides?: Partial<MsgContext>,
) {
const ctx = {
Body: commandBody,
CommandBody: commandBody,
@@ -13,6 +17,7 @@ function buildParams(commandBody: string, cfg: ClawdbotConfig) {
CommandAuthorized: true,
Provider: "whatsapp",
Surface: "whatsapp",
...ctxOverrides,
} as MsgContext;
const command = buildCommandContext({
@@ -64,3 +69,23 @@ describe("handleCommands gating", () => {
expect(result.reply?.text).toContain("/debug is disabled");
});
});
describe("handleCommands identity", () => {
it("returns sender details for /whoami", async () => {
const cfg = {
commands: { text: true },
whatsapp: { allowFrom: ["*"] },
} as ClawdbotConfig;
const params = buildParams("/whoami", cfg, {
SenderId: "12345",
SenderUsername: "TestUser",
ChatType: "direct",
});
const result = await handleCommands(params);
expect(result.shouldContinue).toBe(false);
expect(result.reply?.text).toContain("Provider: whatsapp");
expect(result.reply?.text).toContain("User id: 12345");
expect(result.reply?.text).toContain("Username: @TestUser");
expect(result.reply?.text).toContain("AllowFrom: 12345");
});
});