@@ -8,6 +8,13 @@ import { setZalouserRuntime } from "./runtime.js";
88import { createZalouserRuntimeEnv } from "./test-helpers.js" ;
99import type { ResolvedZalouserAccount , ZaloInboundMessage } from "./types.js" ;
1010
11+ 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" , ( ) => {
1219 it ( "scopes DM pairing-store reads and pairing requests to accountId" , async ( ) => {
1320 const readAllowFromStore = vi . fn (
@@ -28,7 +35,12 @@ describe("zalouser monitor pairing account scoping", () => {
2835 return 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+ ) ;
3244
3345 setZalouserRuntime ( {
3446 logging : {
@@ -89,19 +101,22 @@ describe("zalouser monitor pairing account scoping", () => {
89101 runtime : createZalouserRuntimeEnv ( ) ,
90102 } ) ;
91103
92- 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" ) ;
105120 expect ( sendMessageZalouserMock ) . toHaveBeenCalled ( ) ;
106121 } ) ;
107122} ) ;
0 commit comments