1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-25 02:04:15 +02:00
pigallery2/test/common/unit/JobScheduleDTO.spec.ts

79 lines
2.4 KiB
TypeScript
Raw Normal View History

import {expect} from 'chai';
import {JobScheduleDTO, JobScheduleDTOUtils, JobTriggerType} from '../../../src/common/entities/job/JobScheduleDTO';
2019-12-27 01:24:56 +02:00
describe('JobScheduleDTO', () => {
it('should get date from schedule', async () => {
2021-05-22 14:47:35 +02:00
const refDate = new Date(Date.UTC(2019, 7, 18, 5, 10, 10, 0)); // its a sunday
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.scheduled,
time: (new Date(2019, 7, 18, 5, 10)).getTime()
}
} as any)).to.be.deep.equal((new Date(2019, 7, 18, 5, 10, 0)));
for (let dayOfWeek = 0; dayOfWeek < 7; ++dayOfWeek) {
let nextDay = dayOfWeek < 6 ? (18 + dayOfWeek + 1) : 18;
let h = 10;
let m = 5;
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.periodic,
2021-05-22 14:47:35 +02:00
atTime: (h * 60 + m),
periodicity: dayOfWeek
}
2021-05-22 14:47:35 +02:00
} as any)).to.be.deep.equal((new Date(Date.UTC(2019, 7, nextDay, h, m, 0))), 'for day: ' + dayOfWeek);
h = 2;
m = 5;
nextDay = 18 + dayOfWeek + 1;
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.periodic,
2021-05-22 14:47:35 +02:00
atTime: (h * 60 + m),
periodicity: dayOfWeek
}
2021-05-22 14:47:35 +02:00
} as any)).to.be.deep.equal((new Date(Date.UTC(2019, 7, nextDay, h, m, 0))), 'for day: ' + dayOfWeek);
h = 5;
m = 10;
nextDay = 18 + dayOfWeek + 1;
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.periodic,
2021-05-22 14:47:35 +02:00
atTime: (h * 60 + m),
periodicity: dayOfWeek
}
2021-05-22 14:47:35 +02:00
} as any)).to.be.deep.equal((new Date(Date.UTC(2019, 7, nextDay, h, m, 0))), 'for day: ' + dayOfWeek);
}
{
const h = 10;
const m = 5;
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.periodic,
2021-05-22 14:47:35 +02:00
atTime: (h * 60 + m),
periodicity: 7
}
2021-05-22 14:47:35 +02:00
} as any)).to.be.deep.equal((new Date(Date.UTC(2019, 7, 18, h, m, 0))));
}
{
const h = 2;
const m = 5;
expect(JobScheduleDTOUtils.getNextRunningDate(refDate, {
trigger: {
2019-12-24 13:22:25 +02:00
type: JobTriggerType.periodic,
2021-05-22 14:47:35 +02:00
atTime: (h * 60 + m),
periodicity: 7
}
2021-05-22 14:47:35 +02:00
} as any)).to.be.deep.equal((new Date(Date.UTC(2019, 7, 19, h, m, 0))));
}
});
});