Skip to content

Commit

Permalink
Add test for listJobs
Browse files Browse the repository at this point in the history
  • Loading branch information
nwehrhan committed Dec 2, 2024
1 parent 5d13c7d commit 67dcd5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions packages/job-scheduler/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,43 @@ describe('defineJobScheduler', () => {
});
});

describe('listJobs', () => {
it('should list jobs that exist', async () => {
const minutes = 2;
const jobs_to_schedule = [
{
id: 'once',
type: 'once' as const,
date: Date.now() + 60e3,
execute: vi.fn(),
},
{
id: 'interval',
type: 'interval' as const,
duration: minutes * 60e3,
immediate: true,
execute: vi.fn(),
},
{
id: 'cron',
type: 'cron' as const,
expression: '0 0/2 * * *', // every 2 hours on the 0th minute of the hour
execute: vi.fn(),
},
];

const jobs = defineJobScheduler({ logger: null });

for (const job of jobs_to_schedule) {
await jobs.scheduleJob(job);
}

let allJobs = await jobs.listJobs();

expect(allJobs.length).toEqual(3);
});
});

describe('on', () => {
it('should call success listeners when a job finishes', async () => {
const result = Math.random();
Expand Down
2 changes: 1 addition & 1 deletion packages/job-scheduler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface JobScheduler {
/**
* List all the scheduled jobs.
*/
listJobs(): Promise<Alarms.Alarm>;
listJobs(): Promise<Record<Job['id'], Job>>;
}

/**
Expand Down

0 comments on commit 67dcd5d

Please sign in to comment.