test: guard discord channel mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 01:40:43 +01:00
parent 9dbae5ca95
commit a0288dc4aa
2 changed files with 11 additions and 3 deletions
+6 -2
View File
@@ -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");
+5 -1
View File
@@ -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");
}