matcher/src/modules/ad/tests/unit/domain/time-converter.spec.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-05-02 15:26:04 +00:00
import { TimeConverter } from '../../../domain/entities/time-converter';
describe('TimeConverter', () => {
it('should be defined', () => {
expect(new TimeConverter()).toBeDefined();
});
it('should convert a Europe/Paris datetime to utc datetime', () => {
expect(
TimeConverter.toUtcDatetime(
'2023-05-01',
'07:00',
'Europe/Paris',
).getUTCHours(),
).toBe(6);
});
it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid date, time or timezone', () => {
expect(
TimeConverter.toUtcDatetime(undefined, '07:00', 'Europe/Paris'),
).toBeUndefined();
expect(
TimeConverter.toUtcDatetime('2023-13-01', '07:00', 'Europe/Paris'),
).toBeUndefined();
expect(
TimeConverter.toUtcDatetime('2023-05-01', undefined, 'Europe/Paris'),
).toBeUndefined();
expect(
TimeConverter.toUtcDatetime('2023-05-01', 'a', 'Europe/Paris'),
).toBeUndefined();
expect(
TimeConverter.toUtcDatetime('2023-13-01', '07:00', 'OlympusMons/Mars'),
).toBeUndefined();
});
});