64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { addDays, Interval, set } from 'date-fns';
|
|
import { fromZonedTime } from 'date-fns-tz';
|
|
import { generateIntervalForTimeRange } from './helper';
|
|
|
|
describe('avicennaApiUtilHelper', () => {
|
|
describe('generateIntervalForTimeRange', () => {
|
|
it('should throw an error when the timeRange format is invalid', () => {
|
|
expect(() => generateIntervalForTimeRange('42:00;06:09')).toThrow();
|
|
});
|
|
it('should generate an interval for the specified time range on the current day', () => {
|
|
const result: Interval = {
|
|
start: fromZonedTime(
|
|
set(new Date(), {
|
|
hours: 12,
|
|
minutes: 0,
|
|
seconds: 0,
|
|
milliseconds: 0,
|
|
}),
|
|
'Europe/Berlin',
|
|
),
|
|
end: fromZonedTime(
|
|
set(new Date(), {
|
|
hours: 13,
|
|
minutes: 0,
|
|
seconds: 0,
|
|
milliseconds: 0,
|
|
}),
|
|
'Europe/Berlin',
|
|
),
|
|
};
|
|
|
|
expect(
|
|
generateIntervalForTimeRange('12:00-13:00', 'Europe/Berlin'),
|
|
).toStrictEqual(result);
|
|
});
|
|
it('should generate an interval which spans over two days, if the second time is lower than the first', () => {
|
|
const result: Interval = {
|
|
start: fromZonedTime(
|
|
set(new Date(), {
|
|
hours: 12,
|
|
minutes: 0,
|
|
seconds: 0,
|
|
milliseconds: 0,
|
|
}),
|
|
'Europe/Berlin',
|
|
),
|
|
end: fromZonedTime(
|
|
set(addDays(new Date(), 1), {
|
|
hours: 1,
|
|
minutes: 0,
|
|
seconds: 0,
|
|
milliseconds: 0,
|
|
}),
|
|
'Europe/Berlin',
|
|
),
|
|
};
|
|
|
|
expect(
|
|
generateIntervalForTimeRange('12:00-01:00', 'Europe/Berlin'),
|
|
).toStrictEqual(result);
|
|
});
|
|
});
|
|
});
|