test: cover whoami command
This commit is contained in:
@@ -20,6 +20,7 @@ describe("commands registry", () => {
|
|||||||
const specs = listNativeCommandSpecs();
|
const specs = listNativeCommandSpecs();
|
||||||
expect(specs.find((spec) => spec.name === "help")).toBeTruthy();
|
expect(specs.find((spec) => spec.name === "help")).toBeTruthy();
|
||||||
expect(specs.find((spec) => spec.name === "stop")).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();
|
expect(specs.find((spec) => spec.name === "compact")).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ describe("commands registry", () => {
|
|||||||
const detection = getCommandDetection();
|
const detection = getCommandDetection();
|
||||||
expect(detection.exact.has("/commands")).toBe(true);
|
expect(detection.exact.has("/commands")).toBe(true);
|
||||||
expect(detection.exact.has("/compact")).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 command of listChatCommands()) {
|
||||||
for (const alias of command.textAliases) {
|
for (const alias of command.textAliases) {
|
||||||
expect(detection.exact.has(alias.toLowerCase())).toBe(true);
|
expect(detection.exact.has(alias.toLowerCase())).toBe(true);
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import type { MsgContext } from "../templating.js";
|
|||||||
import { buildCommandContext, handleCommands } from "./commands.js";
|
import { buildCommandContext, handleCommands } from "./commands.js";
|
||||||
import { parseInlineDirectives } from "./directive-handling.js";
|
import { parseInlineDirectives } from "./directive-handling.js";
|
||||||
|
|
||||||
function buildParams(commandBody: string, cfg: ClawdbotConfig) {
|
function buildParams(
|
||||||
|
commandBody: string,
|
||||||
|
cfg: ClawdbotConfig,
|
||||||
|
ctxOverrides?: Partial<MsgContext>,
|
||||||
|
) {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
Body: commandBody,
|
Body: commandBody,
|
||||||
CommandBody: commandBody,
|
CommandBody: commandBody,
|
||||||
@@ -13,6 +17,7 @@ function buildParams(commandBody: string, cfg: ClawdbotConfig) {
|
|||||||
CommandAuthorized: true,
|
CommandAuthorized: true,
|
||||||
Provider: "whatsapp",
|
Provider: "whatsapp",
|
||||||
Surface: "whatsapp",
|
Surface: "whatsapp",
|
||||||
|
...ctxOverrides,
|
||||||
} as MsgContext;
|
} as MsgContext;
|
||||||
|
|
||||||
const command = buildCommandContext({
|
const command = buildCommandContext({
|
||||||
@@ -64,3 +69,23 @@ describe("handleCommands gating", () => {
|
|||||||
expect(result.reply?.text).toContain("/debug is disabled");
|
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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user