@@ -78,20 +78,20 @@ describe("League with 6 teams", async () => {
78
78
79
79
it ( "should be able to complete round 1" , async ( ) => {
80
80
for ( const match of machine . state . matches ) {
81
+ const matchId = match . id ;
81
82
await performAction ( "startMatch" , {
82
- matchId : match . id ,
83
+ matchId,
83
84
} ) ;
84
85
const teamIds = Object . keys ( match . scores ) . map ( ( k ) => parseInt ( k ) ) ;
85
86
86
- const team1Id = teamIds [ 0 ] ;
87
+ const [ team1Id , team2Id ] = teamIds ;
87
88
const teamOnePlayers = machine . state . players . filter (
88
89
( p ) => p . teamId === team1Id
89
90
) ;
90
91
if ( ! teamOnePlayers . length ) {
91
92
throw new Error ( "Players not found" ) ;
92
93
}
93
94
94
- const team2Id = teamIds [ 1 ] ;
95
95
const teamTwoPlayers = machine . state . players . filter (
96
96
( p ) => p . teamId === team2Id
97
97
) ;
@@ -101,41 +101,41 @@ describe("League with 6 teams", async () => {
101
101
102
102
// first team score a goal
103
103
await performAction ( "logGoal" , {
104
- matchId : match . id ,
104
+ matchId,
105
105
playerId : teamOnePlayers [ 0 ] . id ,
106
106
} ) ;
107
107
108
108
// second team score a goal
109
109
await performAction ( "logGoal" , {
110
- matchId : match . id ,
110
+ matchId,
111
111
playerId : teamTwoPlayers [ 0 ] . id ,
112
112
} ) ;
113
113
114
114
// first team score another goal
115
115
await performAction ( "logGoal" , {
116
- matchId : match . id ,
116
+ matchId,
117
117
playerId : teamOnePlayers [ 1 ] . id ,
118
118
} ) ;
119
119
120
120
// second team saves a goal
121
121
await performAction ( "logBlock" , {
122
- matchId : match . id ,
122
+ matchId,
123
123
playerId : teamTwoPlayers [ 1 ] . id ,
124
124
} ) ;
125
125
126
126
// first team does a foul
127
127
await performAction ( "logFoul" , {
128
- matchId : match . id ,
128
+ matchId,
129
129
playerId : teamOnePlayers [ 1 ] . id ,
130
130
} ) ;
131
131
132
132
// end the game
133
133
await performAction ( "endMatch" , {
134
- matchId : match . id ,
134
+ matchId,
135
135
} ) ;
136
136
137
137
// check winner
138
- const _match = machine . state . matches . find ( ( m ) => m . id === match . id ) ;
138
+ const _match = machine . state . matches . find ( ( m ) => m . id === matchId ) ;
139
139
expect ( _match ?. scores [ team1Id ] ) . to . greaterThan ( _match ?. scores [ team2Id ] ! ) ;
140
140
}
141
141
@@ -146,6 +146,8 @@ describe("League with 6 teams", async () => {
146
146
} ) ;
147
147
148
148
it ( "should be able to give a bye to team 5" , async ( ) => {
149
+ expect ( machine . state . meta . round ) . to . equal ( 1 ) ;
150
+
149
151
// give bye to the team 5
150
152
await performAction ( "logByes" , {
151
153
teamId : 5 ,
@@ -162,12 +164,13 @@ describe("League with 6 teams", async () => {
162
164
163
165
it ( "should be able to complete round 2" , async ( ) => {
164
166
for ( const match of machine . state . matches ) {
167
+ const matchId = match . id ;
165
168
if ( match . endTime ) {
166
169
continue ;
167
170
}
168
171
169
172
await performAction ( "startMatch" , {
170
- matchId : match . id ,
173
+ matchId,
171
174
} ) ;
172
175
const teamIds = Object . keys ( match . scores ) . map ( ( k ) => parseInt ( k ) ) ;
173
176
@@ -189,37 +192,37 @@ describe("League with 6 teams", async () => {
189
192
190
193
// first team score a goal
191
194
await performAction ( "logGoal" , {
192
- matchId : match . id ,
195
+ matchId,
193
196
playerId : teamOnePlayers [ 0 ] . id ,
194
197
} ) ;
195
198
196
199
// second team score a goal
197
200
await performAction ( "logGoal" , {
198
- matchId : match . id ,
201
+ matchId,
199
202
playerId : teamTwoPlayers [ 0 ] . id ,
200
203
} ) ;
201
204
202
205
// first team score another goal
203
206
await performAction ( "logGoal" , {
204
- matchId : match . id ,
207
+ matchId,
205
208
playerId : teamOnePlayers [ 1 ] . id ,
206
209
} ) ;
207
210
208
211
// second team saves a goal
209
212
await performAction ( "logBlock" , {
210
- matchId : match . id ,
213
+ matchId,
211
214
playerId : teamTwoPlayers [ 1 ] . id ,
212
215
} ) ;
213
216
214
217
// first team does a foul
215
218
await performAction ( "logFoul" , {
216
- matchId : match . id ,
219
+ matchId,
217
220
playerId : teamOnePlayers [ 1 ] . id ,
218
221
} ) ;
219
222
220
223
// end the game
221
224
await performAction ( "endMatch" , {
222
- matchId : match . id ,
225
+ matchId,
223
226
} ) ;
224
227
225
228
// check winner
@@ -245,7 +248,7 @@ describe("League with 6 teams", async () => {
245
248
throw new Error ( "Players not found" ) ;
246
249
}
247
250
248
- const { logs , errors } = await performAction ( "logGoal" , {
251
+ const { errors } = await performAction ( "logGoal" , {
249
252
matchId : match . id ,
250
253
playerId : teamOnePlayers [ 0 ] . id ,
251
254
} ) ;
@@ -254,7 +257,7 @@ describe("League with 6 teams", async () => {
254
257
}
255
258
// check error for "MATCH_NOT_STARTED"
256
259
assert . typeOf ( errors , "array" ) ;
257
- expect ( errors ? .length ) . to . not . equal ( 0 ) ;
260
+ expect ( errors . length ) . to . not . equal ( 0 ) ;
258
261
expect ( errors [ 0 ] . message ) . to . equal ( "MATCH_NOT_STARTED" ) ;
259
262
} ) ;
260
263
@@ -309,7 +312,7 @@ describe("League with 6 teams", async () => {
309
312
const playersNotPlaying = machine . state . players . filter (
310
313
( p ) => p . teamId !== team1Id && p . teamId !== team2Id
311
314
) ;
312
- const { logs : logs1 , errors : errors1 } = await performAction ( "logGoal" , {
315
+ const { errors : errors1 } = await performAction ( "logGoal" , {
313
316
matchId : match . id ,
314
317
playerId : playersNotPlaying [ 0 ] . id ,
315
318
} ) ;
@@ -318,17 +321,14 @@ describe("League with 6 teams", async () => {
318
321
}
319
322
// check error for "PLAYER_NOT_FOUND"
320
323
assert . typeOf ( errors1 , "array" ) ;
321
- expect ( errors1 ? .length ) . to . not . equal ( 0 ) ;
324
+ expect ( errors1 . length ) . to . not . equal ( 0 ) ;
322
325
expect ( errors1 [ 0 ] . message ) . to . equal ( "INVALID_TEAM" ) ;
323
326
324
327
// remove a goal when not scored
325
- const { logs : logs2 , errors : errors2 } = await performAction (
326
- "removeGoal" ,
327
- {
328
- matchId : match . id ,
329
- playerId : teamTwoPlayers [ 0 ] . id ,
330
- }
331
- ) ;
328
+ const { errors : errors2 } = await performAction ( "removeGoal" , {
329
+ matchId : match . id ,
330
+ playerId : teamTwoPlayers [ 0 ] . id ,
331
+ } ) ;
332
332
333
333
if ( ! errors2 ) {
334
334
throw new Error ( "Error not found" ) ;
@@ -410,7 +410,7 @@ describe("League with 6 teams", async () => {
410
410
throw new Error ( "Players not found" ) ;
411
411
}
412
412
413
- const { logs , errors } = await performAction ( "logGoal" , {
413
+ const { errors } = await performAction ( "logGoal" , {
414
414
matchId : match . id ,
415
415
playerId : teamOnePlayers [ 0 ] . id ,
416
416
} ) ;
@@ -420,7 +420,7 @@ describe("League with 6 teams", async () => {
420
420
}
421
421
// check error for "TOURNAMENT_ENDED"
422
422
assert . typeOf ( errors , "array" ) ;
423
- expect ( errors ? .length ) . to . not . equal ( 0 ) ;
423
+ expect ( errors . length ) . to . not . equal ( 0 ) ;
424
424
expect ( errors [ 0 ] . message ) . to . equal ( "TOURNAMENT_ENDED" ) ;
425
425
} ) ;
426
426
0 commit comments