Skip to content

Commit a885a77

Browse files
authored
Fix final group number for consolation final (#244)
1 parent 862963f commit a885a77

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/base/stage/creator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,10 @@ export class StageCreator {
885885
private async createConsolationFinal(stageId: Id, losers: ParticipantSlot[][], overrides: ConsolationFinalOverrides = {}): Promise<void> {
886886
if (!this.stage.settings?.consolationFinal) return;
887887

888+
const finalGroupNumber = this.stage.type === 'double_elimination' ? 3 : 2;
888889
const semiFinalLosers = losers[losers.length - 2] as Duel;
889-
await this.createUniqueMatchBracket(stageId, 2, [semiFinalLosers], overrides);
890+
891+
await this.createUniqueMatchBracket(stageId, finalGroupNumber, [semiFinalLosers], overrides);
890892
}
891893

892894
/**

test/double-elimination.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ describe('Create double elimination stage', () => {
169169

170170
assert.strictEqual((await storage.select('match', 15)).number, 2); // Consolation final is number 2 of its round (arbitrary).
171171
});
172+
173+
it('should create a consolation final in the final group without grand final', async () => {
174+
await manager.create.stage({
175+
name: 'Example with consolation final',
176+
tournamentId: 0,
177+
type: 'double_elimination',
178+
seeding: [
179+
'Team 1', 'Team 2',
180+
'Team 3', 'Team 4',
181+
'Team 5', 'Team 6',
182+
'Team 7', 'Team 8',
183+
],
184+
settings: {
185+
grandFinal: 'none',
186+
consolationFinal: true,
187+
seedOrdering: ['natural'],
188+
},
189+
});
190+
191+
assert.deepEqual(await storage.select('group'), [
192+
{ id: 0, stage_id: 0, number: 1 },
193+
{ id: 1, stage_id: 0, number: 2 },
194+
{ id: 2, stage_id: 0, number: 3 }, // Final group.
195+
]);
196+
197+
assert.strictEqual((await storage.select('round')).length, 3 + 4 + 1 /* consolation final */);
198+
assert.strictEqual((await storage.select('match')).length, 14);
199+
assert.strictEqual((await storage.select('match', 13)).number, 2); // Consolation final is number 2 of its round (arbitrary).
200+
});
172201
});
173202

174203
describe('Previous and next match update in double elimination stage', () => {

0 commit comments

Comments
 (0)