test: guard discord provider mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 02:28:37 +01:00
parent e994c996c2
commit a0fb3c1dfd

View File

@@ -104,6 +104,14 @@ function createConfigWithDiscordAccount(overrides: Record<string, unknown> = {})
type MockCallReader = { mock: { calls: unknown[][] } };
function firstMockArg(mock: MockCallReader, label: string) {
const firstCall = mock.mock.calls.at(0);
if (!firstCall) {
throw new Error(`expected ${label} mock call`);
}
return firstCall[0];
}
function mockMessages(mock: unknown): string[] {
return (mock as MockCallReader).mock.calls.map((call) => {
const message = call[0];
@@ -154,7 +162,7 @@ describe("monitorDiscordProvider", () => {
| { listenerTimeout?: number; slowListenerThreshold?: number }
| undefined => {
expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1);
const opts = clientConstructorOptionsMock.mock.calls[0]?.[0] as {
const opts = firstMockArg(clientConstructorOptionsMock, "Discord client constructor") as {
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
};
return opts.eventQueue;
@@ -166,13 +174,11 @@ describe("monitorDiscordProvider", () => {
requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number };
} => {
expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1);
return (
(clientConstructorOptionsMock.mock.calls[0]?.[0] as {
clientId?: string;
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number };
}) ?? {}
);
return firstMockArg(clientConstructorOptionsMock, "Discord client constructor") as {
clientId?: string;
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number };
};
};
const getHealthProbe = () => {
@@ -693,7 +699,7 @@ describe("monitorDiscordProvider", () => {
reason: "status-timeout",
});
const firstCall = getAcpSessionStatusMock.mock.calls[0]?.[0] as
const firstCall = firstMockArg(getAcpSessionStatusMock, "ACP session status") as
| { signal?: AbortSignal }
| undefined;
if (!firstCall?.signal) {