@@ -4,22 +4,20 @@ import { BoardMove, Game, GameState, INIT_MOVE, PlayerMove } from ".";
4
4
import { MatchTester } from "./testing" ;
5
5
6
6
const gameBase = {
7
- version : "2.3.0" ,
8
7
minPlayers : 1 ,
9
8
maxPlayers : 10 ,
10
9
} ;
11
10
12
11
describe ( "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
+ } ;
14
18
type GS = GameState < B > ;
15
19
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 > ;
23
21
24
22
const game = {
25
23
...gameBase ,
@@ -28,6 +26,7 @@ describe("turns", () => {
28
26
me : 0 ,
29
27
bot : 0 ,
30
28
numZeroDelay : 0 ,
29
+ expiresAt : undefined ,
31
30
} ,
32
31
itsTheirTurn : players ,
33
32
} ) ,
@@ -40,10 +39,11 @@ describe("turns", () => {
40
39
board . bot ++ ;
41
40
}
42
41
43
- turns . begin ( userId , {
42
+ const { expiresAt } = turns . begin ( userId , {
44
43
expiresIn : 1000 ,
45
44
playerMoveOnExpire : [ "go" , { itWasMe : false } ] ,
46
45
} ) ;
46
+ board . expiresAt = expiresAt ;
47
47
} ,
48
48
} as PM < P > ,
49
49
endTurn : {
@@ -59,17 +59,18 @@ describe("turns", () => {
59
59
endMatch ( ) ;
60
60
return ;
61
61
}
62
- turns . begin ( userId , {
62
+ const { expiresAt } = turns . begin ( userId , {
63
63
expiresIn : delay ,
64
64
playerMoveOnExpire : [ "beginWithDelay" , { delay : 0 } ] ,
65
65
} ) ;
66
+ board . expiresAt = expiresAt ;
66
67
} ,
67
68
} as PM < { delay : number } > ,
68
69
move : {
69
70
execute ( ) {
70
71
//
71
72
} ,
72
- } ,
73
+ } as PM ,
73
74
} ,
74
75
} satisfies Game < GS > ;
75
76
@@ -79,9 +80,11 @@ describe("turns", () => {
79
80
const match = new MatchTester < GS , G > ( { game, numPlayers : 1 } ) ;
80
81
81
82
const userId = match . meta . players . allIds [ 0 ] ;
83
+ expect ( match . board . expiresAt ) . toBe ( undefined ) ;
82
84
83
85
// I make a move
84
86
match . makeMove ( userId , "go" , { } ) ;
87
+ expect ( match . board . expiresAt ) . toEqual ( 1000 ) ;
85
88
86
89
// Auto move 1 second later
87
90
match . fastForward ( 1000 ) ;
@@ -149,24 +152,14 @@ describe("turns", () => {
149
152
expect ( match . matchHasEnded ) . toBe ( true ) ;
150
153
} ) ;
151
154
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 } ) ;
161
157
162
- // FIXME Not true anymore?
163
- test . skip ( "making a move removes delayed move" , ( ) => {
164
- const match = new MatchTester < GS , G > ( { game, numPlayers : 2 } ) ;
165
158
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 ) ;
170
163
} ) ;
171
164
} ) ;
172
165
0 commit comments