feat: add daily cron scheduler for price checks
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
const cronDefault = require('node-cron');
|
||||
|
||||
const SCHEDULE = '0 8 * * *';
|
||||
const TIMEZONE = 'Europe/Amsterdam';
|
||||
|
||||
function start(runCheck, { cron = cronDefault } = {}) {
|
||||
return cron.schedule(SCHEDULE, runCheck, { timezone: TIMEZONE });
|
||||
}
|
||||
|
||||
module.exports = { start, SCHEDULE, TIMEZONE };
|
||||
@@ -0,0 +1,21 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { start, SCHEDULE, TIMEZONE } = require('../src/scheduler');
|
||||
|
||||
test('start schedules the daily check with the expected cron expression and timezone', () => {
|
||||
const calls = [];
|
||||
const fakeCron = {
|
||||
schedule: (expression, fn, options) => {
|
||||
calls.push({ expression, fn, options });
|
||||
return { stop: () => {} };
|
||||
},
|
||||
};
|
||||
const runCheck = async () => {};
|
||||
start(runCheck, { cron: fakeCron });
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].expression, SCHEDULE);
|
||||
assert.equal(SCHEDULE, '0 8 * * *');
|
||||
assert.equal(calls[0].options.timezone, TIMEZONE);
|
||||
assert.equal(TIMEZONE, 'Europe/Amsterdam');
|
||||
assert.equal(calls[0].fn, runCheck);
|
||||
});
|
||||
Reference in New Issue
Block a user