mirror of
https://github.com/diangogav/EDOpro-server-ts
synced 2026-08-24 00:23:05 -04:00
fix: prevent match scores from incrementing on a draw and add tests for duel winner logic
This commit is contained in:
parent
ad8bbabb51
commit
10551e3c0e
2 changed files with 39 additions and 3 deletions
39
src/shared/room/domain/match/domain/Match.test.ts
Normal file
39
src/shared/room/domain/match/domain/Match.test.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { Match } from "./Match";
|
||||
import { Team } from "../../../Team";
|
||||
|
||||
describe("Match", () => {
|
||||
it("should NOT increment score for either player on a draw", () => {
|
||||
const match = new Match({ bestOf: 3 });
|
||||
match.initializeHistoricalData([
|
||||
{ id: "1", name: "Player 0", team: 0 },
|
||||
{ id: "2", name: "Player 1", team: 1 }
|
||||
]);
|
||||
|
||||
const DRAW = 2;
|
||||
match.duelWinner(DRAW, 10, [
|
||||
{ name: "Player 0", ipAddress: "127.0.0.1" },
|
||||
{ name: "Player 1", ipAddress: "127.0.0.2" }
|
||||
]);
|
||||
|
||||
expect(match.score.team0).toBe(0);
|
||||
expect(match.score.team1).toBe(0);
|
||||
expect(match.isFinished()).toBe(false);
|
||||
});
|
||||
|
||||
it("should increment score correctly for winner", () => {
|
||||
const match = new Match({ bestOf: 3 });
|
||||
match.initializeHistoricalData([
|
||||
{ id: "1", name: "Player 0", team: 0 },
|
||||
{ id: "2", name: "Player 1", team: 1 }
|
||||
]);
|
||||
|
||||
match.duelWinner(0, 10, [
|
||||
{ name: "Player 0", ipAddress: "127.0.0.1" },
|
||||
{ name: "Player 1", ipAddress: "127.0.0.2" }
|
||||
]);
|
||||
|
||||
expect(match.score.team0).toBe(1);
|
||||
expect(match.score.team1).toBe(0);
|
||||
expect(match.isFinished()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -76,9 +76,6 @@ export class Match {
|
|||
}
|
||||
|
||||
if (winner === this.DRAW) {
|
||||
this.playerScore++;
|
||||
this.opponentScore++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue