54 lines
1.5 KiB
TypeScript
54 lines
1.5 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(
|
|
new Date('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', () => {
|
|
expect(
|
|
TimeConverter.toUtcDatetime(undefined, '07:00', 'Europe/Paris'),
|
|
).toBeUndefined();
|
|
expect(
|
|
TimeConverter.toUtcDatetime(
|
|
new Date('2023-13-01'),
|
|
'07:00',
|
|
'Europe/Paris',
|
|
),
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined when trying to convert a Europe/Paris datetime to utc datetime without a valid time', () => {
|
|
expect(
|
|
TimeConverter.toUtcDatetime(
|
|
new Date('2023-05-01'),
|
|
undefined,
|
|
'Europe/Paris',
|
|
),
|
|
).toBeUndefined();
|
|
expect(
|
|
TimeConverter.toUtcDatetime(new Date('2023-05-01'), 'a', 'Europe/Paris'),
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined when trying to convert a datetime to utc datetime without a valid timezone', () => {
|
|
expect(
|
|
TimeConverter.toUtcDatetime(
|
|
new Date('2023-12-01'),
|
|
'07:00',
|
|
'OlympusMons/Mars',
|
|
),
|
|
).toBeUndefined();
|
|
});
|
|
});
|