@@ -4,22 +4,20 @@ import { BoardMove, Game, GameState, INIT_MOVE, PlayerMove } from ".";
44import { MatchTester } from "./testing" ;
55
66const gameBase = {
7- version : "2.3.0" ,
87 minPlayers : 1 ,
98 maxPlayers : 10 ,
109} ;
1110
1211describe ( "turns" , ( ) => {
13- type B = { me : number ; bot : number ; numZeroDelay : number } ;
12+ type B = {
13+ me : number ;
14+ bot : number ;
15+ numZeroDelay : number ;
16+ expiresAt : number | undefined ;
17+ } ;
1418 type GS = GameState < B > ;
1519 type P = { itWasMe ?: boolean } ;
16- type PMT = Record < string , unknown > ;
17- // type PMT = {
18- // go: { itWasMe?: boolean };
19- // endTurn: never;
20- // beginZeroDelay: never;
21- // };
22- type PM < P = null > = PlayerMove < GS , P , PMT > ;
20+ type PM < P = null > = PlayerMove < GS , P > ;
2321
2422 const game = {
2523 ...gameBase ,
@@ -28,6 +26,7 @@ describe("turns", () => {
2826 me : 0 ,
2927 bot : 0 ,
3028 numZeroDelay : 0 ,
29+ expiresAt : undefined ,
3130 } ,
3231 itsTheirTurn : players ,
3332 } ) ,
@@ -40,10 +39,11 @@ describe("turns", () => {
4039 board . bot ++ ;
4140 }
4241
43- turns . begin ( userId , {
42+ const { expiresAt } = turns . begin ( userId , {
4443 expiresIn : 1000 ,
4544 playerMoveOnExpire : [ "go" , { itWasMe : false } ] ,
4645 } ) ;
46+ board . expiresAt = expiresAt ;
4747 } ,
4848 } as PM < P > ,
4949 endTurn : {
@@ -59,17 +59,18 @@ describe("turns", () => {
5959 endMatch ( ) ;
6060 return ;
6161 }
62- turns . begin ( userId , {
62+ const { expiresAt } = turns . begin ( userId , {
6363 expiresIn : delay ,
6464 playerMoveOnExpire : [ "beginWithDelay" , { delay : 0 } ] ,
6565 } ) ;
66+ board . expiresAt = expiresAt ;
6667 } ,
6768 } as PM < { delay : number } > ,
6869 move : {
6970 execute ( ) {
7071 //
7172 } ,
72- } ,
73+ } as PM ,
7374 } ,
7475 } satisfies Game < GS > ;
7576
@@ -79,9 +80,11 @@ describe("turns", () => {
7980 const match = new MatchTester < GS , G > ( { game, numPlayers : 1 } ) ;
8081
8182 const userId = match . meta . players . allIds [ 0 ] ;
83+ expect ( match . board . expiresAt ) . toBe ( undefined ) ;
8284
8385 // I make a move
8486 match . makeMove ( userId , "go" , { } ) ;
87+ expect ( match . board . expiresAt ) . toEqual ( 1000 ) ;
8588
8689 // Auto move 1 second later
8790 match . fastForward ( 1000 ) ;
@@ -149,24 +152,14 @@ describe("turns", () => {
149152 expect ( match . matchHasEnded ) . toBe ( true ) ;
150153 } ) ;
151154
152- // FIXME this is not true anymore, perhaps we need the opposite test
153- test . skip ( "turn ends on move" , ( ) => {
154- const match = new MatchTester < GS , G > ( { game, numPlayers : 2 } ) ;
155- const userId = match . meta . players . allIds [ 0 ] ;
156- match . makeMove ( userId , "go" , { itWasMe : true } ) ;
157- match . makeMove ( userId , "move" ) ;
158-
159- expect ( match . meta . players . byId [ userId ] . itsYourTurn ) . toBe ( false ) ;
160- } ) ;
155+ test ( "expiresAt" , ( ) => {
156+ const match = new MatchTester < GS , G > ( { game, numPlayers : 1 } ) ;
161157
162- // FIXME Not true anymore?
163- test . skip ( "making a move removes delayed move" , ( ) => {
164- const match = new MatchTester < GS , G > ( { game, numPlayers : 2 } ) ;
165158 const userId = match . meta . players . allIds [ 0 ] ;
166- match . makeMove ( userId , "go" , { itWasMe : true } ) ;
167- expect ( match . delayedMoves . length ) . toBe ( 1 ) ;
168- match . makeMove ( userId , "move" ) ;
169- expect ( match . delayedMoves . length ) . toBe ( 0 ) ;
159+ expect ( match . board . expiresAt ) . toBe ( undefined ) ;
160+
161+ match . makeMove ( userId , "go" , { } ) ;
162+ expect ( match . board . expiresAt ) . toEqual ( 1000 ) ;
170163 } ) ;
171164} ) ;
172165
0 commit comments