

























@@ -8,6 +8,13 @@ import { setZalouserRuntime } from "./runtime.js";
88import { createZalouserRuntimeEnv } from "./test-helpers.js";
99import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
101011+function requireRecord(value: unknown, label: string): Record<string, unknown> {
12+if (value === null || typeof value !== "object" || Array.isArray(value)) {
13+throw new Error(`expected ${label} to be a record`);
14+}
15+return value as Record<string, unknown>;
16+}
17+1118describe("zalouser monitor pairing account scoping", () => {
1219it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
1320const readAllowFromStore = vi.fn(
@@ -28,7 +35,12 @@ describe("zalouser monitor pairing account scoping", () => {
2835return scopedAccountId === "beta" ? [] : ["attacker"];
2936},
3037);
31-const upsertPairingRequest = vi.fn(async () => ({ code: "PAIRME88", created: true }));
38+const upsertPairingRequest = vi.fn(
39+async (_params: { channel: string; id: string; accountId?: string }) => ({
40+code: "PAIRME88",
41+created: true,
42+}),
43+);
32443345setZalouserRuntime({
3446logging: {
@@ -89,19 +101,22 @@ describe("zalouser monitor pairing account scoping", () => {
89101runtime: createZalouserRuntimeEnv(),
90102});
9110392-expect(readAllowFromStore).toHaveBeenCalledWith(
93-expect.objectContaining({
94-channel: "zalouser",
95-accountId: "beta",
96-}),
104+expect(readAllowFromStore).toHaveBeenCalledOnce();
105+const allowStoreParams = requireRecord(
106+readAllowFromStore.mock.calls[0]?.[0],
107+"allow store params",
97108);
98-expect(upsertPairingRequest).toHaveBeenCalledWith(
99-expect.objectContaining({
100-channel: "zalouser",
101-id: "attacker",
102-accountId: "beta",
103-}),
109+expect(allowStoreParams.channel).toBe("zalouser");
110+expect(allowStoreParams.accountId).toBe("beta");
111+112+expect(upsertPairingRequest).toHaveBeenCalledOnce();
113+const pairingRequest = requireRecord(
114+upsertPairingRequest.mock.calls[0]?.[0],
115+"pairing request params",
104116);
117+expect(pairingRequest.channel).toBe("zalouser");
118+expect(pairingRequest.id).toBe("attacker");
119+expect(pairingRequest.accountId).toBe("beta");
105120expect(sendMessageZalouserMock).toHaveBeenCalled();
106121});
107122});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。