mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 19:04:45 +00:00
test: guard gateway mock calls
This commit is contained in:
@@ -31,7 +31,7 @@ describe("warnLegacyOpenClawEnvVars", () => {
|
||||
});
|
||||
|
||||
expect(emitWarning).toHaveBeenCalledOnce();
|
||||
const [message, options] = emitWarning.mock.calls[0] as [
|
||||
const [message, options] = emitWarning.mock.calls.at(0) as [
|
||||
string,
|
||||
{ code: string; type: string },
|
||||
];
|
||||
|
||||
@@ -157,7 +157,7 @@ describe("handleGatewayPostJsonEndpoint", () => {
|
||||
},
|
||||
);
|
||||
|
||||
const [, requestAuth] = (resolveOperatorScopes.mock.calls[0] as unknown as
|
||||
const [, requestAuth] = (resolveOperatorScopes.mock.calls.at(0) as unknown as
|
||||
| [IncomingMessage, { authMethod?: string; trustDeclaredOperatorScopes: boolean }]
|
||||
| undefined) ?? [undefined, undefined];
|
||||
expect(requestAuth?.authMethod).toBe("token");
|
||||
|
||||
@@ -519,7 +519,7 @@ describe("mcp loopback server", () => {
|
||||
expect(response.status).toBe(200);
|
||||
expect(payload.result?.isError).toBe(false);
|
||||
expect(execute).toHaveBeenCalledTimes(1);
|
||||
const [callId, params, signal] = execute.mock.calls[0] ?? [];
|
||||
const [callId, params, signal] = execute.mock.calls.at(0) ?? [];
|
||||
expect(callId).toMatch(/^mcp-/);
|
||||
expect(params).toEqual({ body: "hello" });
|
||||
expect(signal).toBeInstanceOf(AbortSignal);
|
||||
|
||||
@@ -183,7 +183,7 @@ function expectResponseError(
|
||||
respond: ReturnType<typeof vi.fn>,
|
||||
expected: { code?: string; messageIncludes?: string },
|
||||
) {
|
||||
const call = respond.mock.calls[0];
|
||||
const call = respond.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error("expected response call");
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ function mockRotateOperatorTokenSuccess(): void {
|
||||
function expectRespondedErrorMessage(opts: GatewayRequestHandlerOptions, message: string): void {
|
||||
const respond = opts.respond as ReturnType<typeof vi.fn>;
|
||||
expect(respond).toHaveBeenCalledTimes(1);
|
||||
const call = respond.mock.calls[0] as unknown as [boolean, unknown, { message?: string }];
|
||||
const call = respond.mock.calls.at(0) as unknown as [boolean, unknown, { message?: string }];
|
||||
expect(call[0]).toBe(false);
|
||||
expect(call[1]).toBeUndefined();
|
||||
expect(call[2]?.message).toBe(message);
|
||||
|
||||
@@ -40,7 +40,11 @@ async function callEnvironmentMethod(
|
||||
respond,
|
||||
context: mockContext(),
|
||||
} as never);
|
||||
return respond.mock.calls[0];
|
||||
const call = respond.mock.calls.at(0);
|
||||
if (call === undefined) {
|
||||
throw new Error("expected environments handler to respond");
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -236,7 +236,7 @@ describe("models.list", () => {
|
||||
} as never,
|
||||
});
|
||||
|
||||
const call = respond.mock.calls[0] as
|
||||
const call = respond.mock.calls.at(0) as
|
||||
| [boolean, unknown, { code?: number; message?: string }]
|
||||
| undefined;
|
||||
expect(call?.[0]).toBe(false);
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("native hook relay gateway method", () => {
|
||||
context: {} as never,
|
||||
});
|
||||
|
||||
const call = respond.mock.calls[0] as
|
||||
const call = respond.mock.calls.at(0) as
|
||||
| [boolean, unknown, { code?: string; message?: string }]
|
||||
| undefined;
|
||||
expect(call?.[0]).toBe(false);
|
||||
|
||||
@@ -53,7 +53,7 @@ function expectRespondError(
|
||||
respond: ReturnType<typeof vi.fn>,
|
||||
expected: { code: string; message?: string },
|
||||
): void {
|
||||
const call = respond.mock.calls[0];
|
||||
const call = respond.mock.calls.at(0);
|
||||
expect(call?.[0]).toBe(false);
|
||||
expect(call?.[1]).toBeUndefined();
|
||||
const error = requireRecord(call?.[2]);
|
||||
|
||||
@@ -1014,7 +1014,7 @@ describe("gateway send mirroring", () => {
|
||||
idempotencyKey: "idem-send-options",
|
||||
});
|
||||
|
||||
const options = mocks.deliverOutboundPayloads.mock.calls[0]?.[0];
|
||||
const options = mocks.deliverOutboundPayloads.mock.calls.at(0)?.[0];
|
||||
expect(options?.forceDocument).toBe(true);
|
||||
expect(options?.silent).toBe(true);
|
||||
expect(options?.formatting).toEqual({ parseMode: "HTML" });
|
||||
|
||||
@@ -110,7 +110,7 @@ describe("sessions.send completed subagent follow-up status", () => {
|
||||
isWebchatConnect: () => false,
|
||||
});
|
||||
|
||||
const call = respondMock.mock.calls[0] as
|
||||
const call = respondMock.mock.calls.at(0) as
|
||||
| [boolean, { runId?: string; status?: string; messageSeq?: number }, unknown?, unknown?]
|
||||
| undefined;
|
||||
expect(call?.[0]).toBe(true);
|
||||
|
||||
@@ -141,7 +141,7 @@ function expectError(result: CallResult, code: string, message: string): void {
|
||||
}
|
||||
|
||||
function firstCallArg<T>(mock: { mock: { calls: unknown[][] } }, _type?: (value: T) => T): T {
|
||||
const call = mock.mock.calls[0];
|
||||
const call = mock.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error("Expected first mock call");
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ describe("ttsHandlers", () => {
|
||||
context: { getRuntimeConfig: mocks.getRuntimeConfig },
|
||||
} as never);
|
||||
|
||||
const call = respond.mock.calls[0] as
|
||||
const call = respond.mock.calls.at(0) as
|
||||
| [boolean, unknown, { code?: number; message?: string }]
|
||||
| undefined;
|
||||
expect(call?.[0]).toBe(false);
|
||||
|
||||
@@ -157,7 +157,7 @@ describe("gateway usage helpers", () => {
|
||||
expect(a.totals.totalTokens).toBe(1);
|
||||
expect(b.totals.totalTokens).toBe(1);
|
||||
expect(vi.mocked(loadCostUsageSummaryFromCache)).toHaveBeenCalledTimes(1);
|
||||
expect(vi.mocked(loadCostUsageSummaryFromCache).mock.calls[0]?.[0]?.refreshMode).toBe(
|
||||
expect(vi.mocked(loadCostUsageSummaryFromCache).mock.calls.at(0)?.[0]?.refreshMode).toBe(
|
||||
"sync-when-empty",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user