@@ -14,10 +14,17 @@ import { ProcessGameConfig } from '../core/game';
1414import type { Transport } from './transport/transport' ;
1515import { LocalTransport , Local } from './transport/local' ;
1616import { SocketIOTransport , SocketIO } from './transport/socketio' ;
17- import { update , sync , makeMove , gameEvent } from '../core/action-creators' ;
17+ import {
18+ update ,
19+ sync ,
20+ makeMove ,
21+ gameEvent ,
22+ patch ,
23+ } from '../core/action-creators' ;
1824import Debug from './debug/Debug.svelte' ;
1925import { error } from '../core/logger' ;
2026import type { LogEntry , State , SyncInfo } from '../types' ;
27+ import type { Operation } from 'rfc6902' ;
2128
2229jest . mock ( '../core/logger' , ( ) => ( {
2330 info : jest . fn ( ) ,
@@ -370,19 +377,20 @@ test('accepts enhancer for store', () => {
370377} ) ;
371378
372379describe ( 'event dispatchers' , ( ) => {
380+ const clientEvents = [
381+ 'endTurn' ,
382+ 'pass' ,
383+ 'endPhase' ,
384+ 'setPhase' ,
385+ 'endGame' ,
386+ 'setActivePlayers' ,
387+ 'endStage' ,
388+ 'setStage' ,
389+ ] ;
373390 test ( 'default' , ( ) => {
374391 const game = { } ;
375392 const client = Client ( { game } ) ;
376- expect ( Object . keys ( client . events ) ) . toEqual ( [
377- 'endTurn' ,
378- 'pass' ,
379- 'endPhase' ,
380- 'setPhase' ,
381- 'endGame' ,
382- 'setActivePlayers' ,
383- 'endStage' ,
384- 'setStage' ,
385- ] ) ;
393+ expect ( Object . keys ( client . events ) ) . toEqual ( clientEvents ) ;
386394 expect ( client . getState ( ) . ctx . turn ) . toBe ( 1 ) ;
387395 client . events . endTurn ( ) ;
388396 expect ( client . getState ( ) . ctx . turn ) . toBe ( 2 ) ;
@@ -396,16 +404,7 @@ describe('event dispatchers', () => {
396404 } ,
397405 } ;
398406 const client = Client ( { game } ) ;
399- expect ( Object . keys ( client . events ) ) . toEqual ( [
400- 'endTurn' ,
401- 'pass' ,
402- 'endPhase' ,
403- 'setPhase' ,
404- 'endGame' ,
405- 'setActivePlayers' ,
406- 'endStage' ,
407- 'setStage' ,
408- ] ) ;
407+ expect ( Object . keys ( client . events ) ) . toEqual ( clientEvents ) ;
409408 expect ( client . getState ( ) . ctx . turn ) . toBe ( 1 ) ;
410409 client . events . endTurn ( ) ;
411410 expect ( client . getState ( ) . ctx . turn ) . toBe ( 2 ) ;
@@ -464,7 +463,7 @@ describe('move dispatchers', () => {
464463 expect ( store . getState ( ) . G ) . toMatchObject ( { victory : true } ) ;
465464 } ) ;
466465
467- test ( 'with undefined playerID - singleplayer mode' , ( ) => {
466+ test ( 'with undefined playerID - single player mode' , ( ) => {
468467 const store = createStore ( reducer , initialState ) ;
469468 const api = createMoveDispatchers ( game . moveNames , store ) ;
470469 api . B ( ) ;
@@ -484,7 +483,7 @@ describe('move dispatchers', () => {
484483 expect ( store . getState ( ) . G ) . toMatchObject ( { moved : undefined } ) ;
485484 } ) ;
486485
487- test ( 'with null playerID - singleplayer mode' , ( ) => {
486+ test ( 'with null playerID - single player mode' , ( ) => {
488487 const store = createStore ( reducer , initialState ) ;
489488 const api = createMoveDispatchers ( game . moveNames , store , null ) ;
490489 api . B ( ) ;
@@ -552,6 +551,26 @@ describe('log handling', () => {
552551 expect ( client . log ) . toEqual ( deltalog ) ;
553552 } ) ;
554553
554+ test ( 'patch' , ( ) => {
555+ const patches = [
556+ { op : 'replace' , path : '/_stateID' , value : 1 } ,
557+ ] as Operation [ ] ;
558+ const deltalog = [
559+ {
560+ action : { } ,
561+ _stateID : 0 ,
562+ } ,
563+ {
564+ action : { } ,
565+ _stateID : 1 ,
566+ } ,
567+ ] as LogEntry [ ] ;
568+ const action = patch ( 0 , 1 , patches , deltalog ) ;
569+ client . store . dispatch ( action ) ;
570+
571+ expect ( client . log ) . toEqual ( deltalog ) ;
572+ } ) ;
573+
555574 test ( 'sync' , ( ) => {
556575 const state = { restore : true } ;
557576 const log = [ '0' , '1' ] ;
@@ -756,6 +775,10 @@ describe('start / stop', () => {
756775 const client = Client ( { game : { } , debug : { target : el } } ) ;
757776 client . start ( ) ;
758777 client . stop ( ) ;
778+ expect ( error ) . toHaveBeenCalledTimes ( 3 ) ;
779+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: B' ) ;
780+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: C' ) ;
781+ expect ( error ) . toHaveBeenLastCalledWith ( 'disallowed move: A' ) ;
759782 } ) ;
760783
761784 test ( 'no error when mounting on null element' , ( ) => {
@@ -769,17 +792,29 @@ describe('start / stop', () => {
769792 const client = Client ( { game : { } , debug : { impl : Debug } } ) ;
770793 client . start ( ) ;
771794 client . stop ( ) ;
795+ expect ( error ) . toHaveBeenCalledTimes ( 3 ) ;
796+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: B' ) ;
797+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: C' ) ;
798+ expect ( error ) . toHaveBeenLastCalledWith ( 'disallowed move: A' ) ;
772799 } ) ;
773800
774801 test ( 'production mode' , ( ) => {
775802 process . env . NODE_ENV = 'production' ;
776803 const client = Client ( { game : { } } ) ;
777804 client . start ( ) ;
778805 client . stop ( ) ;
806+ expect ( error ) . toHaveBeenCalledTimes ( 3 ) ;
807+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: B' ) ;
808+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: C' ) ;
809+ expect ( error ) . toHaveBeenLastCalledWith ( 'disallowed move: A' ) ;
779810 } ) ;
780811
781812 test ( 'try to stop without starting' , ( ) => {
782813 const client = Client ( { game : { } } ) ;
783814 client . stop ( ) ;
815+ expect ( error ) . toHaveBeenCalledTimes ( 3 ) ;
816+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: B' ) ;
817+ expect ( error ) . toHaveBeenCalledWith ( 'disallowed move: C' ) ;
818+ expect ( error ) . toHaveBeenLastCalledWith ( 'disallowed move: A' ) ;
784819 } ) ;
785820} ) ;
0 commit comments