fix: normalize reused tournament code lifecycle
This commit is contained in:
1 parent
6b1c450752
commit
489d040d8f
3 files changed
+188
-21
No files matched your search
@@ -542,7 +542,10 @@ describe('planCompetitionMigration', () => {
|
||||
_id: 'used-code-by-slot',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
releasedAt: '2026-07-01T12:00:00.000Z',
|
||||
voidedAt: '2026-07-01T18:00:00.000Z',
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -550,6 +553,12 @@ describe('planCompetitionMigration', () => {
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments).toHaveLength(1);
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
state: 'used',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
});
|
||||
expect(plan.assignments[0]).not.toHaveProperty('releasedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('voidedAt');
|
||||
expect(plan.warnings).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -565,6 +574,7 @@ describe('planCompetitionMigration', () => {
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
releasedAt: '2026-07-04T00:00:00.000Z',
|
||||
voidedAt: '2026-07-03T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
@@ -578,6 +588,130 @@ describe('planCompetitionMigration', () => {
|
||||
voidedAt: '2026-07-03T00:00:00.000Z',
|
||||
}),
|
||||
);
|
||||
expect(plan.assignments[0]).not.toHaveProperty('releasedAt');
|
||||
});
|
||||
|
||||
it('ignores stale terminal timestamps from an earlier lifecycle when a code is reserved again', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-reused-reserved-code-timeline',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'reused-reserved-code',
|
||||
state: 'reserved',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-01T00:00:00.000Z',
|
||||
releasedAt: '2026-07-02T00:00:00.000Z',
|
||||
voidedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotMatchId: 'KR_STALE_RESERVED_LIFECYCLE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments).toContainEqual(
|
||||
expect.objectContaining({
|
||||
state: 'reserved',
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
}),
|
||||
);
|
||||
expect(plan.assignments[0]).not.toHaveProperty('usedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('releasedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('voidedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('riotMatchId');
|
||||
});
|
||||
|
||||
it('preserves only the applicable lifecycle for a released code', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-released-code-timeline',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'released-code-with-stale-terminal-fields',
|
||||
state: 'released',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-01T00:00:00.000Z',
|
||||
releasedAt: '2026-07-04T00:00:00.000Z',
|
||||
voidedAt: '2026-07-02T00:00:00.000Z',
|
||||
riotMatchId: 'KR_STALE_RELEASED_LIFECYCLE',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
state: 'released',
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
releasedAt: '2026-07-04T00:00:00.000Z',
|
||||
});
|
||||
expect(plan.assignments[0]).not.toHaveProperty('usedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('voidedAt');
|
||||
expect(plan.assignments[0]).not.toHaveProperty('riotMatchId');
|
||||
});
|
||||
|
||||
it('uses updatedAt as voidedAt for the production reversal document shape', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-voided-code-updated-at-fallback',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
result: { games: [], seriesResults: [] },
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'voided-code-updated-at-fallback',
|
||||
state: 'voided',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-01T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
updatedAt: '2026-07-03T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = requireReady(planCompetitionMigration(legacy));
|
||||
|
||||
expect(plan.assignments[0]).toMatchObject({
|
||||
state: 'voided',
|
||||
voidedAt: '2026-07-03T00:00:00.000Z',
|
||||
});
|
||||
});
|
||||
|
||||
it('still quarantines an inverted timestamp from the current lifecycle', () => {
|
||||
const legacy = pairedMatch({
|
||||
_id: 'match-inverted-current-code-timeline',
|
||||
gameCount: 1,
|
||||
gameSchedule: undefined,
|
||||
result: {
|
||||
games: [
|
||||
legacyGame({
|
||||
gameNumber: 1,
|
||||
riotMatchId: 'KR_INVERTED_CURRENT_TIMELINE',
|
||||
riotArchivePresent: true,
|
||||
}),
|
||||
],
|
||||
seriesResults: [],
|
||||
},
|
||||
tournamentCodes: [
|
||||
{
|
||||
_id: 'used-code-inverted-current-timeline',
|
||||
state: 'used',
|
||||
gameNumber: 1,
|
||||
reservedAt: '2026-07-03T00:00:00.000Z',
|
||||
usedAt: '2026-07-02T00:00:00.000Z',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const plan = planCompetitionMigration(legacy);
|
||||
|
||||
expectQuarantineReason(plan, 'INVALID_TOURNAMENT_CODE_TIMELINE');
|
||||
});
|
||||
|
||||
it('maps a result-less reserved TournamentCode by its global game number', () => {
|
||||
|
||||
Reference in new issue
Block a user