fix: resume tournament result polling after delayed codes

This commit is contained in:
dahyeon committed 2026-06-25 04:58:10 -07:00
1 parent e50a683336
commit 2984bd1604
8 files changed
+207 -21

No files matched your search

@@ -4,6 +4,7 @@ import type { RiotMatchDto } from '../riot/riot.types';
import { TournamentResultService } from './tournament-result.service';
type TournamentResultServiceInternals = TournamentResultService & {
nextPollDelayMs(elapsedMs: number): number | null;
resolveRequiredGameSlots(match: MatchDocument): number;
resolveSeriesRefForGameNumber(
match: MatchDocument,
@@ -235,7 +236,7 @@ describe('TournamentResultService tournament code polling', () => {
{ buildAndUpsert: jest.fn().mockResolvedValue(undefined) } as never,
);
return { service, match, code };
return { service, match, code, riotMatchService };
}
it('matches Riot tournament codes using exact casing', async () => {
@@ -256,6 +257,23 @@ describe('TournamentResultService tournament code polling', () => {
expect(match.result?.games).toHaveLength(1);
});
it('limits expanded polling to two team members per team', async () => {
const { service, match, riotMatchService } = createPollFixture({
storedCode: 'AbC-12345',
riotTournamentCode: 'AbC-12345',
});
await service.processPollJob({
matchId: match._id.toString(),
attempt: 1,
expandedToAllPuuids: true,
});
expect(
riotMatchService.getMatchIdsByPuuid.mock.calls.map(([puuid]) => puuid),
).toEqual(['poll-puuid-1', 'poll-puuid-2', 'poll-puuid-6', 'poll-puuid-7']);
});
it('does not match tournament codes when casing differs', async () => {
const { service, match, code } = createPollFixture({
storedCode: 'ABC-12345',
@@ -275,6 +293,15 @@ describe('TournamentResultService tournament code polling', () => {
});
});
describe('TournamentResultService polling cadence', () => {
it('polls every two minutes during the first hour', () => {
const service = createService();
expect(service.nextPollDelayMs(0)).toBe(2 * 60_000);
expect(service.nextPollDelayMs(60 * 60_000)).toBe(2 * 60_000);
});
});
describe('TournamentResultService manual result collection', () => {
function createManualFixture() {
const communityId = new mongoose.Types.ObjectId();