36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
|
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();
|
||
|
});
|
||
|
});
|