From a2aab81e059cd5660cd6540c0514b32ab2ba54d6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 20:26:51 +0100 Subject: [PATCH] test: tighten zalouser account scope assertions --- .../src/monitor.account-scope.test.ts | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/extensions/zalouser/src/monitor.account-scope.test.ts b/extensions/zalouser/src/monitor.account-scope.test.ts index d91602398c4..8914253af60 100644 --- a/extensions/zalouser/src/monitor.account-scope.test.ts +++ b/extensions/zalouser/src/monitor.account-scope.test.ts @@ -8,6 +8,13 @@ import { setZalouserRuntime } from "./runtime.js"; import { createZalouserRuntimeEnv } from "./test-helpers.js"; import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js"; +function requireRecord(value: unknown, label: string): Record { + if (value === null || typeof value !== "object" || Array.isArray(value)) { + throw new Error(`expected ${label} to be a record`); + } + return value as Record; +} + describe("zalouser monitor pairing account scoping", () => { it("scopes DM pairing-store reads and pairing requests to accountId", async () => { const readAllowFromStore = vi.fn( @@ -28,7 +35,12 @@ describe("zalouser monitor pairing account scoping", () => { return scopedAccountId === "beta" ? [] : ["attacker"]; }, ); - const upsertPairingRequest = vi.fn(async () => ({ code: "PAIRME88", created: true })); + const upsertPairingRequest = vi.fn( + async (_params: { channel: string; id: string; accountId?: string }) => ({ + code: "PAIRME88", + created: true, + }), + ); setZalouserRuntime({ logging: { @@ -89,19 +101,22 @@ describe("zalouser monitor pairing account scoping", () => { runtime: createZalouserRuntimeEnv(), }); - expect(readAllowFromStore).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "zalouser", - accountId: "beta", - }), + expect(readAllowFromStore).toHaveBeenCalledOnce(); + const allowStoreParams = requireRecord( + readAllowFromStore.mock.calls[0]?.[0], + "allow store params", ); - expect(upsertPairingRequest).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "zalouser", - id: "attacker", - accountId: "beta", - }), + expect(allowStoreParams.channel).toBe("zalouser"); + expect(allowStoreParams.accountId).toBe("beta"); + + expect(upsertPairingRequest).toHaveBeenCalledOnce(); + const pairingRequest = requireRecord( + upsertPairingRequest.mock.calls[0]?.[0], + "pairing request params", ); + expect(pairingRequest.channel).toBe("zalouser"); + expect(pairingRequest.id).toBe("attacker"); + expect(pairingRequest.accountId).toBe("beta"); expect(sendMessageZalouserMock).toHaveBeenCalled(); }); });