Files
lolympus-tournament-support/apps/api/src/modules/global/database/migrations/repair-double-elimination-series-rules.spec.ts
T
dahyeon 4b8ccf0077 fix: harden result polling and Redis 8.10 operations
Preserve tournament result jobs through lock contention and transient failures,
atomically schedule retries before acknowledgement, and publish initial polls
after releasing the preparation lock.

Fix Redis connection blocking, durability Hash cleanup, duplicate auction
request ordering, and scheduled-job promotion. Use native Redis 8.10 stream,
lock, counter, and field-expiring cache operations with invalidation fencing.

Repair 90 test type errors and add a repeatable API typecheck command.

Validation: 704 API tests, 129 web tests, 31 real Redis integration tests,
3 dependency checks, workspace type checks and builds, and changed-file lint.
2026-11-09 17:33:13 +09:00

103 lines
2.6 KiB
TypeScript

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',
riotMatchId: 'KR_1',
blueTeamIndex: 4,
redTeamIndex: 6,
winnerTeamIndex: 4,
winnerSide: 'blue',
gameCreation: Date.parse('2026-05-03T00:00:00.000Z'),
gameDuration: 1800,
participants: [],
},
],
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,
},
]);
});
});