fix: resume tournament result polling after delayed codes
This commit is contained in:
1 parent
e50a683336
commit
2984bd1604
8 files changed
+207
-21
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { TournamentCodeScheduler } from './tournament-code.scheduler';
|
||||
|
||||
describe('TournamentCodeScheduler', () => {
|
||||
function createScheduler(params?: {
|
||||
attachedMatches?: unknown[];
|
||||
scheduleInitialPoll?: jest.Mock;
|
||||
}) {
|
||||
const tournamentCodeService = {
|
||||
attachPendingMatchDocuments: jest
|
||||
.fn()
|
||||
.mockResolvedValue(params?.attachedMatches ?? []),
|
||||
markExpired: jest.fn().mockResolvedValue(0),
|
||||
};
|
||||
const autoProvisionService = {
|
||||
ensurePool: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const tournamentResultService = {
|
||||
scheduleInitialPoll:
|
||||
params?.scheduleInitialPoll ?? jest.fn().mockResolvedValue(null),
|
||||
};
|
||||
const scheduler = new TournamentCodeScheduler(
|
||||
tournamentCodeService as never,
|
||||
autoProvisionService as never,
|
||||
tournamentResultService as never,
|
||||
) as unknown as { attachPending(): Promise<void> };
|
||||
|
||||
return {
|
||||
scheduler,
|
||||
tournamentCodeService,
|
||||
tournamentResultService,
|
||||
};
|
||||
}
|
||||
|
||||
it('starts result polling after attaching delayed tournament codes', async () => {
|
||||
const attachedMatches = [{ _id: 'match-1' }, { _id: 'match-2' }];
|
||||
const { scheduler, tournamentResultService } = createScheduler({
|
||||
attachedMatches,
|
||||
});
|
||||
|
||||
await scheduler.attachPending();
|
||||
|
||||
expect(tournamentResultService.scheduleInitialPoll).toHaveBeenCalledTimes(
|
||||
2,
|
||||
);
|
||||
expect(tournamentResultService.scheduleInitialPoll).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
attachedMatches[0],
|
||||
);
|
||||
expect(tournamentResultService.scheduleInitialPoll).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
attachedMatches[1],
|
||||
);
|
||||
});
|
||||
|
||||
it('does not schedule result polling when no match received new codes', async () => {
|
||||
const { scheduler, tournamentResultService } = createScheduler();
|
||||
|
||||
await scheduler.attachPending();
|
||||
|
||||
expect(tournamentResultService.scheduleInitialPoll).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user