@@ -308,3 +308,74 @@ describe('redactLog', () => {
308308 ] ) ;
309309 } ) ;
310310} ) ;
311+
312+ test ( 'make move args to be secret depends on G via conditional redact' , async ( ) => {
313+ const game = {
314+ setup : ( ) => ( {
315+ isASecret : false ,
316+ } ) ,
317+ moves : {
318+ A : {
319+ move : ( G ) => G ,
320+ redact : ( G ) => G . isASecret ,
321+ } ,
322+ B : ( G ) => {
323+ return { ...G , isASecret : true } ;
324+ } ,
325+ } ,
326+ } ;
327+
328+ const send = jest . fn ( ) ;
329+ const master = new Master ( game , new InMemory ( ) , TransportAPI ( send ) ) ;
330+ const filterPlayerView = getFilterPlayerView ( game ) ;
331+
332+ const actionA0 = ActionCreators . makeMove ( 'A' , [ 'not redacted' ] , '0' ) ;
333+ const actionB = ActionCreators . makeMove ( 'B' , [ 'not redacted' ] , '0' ) ;
334+ const actionA1 = ActionCreators . makeMove ( 'A' , [ 'redacted' ] , '0' ) ;
335+
336+ // test: ping-pong two moves, then sync and check the log
337+ await master . onSync ( 'matchID' , '0' , undefined , 2 ) ;
338+ await master . onUpdate ( actionA0 , 0 , 'matchID' , '0' ) ;
339+ await master . onUpdate ( actionB , 1 , 'matchID' , '0' ) ;
340+ await master . onUpdate ( actionA1 , 2 , 'matchID' , '0' ) ;
341+ await master . onSync ( 'matchID' , '1' , undefined , 2 ) ;
342+
343+ const payload = send . mock . calls [ send . mock . calls . length - 1 ] [ 0 ] ;
344+ expect (
345+ ( filterPlayerView ( '1' , payload ) . args [ 1 ] as SyncInfo ) . log
346+ ) . toMatchObject ( [
347+ {
348+ action : {
349+ type : 'MAKE_MOVE' ,
350+ payload : {
351+ type : 'A' ,
352+ args : [ 'not redacted' ] ,
353+ playerID : '0' ,
354+ } ,
355+ } ,
356+ _stateID : 0 ,
357+ } ,
358+ {
359+ action : {
360+ type : 'MAKE_MOVE' ,
361+ payload : {
362+ type : 'B' ,
363+ args : [ 'not redacted' ] ,
364+ playerID : '0' ,
365+ } ,
366+ } ,
367+ _stateID : 1 ,
368+ } ,
369+ {
370+ action : {
371+ type : 'MAKE_MOVE' ,
372+ payload : {
373+ type : 'A' ,
374+ args : null ,
375+ playerID : '0' ,
376+ } ,
377+ } ,
378+ _stateID : 2 ,
379+ } ,
380+ ] ) ;
381+ } ) ;
0 commit comments