0
I have a javascript class that contains a function which initializes a cron job. To perform cron-job I used the Node-Cron library. But I can’t find a way to test the class and function.
The variables that control Node-cron are in a .env. For the tests I’m using jest Job is launched when the application is lifted (the file containing the class is imported and the class is already exported instantiated)
.env file
#CRON JOB
FREQUENCY_CRON='30 00 * * *'
TIMEZONE="America/Sao_Paulo"
SCHEDULED=true
INACTIVE_EXPIRATION_TIME=2592000000 #30 DAYS
Cronjob.js
class CronJob {
constructor() {
this.startJob();
}
async startJob() {
cron.schedule(
process.env.FREQUENCY_CRON,
async () => {
//DO SOME DATA PROCESSING
},
{
scheduled: process.env.SCHEDULED,
timezone: process.env.TIMEZONE
}
);
}
}
export default new CronJob();