Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit d28b9b8

Browse files
author
b0dea
committed
improv: add some additional unit tests
1 parent 95312f4 commit d28b9b8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/unit/pulse.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,30 @@ describe('Test Pulse', () => {
254254
expect(updatedJob.attrs.nextRunAt).not.toBeNull();
255255
});
256256

257+
test('should compute nextRunAt after running a recurring job', async () => {
258+
let executionCount = 0;
259+
260+
globalPulseInstance.define('recurringJob', async () => {
261+
executionCount++;
262+
});
263+
264+
const job = globalPulseInstance.create('recurringJob', { key: 'value' });
265+
job.attrs.repeatInterval = '5 minutes';
266+
await job.save();
267+
268+
globalPulseInstance.processEvery('1 second');
269+
await globalPulseInstance.start();
270+
271+
await new Promise((resolve) => setTimeout(resolve, 4000));
272+
273+
const updatedJob = (await globalPulseInstance.jobs({ name: 'recurringJob' }))[0];
274+
275+
expect(executionCount).toBeGreaterThan(0);
276+
expect(updatedJob.attrs.lastRunAt).not.toBeNull();
277+
expect(updatedJob.attrs.nextRunAt).not.toBeNull();
278+
expect(updatedJob.attrs.nextRunAt?.getTime()).toBeGreaterThan(Date.now() - 100);
279+
});
280+
257281
test('should resume recurring jobs on restart - cron', async () => {
258282
const job = globalPulseInstance.create('sendEmail', { to: 'user@example.com' });
259283
job.attrs.repeatInterval = '*/5 * * * *';
@@ -457,6 +481,17 @@ describe('Test Pulse', () => {
457481
const now = new Date().getTime();
458482
expect(nextRunAt - now <= 0).toBe(true);
459483
});
484+
485+
test('should update nextRunAt after running a recurring job', async () => {
486+
const job = globalPulseInstance.create('recurringJob', { data: 'test' });
487+
job.attrs.repeatInterval = '*/5 * * * *';
488+
await job.save();
489+
490+
await job.run();
491+
492+
expect(job.attrs.nextRunAt).not.toBeNull();
493+
expect(job.attrs.nextRunAt?.getTime()).toBeGreaterThan(Date.now());
494+
});
460495
});
461496
describe('Test with array of names specified', () => {
462497
test('returns array of jobs', async () => {

0 commit comments

Comments
 (0)