test: guard channel auth mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 07:15:51 +01:00
parent 7411396dbc
commit acd8236ef2

View File

@@ -89,7 +89,7 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
}
function readFirstCallArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> {
const [arg] = mock.mock.calls[0] ?? [];
const [arg] = mock.mock.calls.at(0) ?? [];
if (!arg || typeof arg !== "object") {
throw new Error("expected first call argument object");
}
@@ -223,7 +223,7 @@ describe("channel-auth", () => {
await runChannelLogin({ channel: "whatsapp", account: "acct-1" }, runtime);
expect(mocks.callGateway).not.toHaveBeenCalled();
expect(String(runtime.log.mock.calls[0]?.[0])).toContain("Gateway is in remote mode");
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain("Gateway is in remote mode");
});
it("keeps login successful when local gateway runtime reconcile fails", async () => {
@@ -233,7 +233,7 @@ describe("channel-auth", () => {
runChannelLogin({ channel: "whatsapp", account: "acct-1" }, runtime),
).resolves.toBeUndefined();
expect(String(runtime.log.mock.calls[0]?.[0])).toContain(
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
"running gateway did not restart it: gateway unreachable",
);
});
@@ -565,7 +565,7 @@ describe("channel-auth", () => {
account: { id: "resolved-account" },
runtime,
});
expect(String(runtime.log.mock.calls[0]?.[0])).toContain(
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
"running gateway did not stop it: gateway unreachable",
);
expect(mocks.setVerbose).not.toHaveBeenCalled();