fix: repair double-elimination tournament codes
This commit is contained in:
1 parent
2d1c33f1e9
commit
3357d4c9c8
2 files changed
+243
-14
No files matched your search
+94
@@ -0,0 +1,94 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { buildRepairPlan } from './repair-double-elimination-series-rules';
|
||||
import type { MatchDocument, TournamentCodeDocument } from '../schema';
|
||||
|
||||
function createMatch(overrides: Partial<MatchDocument>): MatchDocument {
|
||||
return {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
gameCount: 3,
|
||||
tournamentCodeIds: [],
|
||||
doubleElimination: {
|
||||
teamCount: 8,
|
||||
resetFinalEnabled: false,
|
||||
resetFinalCreated: false,
|
||||
seeds: [],
|
||||
bracketMatches: [],
|
||||
placements: {},
|
||||
events: [],
|
||||
},
|
||||
...overrides,
|
||||
} as unknown as MatchDocument;
|
||||
}
|
||||
|
||||
function createCode(
|
||||
overrides: Partial<TournamentCodeDocument>,
|
||||
): TournamentCodeDocument {
|
||||
return {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
code: 'CODE',
|
||||
state: 'reserved',
|
||||
...overrides,
|
||||
} as unknown as TournamentCodeDocument;
|
||||
}
|
||||
|
||||
describe('repair-double-elimination-series-rules buildRepairPlan', () => {
|
||||
it('plans missing ready series slots even when result games already exist', () => {
|
||||
const match = createMatch({
|
||||
result: {
|
||||
riotMatchIds: ['KR_1'],
|
||||
games: [
|
||||
{
|
||||
gameNumber: 1,
|
||||
bracketMatchId: 'WB_R2_M1',
|
||||
},
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
doubleElimination: {
|
||||
teamCount: 8,
|
||||
resetFinalEnabled: false,
|
||||
resetFinalCreated: false,
|
||||
seeds: [],
|
||||
bracketMatches: [
|
||||
{
|
||||
bracketMatchId: 'WB_R2_M1',
|
||||
gameNumber: 1,
|
||||
gameCount: 3,
|
||||
requiredWins: 2,
|
||||
bracketSide: 'winner',
|
||||
roundNumber: 2,
|
||||
matchNumber: 1,
|
||||
state: 'ready',
|
||||
teamAIndex: 4,
|
||||
teamBIndex: 6,
|
||||
},
|
||||
],
|
||||
placements: {},
|
||||
events: [],
|
||||
},
|
||||
});
|
||||
const existingFirstSetCode = createCode({
|
||||
bracketMatchId: 'WB_R2_M1',
|
||||
gameNumber: 1,
|
||||
});
|
||||
|
||||
const plan = buildRepairPlan(match, [existingFirstSetCode], 3);
|
||||
|
||||
expect(plan.ruleRepairSkippedReason).toBe('result-games-exist');
|
||||
expect(plan.codeUpdates).toEqual([]);
|
||||
expect(plan.missingReadySlots).toEqual([
|
||||
{
|
||||
bracketMatchId: 'WB_R2_M1',
|
||||
gameNumber: 2,
|
||||
seriesGameNumber: 2,
|
||||
seriesGameCount: 3,
|
||||
},
|
||||
{
|
||||
bracketMatchId: 'WB_R2_M1',
|
||||
gameNumber: 3,
|
||||
seriesGameNumber: 3,
|
||||
seriesGameCount: 3,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user