@@ -255,52 +255,62 @@ test('action', async () => {
255255 // ... and not if player != currentPlayer
256256 await io . socket . receive ( 'action' , action , 1 , 'gameID' , '100' ) ;
257257 expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 0 ) ;
258+ await io . socket . receive (
259+ 'action' ,
260+ ActionCreators . makeMove ( ) ,
261+ 1 ,
262+ 'gameID' ,
263+ '100'
264+ ) ;
265+ expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 0 ) ;
258266
259267 // Another broadcasted action.
260268 await io . socket . receive ( 'action' , action , 1 , 'gameID' , '1' ) ;
261269 expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 2 ) ;
262270} ) ;
263271
264- test ( 'playerView (sync)' , async ( ) => {
265- // Write the player into G.
266- const game = Game ( {
267- playerView : ( G , ctx , player ) => {
268- return Object . assign ( { } , G , { player } ) ;
269- } ,
270- } ) ;
271-
272- const server = Server ( { games : [ game ] } ) ;
273- const io = server . app . context . io ;
272+ describe ( 'playerView' , ( ) => {
273+ test ( 'sync' , async ( ) => {
274+ // Write the player into G.
275+ const game = Game ( {
276+ playerView : ( G , ctx , player ) => {
277+ return Object . assign ( { } , G , { player } ) ;
278+ } ,
279+ } ) ;
274280
275- await io . socket . receive ( 'sync' , 'gameID' , 0 ) ;
276- expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 1 ) ;
277- expect ( io . socket . emit . mock . calls [ 0 ] [ 2 ] . G ) . toEqual ( { player : 0 } ) ;
278- } ) ;
281+ const server = Server ( { games : [ game ] } ) ;
282+ const io = server . app . context . io ;
279283
280- test ( 'playerView (action)' , async ( ) => {
281- const game = Game ( {
282- playerView : ( G , ctx , player ) => {
283- return Object . assign ( { } , G , { player } ) ;
284- } ,
284+ await io . socket . receive ( 'sync' , 'gameID' , 0 ) ;
285+ expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 1 ) ;
286+ expect ( io . socket . emit . mock . calls [ 0 ] [ 2 ] . G ) . toEqual ( { player : 0 } ) ;
285287 } ) ;
286- const server = Server ( { games : [ game ] } ) ;
287- const io = server . app . context . io ;
288- const action = ActionCreators . gameEvent ( 'endTurn' ) ;
289288
290- io . socket . id = 'first' ;
291- await io . socket . receive ( 'sync' , 'gameID' , '0' , 2 ) ;
292- io . socket . id = 'second' ;
293- await io . socket . receive ( 'sync' , 'gameID' , '1' , 2 ) ;
294- io . socket . emit . mockReset ( ) ;
289+ test ( 'action' , async ( ) => {
290+ const game = Game ( {
291+ playerView : ( G , ctx , player ) => {
292+ return Object . assign ( { } , G , { player } ) ;
293+ } ,
294+ } ) ;
295+ const server = Server ( { games : [ game ] } ) ;
296+ const io = server . app . context . io ;
297+ const action = ActionCreators . gameEvent ( 'endTurn' ) ;
295298
296- await io . socket . receive ( 'action' , action , 0 , 'gameID' , '0' ) ;
297- expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 2 ) ;
299+ io . socket . id = 'first' ;
300+ await io . socket . receive ( 'sync' , 'gameID' , '0' , 2 ) ;
301+ io . socket . id = 'second' ;
302+ await io . socket . receive ( 'sync' , 'gameID' , '1' , 2 ) ;
303+ io . socket . emit . mockReset ( ) ;
304+
305+ await io . socket . receive ( 'action' , action , 0 , 'gameID' , '0' ) ;
306+ expect ( io . socket . emit ) . toHaveBeenCalledTimes ( 2 ) ;
298307
299- const G_player0 = io . socket . emit . mock . calls [ 0 ] [ 2 ] . G ;
300- const G_player1 = io . socket . emit . mock . calls [ 1 ] [ 2 ] . G ;
308+ const G_player0 = io . socket . emit . mock . calls [ 0 ] [ 2 ] . G ;
309+ const G_player1 = io . socket . emit . mock . calls [ 1 ] [ 2 ] . G ;
301310
302- expect ( G_player0 . player ) . toBe ( '0' ) ;
303- expect ( G_player1 . player ) . toBe ( '1' ) ;
311+ expect ( G_player0 . player ) . toBe ( '0' ) ;
312+ expect ( G_player1 . player ) . toBe ( '1' ) ;
313+ } ) ;
304314} ) ;
305315
306316test ( 'custom db implementation' , async ( ) => {
0 commit comments