Skip to content

Commit 0f26e8c

Browse files
refactor: cleanup
1 parent 11195fd commit 0f26e8c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

tests/mru-6.test.ts

+30-30
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ describe("League with 6 teams", async () => {
7878

7979
it("should be able to complete round 1", async () => {
8080
for (const match of machine.state.matches) {
81+
const matchId = match.id;
8182
await performAction("startMatch", {
82-
matchId: match.id,
83+
matchId,
8384
});
8485
const teamIds = Object.keys(match.scores).map((k) => parseInt(k));
8586

86-
const team1Id = teamIds[0];
87+
const [team1Id, team2Id] = teamIds;
8788
const teamOnePlayers = machine.state.players.filter(
8889
(p) => p.teamId === team1Id
8990
);
9091
if (!teamOnePlayers.length) {
9192
throw new Error("Players not found");
9293
}
9394

94-
const team2Id = teamIds[1];
9595
const teamTwoPlayers = machine.state.players.filter(
9696
(p) => p.teamId === team2Id
9797
);
@@ -101,41 +101,41 @@ describe("League with 6 teams", async () => {
101101

102102
// first team score a goal
103103
await performAction("logGoal", {
104-
matchId: match.id,
104+
matchId,
105105
playerId: teamOnePlayers[0].id,
106106
});
107107

108108
// second team score a goal
109109
await performAction("logGoal", {
110-
matchId: match.id,
110+
matchId,
111111
playerId: teamTwoPlayers[0].id,
112112
});
113113

114114
// first team score another goal
115115
await performAction("logGoal", {
116-
matchId: match.id,
116+
matchId,
117117
playerId: teamOnePlayers[1].id,
118118
});
119119

120120
// second team saves a goal
121121
await performAction("logBlock", {
122-
matchId: match.id,
122+
matchId,
123123
playerId: teamTwoPlayers[1].id,
124124
});
125125

126126
// first team does a foul
127127
await performAction("logFoul", {
128-
matchId: match.id,
128+
matchId,
129129
playerId: teamOnePlayers[1].id,
130130
});
131131

132132
// end the game
133133
await performAction("endMatch", {
134-
matchId: match.id,
134+
matchId,
135135
});
136136

137137
// 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);
139139
expect(_match?.scores[team1Id]).to.greaterThan(_match?.scores[team2Id]!);
140140
}
141141

@@ -146,6 +146,8 @@ describe("League with 6 teams", async () => {
146146
});
147147

148148
it("should be able to give a bye to team 5", async () => {
149+
expect(machine.state.meta.round).to.equal(1);
150+
149151
// give bye to the team 5
150152
await performAction("logByes", {
151153
teamId: 5,
@@ -162,12 +164,13 @@ describe("League with 6 teams", async () => {
162164

163165
it("should be able to complete round 2", async () => {
164166
for (const match of machine.state.matches) {
167+
const matchId = match.id;
165168
if (match.endTime) {
166169
continue;
167170
}
168171

169172
await performAction("startMatch", {
170-
matchId: match.id,
173+
matchId,
171174
});
172175
const teamIds = Object.keys(match.scores).map((k) => parseInt(k));
173176

@@ -189,37 +192,37 @@ describe("League with 6 teams", async () => {
189192

190193
// first team score a goal
191194
await performAction("logGoal", {
192-
matchId: match.id,
195+
matchId,
193196
playerId: teamOnePlayers[0].id,
194197
});
195198

196199
// second team score a goal
197200
await performAction("logGoal", {
198-
matchId: match.id,
201+
matchId,
199202
playerId: teamTwoPlayers[0].id,
200203
});
201204

202205
// first team score another goal
203206
await performAction("logGoal", {
204-
matchId: match.id,
207+
matchId,
205208
playerId: teamOnePlayers[1].id,
206209
});
207210

208211
// second team saves a goal
209212
await performAction("logBlock", {
210-
matchId: match.id,
213+
matchId,
211214
playerId: teamTwoPlayers[1].id,
212215
});
213216

214217
// first team does a foul
215218
await performAction("logFoul", {
216-
matchId: match.id,
219+
matchId,
217220
playerId: teamOnePlayers[1].id,
218221
});
219222

220223
// end the game
221224
await performAction("endMatch", {
222-
matchId: match.id,
225+
matchId,
223226
});
224227

225228
// check winner
@@ -245,7 +248,7 @@ describe("League with 6 teams", async () => {
245248
throw new Error("Players not found");
246249
}
247250

248-
const { logs, errors } = await performAction("logGoal", {
251+
const { errors } = await performAction("logGoal", {
249252
matchId: match.id,
250253
playerId: teamOnePlayers[0].id,
251254
});
@@ -254,7 +257,7 @@ describe("League with 6 teams", async () => {
254257
}
255258
// check error for "MATCH_NOT_STARTED"
256259
assert.typeOf(errors, "array");
257-
expect(errors?.length).to.not.equal(0);
260+
expect(errors.length).to.not.equal(0);
258261
expect(errors[0].message).to.equal("MATCH_NOT_STARTED");
259262
});
260263

@@ -309,7 +312,7 @@ describe("League with 6 teams", async () => {
309312
const playersNotPlaying = machine.state.players.filter(
310313
(p) => p.teamId !== team1Id && p.teamId !== team2Id
311314
);
312-
const { logs: logs1, errors: errors1 } = await performAction("logGoal", {
315+
const { errors: errors1 } = await performAction("logGoal", {
313316
matchId: match.id,
314317
playerId: playersNotPlaying[0].id,
315318
});
@@ -318,17 +321,14 @@ describe("League with 6 teams", async () => {
318321
}
319322
// check error for "PLAYER_NOT_FOUND"
320323
assert.typeOf(errors1, "array");
321-
expect(errors1?.length).to.not.equal(0);
324+
expect(errors1.length).to.not.equal(0);
322325
expect(errors1[0].message).to.equal("INVALID_TEAM");
323326

324327
// 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+
});
332332

333333
if (!errors2) {
334334
throw new Error("Error not found");
@@ -410,7 +410,7 @@ describe("League with 6 teams", async () => {
410410
throw new Error("Players not found");
411411
}
412412

413-
const { logs, errors } = await performAction("logGoal", {
413+
const { errors } = await performAction("logGoal", {
414414
matchId: match.id,
415415
playerId: teamOnePlayers[0].id,
416416
});
@@ -420,7 +420,7 @@ describe("League with 6 teams", async () => {
420420
}
421421
// check error for "TOURNAMENT_ENDED"
422422
assert.typeOf(errors, "array");
423-
expect(errors?.length).to.not.equal(0);
423+
expect(errors.length).to.not.equal(0);
424424
expect(errors[0].message).to.equal("TOURNAMENT_ENDED");
425425
});
426426

0 commit comments

Comments
 (0)