test: harden competition migration assertions

This commit is contained in:
dahyeon committed 2026-07-13 03:59:52 +00:00
1 parent a307780752
commit bbcb2f43dc
2 files changed
+72 -71

No files matched your search

@@ -63,12 +63,11 @@ describe('planCompetitionMigration', () => {
riotMatchId: 'KR_WITH_ARCHIVE',
},
});
expect(games[1]).toMatchObject({
evidence: {
type: 'legacy',
legacyReference: expect.stringContaining('KR_NORMALIZED_ONLY'),
},
});
expect(games[1].evidence.type).toBe('legacy');
if (games[1].evidence.type !== 'legacy') {
throw new Error('Expected normalized-only legacy evidence.');
}
expect(games[1].evidence.legacyReference).toContain('KR_NORMALIZED_ONLY');
});
it('turns a winner-only Series into an adjudication without fabricating games', () => {
@@ -131,12 +130,7 @@ describe('planCompetitionMigration', () => {
const plan = planCompetitionMigration(legacy);
expect(plan).toMatchObject({
status: 'quarantined',
reasons: expect.arrayContaining([
expect.objectContaining({ code: 'AMBIGUOUS_GAME_ASSIGNMENT' }),
]),
});
expectQuarantineReason(plan, 'AMBIGUOUS_GAME_ASSIGNMENT');
});
it('preserves a persisted non-canonical round-robin schedule', () => {
@@ -187,17 +181,19 @@ describe('planCompetitionMigration', () => {
const plan = requireReady(planCompetitionMigration(legacy));
expect(plan.competition.format).toMatchObject({
type: 'round-robin',
pairings: expect.arrayContaining([
expect.objectContaining({
roundNumber: 3,
matchNumber: 4,
teamAId: plan.competition.teams[5].teamId,
teamBId: plan.competition.teams[6].teamId,
}),
]),
});
expect(plan.competition.format.type).toBe('round-robin');
if (plan.competition.format.type !== 'round-robin') {
throw new Error('Expected a round-robin format.');
}
expect(
plan.competition.format.pairings?.some(
(pairing) =>
pairing.roundNumber === 3 &&
pairing.matchNumber === 4 &&
pairing.teamAId === plan.competition.teams[5].teamId &&
pairing.teamBId === plan.competition.teams[6].teamId,
),
).toBe(true);
expect(
plan.facts.filter(({ type }) => type === 'game-accepted'),
).toHaveLength(12);
@@ -284,14 +280,7 @@ describe('planCompetitionMigration', () => {
const plan = planCompetitionMigration(legacy);
expect(plan).toMatchObject({
status: 'quarantined',
reasons: expect.arrayContaining([
expect.objectContaining({
code: 'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT',
}),
]),
});
expectQuarantineReason(plan, 'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT');
});
it('quarantines conflicting Riot evidence and global game number', () => {
@@ -322,14 +311,10 @@ describe('planCompetitionMigration', () => {
],
});
expect(planCompetitionMigration(legacy)).toMatchObject({
status: 'quarantined',
reasons: expect.arrayContaining([
expect.objectContaining({
code: 'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT',
}),
]),
});
expectQuarantineReason(
planCompetitionMigration(legacy),
'TOURNAMENT_CODE_ASSIGNMENT_CONFLICT',
);
});
it('quarantines a TournamentCode game number outside the Competition topology', () => {
@@ -346,14 +331,10 @@ describe('planCompetitionMigration', () => {
],
});
expect(planCompetitionMigration(legacy)).toMatchObject({
status: 'quarantined',
reasons: expect.arrayContaining([
expect.objectContaining({
code: 'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
}),
]),
});
expectQuarantineReason(
planCompetitionMigration(legacy),
'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
);
});
it('does not guess the first slot of a multi-slot Series without exact slot evidence', () => {
@@ -372,14 +353,10 @@ describe('planCompetitionMigration', () => {
const plan = planCompetitionMigration(legacy);
expect(plan).toMatchObject({
status: 'quarantined',
reasons: expect.arrayContaining([
expect.objectContaining({
code: 'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
}),
]),
});
expectQuarantineReason(
plan,
'TOURNAMENT_CODE_ASSIGNMENT_MAPPING_NOT_FOUND',
);
});
it('repairs the data.txt WB_R2_M2 positional bug from accepted game evidence', () => {
@@ -418,16 +395,22 @@ describe('planCompetitionMigration', () => {
loserTeamId: team3!.teamId,
},
});
expect(series('WB_FINAL')).toMatchObject({
entries: expect.arrayContaining([
{ slot: 'B', teamId: team8!.teamId, gameWins: 0 },
]),
});
expect(series('LB_R2_M1')).toMatchObject({
entries: expect.arrayContaining([
{ slot: 'B', teamId: team3!.teamId, gameWins: 0 },
]),
});
expect(
series('WB_FINAL')?.entries.some(
(entry) =>
entry.slot === 'B' &&
entry.teamId === team8!.teamId &&
entry.gameWins === 0,
),
).toBe(true);
expect(
series('LB_R2_M1')?.entries.some(
(entry) =>
entry.slot === 'B' &&
entry.teamId === team3!.teamId &&
entry.gameWins === 0,
),
).toBe(true);
});
});
@@ -484,6 +467,19 @@ function requireReady(
return plan;
}
function expectQuarantineReason(
plan: ReturnType<typeof planCompetitionMigration>,
code: string,
): void {
expect(plan.status).toBe('quarantined');
if (plan.status !== 'quarantined') {
throw new Error(
`Expected a quarantined migration plan, got ${plan.status}.`,
);
}
expect(plan.reasons.some((reason) => reason.code === code)).toBe(true);
}
function loadDataTxtFixture(): LegacyMatchInput {
const seededTeamIndexes = [1, 8, 3, 4, 5, 6, 7, 2];
const games = [