63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
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();
|
|
});
|
|
});
|