mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
test: guard discord channel mock calls
This commit is contained in:
@@ -110,7 +110,11 @@ function objectArgAt(
|
||||
}
|
||||
|
||||
function argAt(mock: MockWithCalls, callIndex: number, argIndex: number): unknown {
|
||||
return mock.mock.calls[callIndex]?.[argIndex];
|
||||
const call = mock.mock.calls[callIndex];
|
||||
if (!call || !(argIndex in call)) {
|
||||
throw new Error(`expected call ${callIndex} argument ${argIndex}`);
|
||||
}
|
||||
return call[argIndex];
|
||||
}
|
||||
|
||||
function recordField(value: unknown, field: string): Record<string, unknown> {
|
||||
@@ -444,7 +448,7 @@ describe("discordPlugin outbound", () => {
|
||||
target: "channel:222",
|
||||
});
|
||||
|
||||
expect(fetchPermissionsSpy.mock.calls[0]?.[0]).toBe("222");
|
||||
expect(argAt(fetchPermissionsSpy, 0, 0)).toBe("222");
|
||||
expect(objectArgAt(fetchPermissionsSpy, 0, 1).token).toBe("discord-token");
|
||||
const permissions = recordField(diagnostics?.details?.permissions, "permissions");
|
||||
expect(permissions.channelId).toBe("222");
|
||||
|
||||
@@ -63,7 +63,11 @@ describe("ensureOggOpus", () => {
|
||||
}
|
||||
|
||||
function readSingleCommandArgs(mock: typeof runFfprobeMock | typeof runFfmpegMock): string[] {
|
||||
const args = mock.mock.calls[0]?.[0];
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("missing command call");
|
||||
}
|
||||
const [args] = call;
|
||||
if (!Array.isArray(args) || !args.every((arg): arg is string => typeof arg === "string")) {
|
||||
throw new Error("missing command args");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user