fix: recover legacy tournament code transitions
This commit is contained in:
1 parent
489d040d8f
commit
ef47de7e4f
5 files changed
+775
-5
No files matched your search
@@ -244,6 +244,162 @@ describe('migrateCompetitionDomain', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('hydrates Riot occurrence evidence and persists the normalized used transition idempotently', async () => {
|
||||
const riotMatchId = 'KR_LEGACY_USED_TRANSITION';
|
||||
const match = readyMatch(riotMatchId);
|
||||
match.updatedAt = new Date('2026-07-03T00:06:00.000Z');
|
||||
const legacyOccurrenceAt = new Date(1_782_864_000_000 + 1800 * 1000);
|
||||
const code = usedTournamentCode(match, riotMatchId);
|
||||
code.reservedAt = new Date('2026-07-03T00:00:00.000Z');
|
||||
code.usedAt = legacyOccurrenceAt;
|
||||
code.updatedAt = new Date('2026-07-03T00:05:00.000Z');
|
||||
const originalCode = canonical(code);
|
||||
const archive = riotArchive(riotMatchId);
|
||||
archive.raw = {
|
||||
info: {
|
||||
gameCreation: 1_782_864_000_000,
|
||||
gameEndTimestamp: legacyOccurrenceAt.getTime(),
|
||||
},
|
||||
};
|
||||
const db = new MemoryMigrationDb({
|
||||
match: [match],
|
||||
riotMatch: [archive],
|
||||
tournamentCode: [code],
|
||||
});
|
||||
|
||||
const dryRun = await migrateCompetitionDomain(db);
|
||||
|
||||
expect(dryRun.summary).toMatchObject({
|
||||
ready: 1,
|
||||
quarantined: 0,
|
||||
warnings: 1,
|
||||
});
|
||||
const warning = dryRun.matches[0].warnings.find(
|
||||
({ code: warningCode }) =>
|
||||
warningCode === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
);
|
||||
expect(warning?.details).toMatchObject({
|
||||
originalReservedAt: '2026-07-03T00:00:00.000Z',
|
||||
originalUsedAt: legacyOccurrenceAt.toISOString(),
|
||||
sourceUpdatedAt: '2026-07-03T00:05:00.000Z',
|
||||
normalizedUsedAt: '2026-07-03T00:05:00.000Z',
|
||||
legacyOccurrenceSource: 'riot-archive-gameEndTimestamp',
|
||||
riotMatchId,
|
||||
strategy: 'use-persisted-transition-time',
|
||||
});
|
||||
expect(db.writeCount).toBe(0);
|
||||
|
||||
const firstApply = await migrateCompetitionDomain(db, {
|
||||
dryRun: false,
|
||||
startSession: () => Promise.resolve(new FakeSession()),
|
||||
});
|
||||
|
||||
expect(firstApply.summary).toMatchObject({ applied: 1, failed: 0 });
|
||||
expect(db.docs('tournament_code_assignment')).toContainEqual(
|
||||
expect.objectContaining({
|
||||
state: 'used',
|
||||
reservedAt: new Date('2026-07-03T00:00:00.000Z'),
|
||||
usedAt: new Date('2026-07-03T00:05:00.000Z'),
|
||||
createdAt: new Date('2026-07-03T00:00:00.000Z'),
|
||||
updatedAt: new Date('2026-07-03T00:05:00.000Z'),
|
||||
}),
|
||||
);
|
||||
expect(canonical(db.docs('tournamentCode')[0])).toBe(originalCode);
|
||||
|
||||
const replay = await migrateCompetitionDomain(db, {
|
||||
dryRun: false,
|
||||
startSession: () => Promise.resolve(new FakeSession()),
|
||||
});
|
||||
|
||||
expect(replay.summary).toMatchObject({
|
||||
applied: 0,
|
||||
alreadyApplied: 1,
|
||||
failed: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
'raw.info.gameCreation',
|
||||
{ raw: { info: { gameCreation: 1_782_864_000_000 } } },
|
||||
],
|
||||
[
|
||||
'top-level gameCreation',
|
||||
{
|
||||
gameCreation: 1_782_864_000_000,
|
||||
raw: { metadata: { matchId: 'KR_GAME_CREATION_FALLBACK' } },
|
||||
},
|
||||
],
|
||||
])(
|
||||
'hydrates the %s Riot occurrence fallback',
|
||||
async (_label, archiveFields) => {
|
||||
const riotMatchId = 'KR_GAME_CREATION_FALLBACK';
|
||||
const match = readyMatch(riotMatchId);
|
||||
const code = usedTournamentCode(match, riotMatchId);
|
||||
code.reservedAt = new Date('2026-07-01T00:10:00.000Z');
|
||||
code.usedAt = new Date('2026-07-01T00:00:00.000Z');
|
||||
code.updatedAt = new Date('2026-07-01T00:20:00.000Z');
|
||||
const archive = Object.assign(riotArchive(riotMatchId), archiveFields);
|
||||
const db = new MemoryMigrationDb({
|
||||
match: [match],
|
||||
riotMatch: [archive],
|
||||
tournamentCode: [code],
|
||||
});
|
||||
|
||||
const result = await migrateCompetitionDomain(db);
|
||||
|
||||
expect(result.summary).toMatchObject({ ready: 1, quarantined: 0 });
|
||||
const warning = result.matches[0].warnings.find(
|
||||
({ code: warningCode }) =>
|
||||
warningCode === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
);
|
||||
expect(warning?.details).toMatchObject({
|
||||
originalUsedAt: '2026-07-01T00:00:00.000Z',
|
||||
normalizedUsedAt: '2026-07-01T00:20:00.000Z',
|
||||
legacyOccurrenceSource: 'riot-archive-gameCreation',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
['null', null],
|
||||
['blank', ''],
|
||||
['invalid', 'not-a-date'],
|
||||
])(
|
||||
'falls back to archive gameCreation when gameEndTimestamp is %s',
|
||||
async (_label, invalidGameEnd) => {
|
||||
const riotMatchId = 'KR_INVALID_ARCHIVE_GAME_END';
|
||||
const match = readyMatch(riotMatchId);
|
||||
const code = usedTournamentCode(match, riotMatchId);
|
||||
code.reservedAt = new Date('2026-07-01T00:10:00.000Z');
|
||||
code.usedAt = new Date('2026-07-01T00:00:00.000Z');
|
||||
code.updatedAt = new Date('2026-07-01T00:20:00.000Z');
|
||||
const archive = riotArchive(riotMatchId);
|
||||
archive.raw = {
|
||||
info: {
|
||||
gameEndTimestamp: invalidGameEnd,
|
||||
gameCreation: 1_782_864_000_000,
|
||||
},
|
||||
};
|
||||
const db = new MemoryMigrationDb({
|
||||
match: [match],
|
||||
riotMatch: [archive],
|
||||
tournamentCode: [code],
|
||||
});
|
||||
|
||||
const result = await migrateCompetitionDomain(db);
|
||||
|
||||
expect(result.summary).toMatchObject({ ready: 1, quarantined: 0 });
|
||||
const warning = result.matches[0].warnings.find(
|
||||
({ code: warningCode }) =>
|
||||
warningCode === 'LEGACY_USED_CODE_TRANSITION_TIME_NORMALIZED',
|
||||
);
|
||||
expect(warning?.details).toMatchObject({
|
||||
legacyOccurrenceSource: 'riot-archive-gameCreation',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('quarantines an ambiguous Match without changing any legacy Match field', async () => {
|
||||
const match = ambiguousMatch();
|
||||
const before = canonical(match);
|
||||
|
||||
Reference in new issue
Block a user