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