From 5ea3e46bda12240a14e4fbc80cddf01539d27904 Mon Sep 17 00:00:00 2001 From: treydoe1 Date: Tue, 12 May 2026 17:17:12 -0400 Subject: [PATCH] add cron utility tests --- plugins/cron/utils.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 plugins/cron/utils.test.ts diff --git a/plugins/cron/utils.test.ts b/plugins/cron/utils.test.ts new file mode 100644 index 0000000..21c31f8 --- /dev/null +++ b/plugins/cron/utils.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from 'vitest' +import { getNextExecutionTime, parseCronExpression } from './utils' + +describe('cron utils', () => { + it('parses valid cron expressions', () => { + const interval = parseCronExpression('*/15 * * * *') + + expect(interval.next().getMinutes() % 15).toBe(0) + }) + + it('throws for invalid cron expressions', () => { + expect(() => parseCronExpression('not a cron')).toThrow() + }) + + it('returns the next execution time after the provided timestamp', () => { + const after = new Date(2026, 0, 1, 10, 30, 0).getTime() + + expect(getNextExecutionTime('0 11 * * *', after)).toBe( + new Date(2026, 0, 1, 11, 0, 0).getTime() + ) + }) + + it('rolls over to the next day when the scheduled time has passed', () => { + const after = new Date(2026, 0, 1, 11, 30, 0).getTime() + + expect(getNextExecutionTime('0 11 * * *', after)).toBe( + new Date(2026, 0, 2, 11, 0, 0).getTime() + ) + }) +})