Skip to content

Commit cecd181

Browse files
authored
Fix get.currentRound() when BYE decided (#245)
1 parent a885a77 commit cecd181

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class Get extends BaseGetter {
112112
const matchesByRound = helpers.splitBy(matches, 'round_id');
113113

114114
for (const roundMatches of matchesByRound) {
115-
if (roundMatches.every(match => match.status >= Status.Completed))
115+
if (roundMatches.every(match => helpers.isMatchStale(match)))
116116
continue;
117117

118118
const round = await this.storage.select('round', roundMatches[0].round_id);

test/get.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,38 @@ describe('Get child games', () => {
5959
});
6060
});
6161

62+
describe('Get current round', () => {
63+
64+
beforeEach(() => {
65+
storage.reset();
66+
});
67+
68+
it('should skip a round decided by BYEs when getting the current round', async () => {
69+
const stage = await manager.create.stage({
70+
name: 'Some Title',
71+
tournamentId: 0,
72+
type: 'single_elimination',
73+
seeding: ['P1', 'P2', 'P3', null],
74+
settings: {
75+
grandFinal: 'simple',
76+
balanceByes: true,
77+
matchesChildCount: 3,
78+
},
79+
});
80+
81+
assert.strictEqual((await manager.get.currentRound(stage.id)).number, 1);
82+
assert.deepEqual((await manager.get.currentMatches(stage.id)).map(match => match.round_id), [0]);
83+
84+
await manager.update.match({ id: 1, opponent1: { result: 'win' } });
85+
86+
const currentRound = await manager.get.currentRound(stage.id);
87+
const currentMatches = await manager.get.currentMatches(stage.id);
88+
89+
assert.strictEqual(currentRound.number, 2);
90+
assert.deepEqual(currentMatches.map(match => match.round_id), [currentRound.id]);
91+
});
92+
});
93+
6294
describe('Get final standings', () => {
6395

6496
beforeEach(() => {

test/unit/get.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ describe('Unit - get', () => {
6161
[{ stage_id: 2, round_id: 0, status: Status.Completed }, { stage_id: 2, round_id: 0, status: Status.Completed }, { stage_id: 2, round_id: 1, status: Status.Waiting }],
6262
{ stage_id: 2, id: 1 },
6363
],
64+
[
65+
'two rounds, with 1st round decided by completed matches and BYEs',
66+
[{ stage_id: 2, id: 0 }, { stage_id: 2, id: 1 }],
67+
[
68+
{ stage_id: 2, round_id: 0, status: Status.Locked, opponent1: { id: 0 }, opponent2: null },
69+
{ stage_id: 2, round_id: 0, status: Status.Completed },
70+
{ stage_id: 2, round_id: 1, status: Status.Ready },
71+
],
72+
{ stage_id: 2, id: 1 },
73+
],
6474
[
6575
'two stages, with all matches completed',
6676
[{ stage_id: 2, id: 0 }, { stage_id: 2, id: 1 }],

0 commit comments

Comments
 (0)