mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-01-11 17:12:39 +00:00
move tests folder to the root
This commit is contained in:
52
tests/unit/ad/infrastructure/ad.repository.spec.ts
Normal file
52
tests/unit/ad/infrastructure/ad.repository.spec.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { OUTPUT_DATETIME_TRANSFORMER } from '@modules/ad/ad.di-tokens';
|
||||
import { AdMapper } from '@modules/ad/ad.mapper';
|
||||
import { DateTimeTransformerPort } from '@modules/ad/core/application/ports/datetime-transformer.port';
|
||||
import { AdRepository } from '@modules/ad/infrastructure/ad.repository';
|
||||
import { PrismaService } from '@modules/ad/infrastructure/prisma.service';
|
||||
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const mockMessagePublisher = {
|
||||
publish: jest.fn().mockImplementation(),
|
||||
};
|
||||
|
||||
const mockOutputDatetimeTransformer: DateTimeTransformerPort = {
|
||||
fromDate: jest.fn(),
|
||||
toDate: jest.fn(),
|
||||
day: jest.fn(),
|
||||
time: jest.fn(),
|
||||
};
|
||||
|
||||
describe('Ad repository', () => {
|
||||
let prismaService: PrismaService;
|
||||
let adMapper: AdMapper;
|
||||
let eventEmitter: EventEmitter2;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [EventEmitterModule.forRoot()],
|
||||
providers: [
|
||||
PrismaService,
|
||||
AdMapper,
|
||||
{
|
||||
provide: OUTPUT_DATETIME_TRANSFORMER,
|
||||
useValue: mockOutputDatetimeTransformer,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
prismaService = module.get<PrismaService>(PrismaService);
|
||||
adMapper = module.get<AdMapper>(AdMapper);
|
||||
eventEmitter = module.get<EventEmitter2>(EventEmitter2);
|
||||
});
|
||||
it('should be defined', () => {
|
||||
expect(
|
||||
new AdRepository(
|
||||
prismaService,
|
||||
adMapper,
|
||||
eventEmitter,
|
||||
mockMessagePublisher,
|
||||
),
|
||||
).toBeDefined();
|
||||
});
|
||||
});
|
||||
248
tests/unit/ad/infrastructure/input-datetime-transformer.spec.ts
Normal file
248
tests/unit/ad/infrastructure/input-datetime-transformer.spec.ts
Normal file
@@ -0,0 +1,248 @@
|
||||
import { TIMEZONE_FINDER, TIME_CONVERTER } from '@modules/ad/ad.di-tokens';
|
||||
import { Frequency } from '@modules/ad/core/application/ports/datetime-transformer.port';
|
||||
import { TimeConverterPort } from '@modules/ad/core/application/ports/time-converter.port';
|
||||
import { TimezoneFinderPort } from '@modules/ad/core/application/ports/timezone-finder.port';
|
||||
import { InputDateTimeTransformer } from '@modules/ad/infrastructure/input-datetime-transformer';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const mockTimezoneFinder: TimezoneFinderPort = {
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter: TimeConverterPort = {
|
||||
localStringTimeToUtcStringTime: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => '00:15'),
|
||||
utcStringTimeToLocalStringTime: jest.fn(),
|
||||
localStringDateTimeToUtcDate: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => new Date('2023-07-30T06:15:00.000Z'))
|
||||
.mockImplementationOnce(() => new Date('2023-07-20T08:15:00.000Z'))
|
||||
.mockImplementationOnce(() => new Date('2023-07-19T23:15:00.000Z'))
|
||||
.mockImplementationOnce(() => new Date('2023-07-19T23:15:00.000Z')),
|
||||
utcStringDateTimeToLocalIsoString: jest.fn(),
|
||||
utcUnixEpochDayFromTime: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => 4)
|
||||
.mockImplementationOnce(() => 3)
|
||||
.mockImplementationOnce(() => 3)
|
||||
.mockImplementationOnce(() => 5)
|
||||
.mockImplementationOnce(() => 5),
|
||||
localUnixEpochDayFromTime: jest.fn(),
|
||||
};
|
||||
|
||||
describe('Input Datetime Transformer', () => {
|
||||
let inputDatetimeTransformer: InputDateTimeTransformer;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
{
|
||||
provide: TIMEZONE_FINDER,
|
||||
useValue: mockTimezoneFinder,
|
||||
},
|
||||
{
|
||||
provide: TIME_CONVERTER,
|
||||
useValue: mockTimeConverter,
|
||||
},
|
||||
InputDateTimeTransformer,
|
||||
],
|
||||
}).compile();
|
||||
|
||||
inputDatetimeTransformer = module.get<InputDateTimeTransformer>(
|
||||
InputDateTimeTransformer,
|
||||
);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(inputDatetimeTransformer).toBeDefined();
|
||||
});
|
||||
|
||||
describe('fromDate', () => {
|
||||
it('should return fromDate as is if frequency is recurrent', () => {
|
||||
const transformedFromDate: string = inputDatetimeTransformer.fromDate(
|
||||
{
|
||||
date: '2023-07-30',
|
||||
time: '07:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(transformedFromDate).toBe('2023-07-30');
|
||||
});
|
||||
it('should return transformed fromDate if frequency is punctual and coordinates are those of Nancy', () => {
|
||||
const transformedFromDate: string = inputDatetimeTransformer.fromDate(
|
||||
{
|
||||
date: '2023-07-30',
|
||||
time: '07:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(transformedFromDate).toBe('2023-07-30');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toDate', () => {
|
||||
it('should return toDate as is if frequency is recurrent', () => {
|
||||
const transformedToDate: string = inputDatetimeTransformer.toDate(
|
||||
'2024-07-29',
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '10:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(transformedToDate).toBe('2024-07-29');
|
||||
});
|
||||
it('should return transformed fromDate if frequency is punctual', () => {
|
||||
const transformedToDate: string = inputDatetimeTransformer.toDate(
|
||||
'2024-07-30',
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '10:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(transformedToDate).toBe('2023-07-20');
|
||||
});
|
||||
});
|
||||
|
||||
describe('day', () => {
|
||||
it('should not change day if frequency is recurrent and converted UTC time is on the same day', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '01:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(1);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted UTC time is on the previous day', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(0);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted UTC time is on the previous day and given day is sunday', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
0,
|
||||
{
|
||||
date: '2023-07-23',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(6);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted UTC time is on the next day', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 30.82,
|
||||
lat: 49.37,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(2);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted UTC time is on the next day and given day is saturday(6)', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
6,
|
||||
{
|
||||
date: '2023-07-29',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 30.82,
|
||||
lat: 49.37,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(0);
|
||||
});
|
||||
it('should return utc fromDate day if frequency is punctual', () => {
|
||||
const day: number = inputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(day).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('time', () => {
|
||||
it('should transform given time to utc time if frequency is recurrent', () => {
|
||||
const time: string = inputDatetimeTransformer.time(
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '01:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(time).toBe('00:15');
|
||||
});
|
||||
it('should return given time to utc time if frequency is punctual', () => {
|
||||
const time: string = inputDatetimeTransformer.time(
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '01:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(time).toBe('23:15');
|
||||
});
|
||||
});
|
||||
});
|
||||
248
tests/unit/ad/infrastructure/output-datetime-transformer.spec.ts
Normal file
248
tests/unit/ad/infrastructure/output-datetime-transformer.spec.ts
Normal file
@@ -0,0 +1,248 @@
|
||||
import { TIMEZONE_FINDER, TIME_CONVERTER } from '@modules/ad/ad.di-tokens';
|
||||
import { Frequency } from '@modules/ad/core/application/ports/datetime-transformer.port';
|
||||
import { TimeConverterPort } from '@modules/ad/core/application/ports/time-converter.port';
|
||||
import { TimezoneFinderPort } from '@modules/ad/core/application/ports/timezone-finder.port';
|
||||
import { OutputDateTimeTransformer } from '@modules/ad/infrastructure/output-datetime-transformer';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const mockTimezoneFinder: TimezoneFinderPort = {
|
||||
timezones: jest.fn().mockImplementation(() => ['Europe/Paris']),
|
||||
};
|
||||
|
||||
const mockTimeConverter: TimeConverterPort = {
|
||||
localStringTimeToUtcStringTime: jest.fn(),
|
||||
utcStringTimeToLocalStringTime: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => '00:15'),
|
||||
localStringDateTimeToUtcDate: jest.fn(),
|
||||
utcStringDateTimeToLocalIsoString: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => '2023-07-30T08:15:00.000+02:00')
|
||||
.mockImplementationOnce(() => '2023-07-20T10:15:00.000+02:00')
|
||||
.mockImplementationOnce(() => '2023-07-19T23:15:00.000+02:00')
|
||||
.mockImplementationOnce(() => '2023-07-20T00:15:00.000+02:00'),
|
||||
utcUnixEpochDayFromTime: jest.fn(),
|
||||
localUnixEpochDayFromTime: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => 4)
|
||||
.mockImplementationOnce(() => 5)
|
||||
.mockImplementationOnce(() => 5)
|
||||
.mockImplementationOnce(() => 3)
|
||||
.mockImplementationOnce(() => 3),
|
||||
};
|
||||
|
||||
describe('Output Datetime Transformer', () => {
|
||||
let outputDatetimeTransformer: OutputDateTimeTransformer;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
{
|
||||
provide: TIMEZONE_FINDER,
|
||||
useValue: mockTimezoneFinder,
|
||||
},
|
||||
{
|
||||
provide: TIME_CONVERTER,
|
||||
useValue: mockTimeConverter,
|
||||
},
|
||||
OutputDateTimeTransformer,
|
||||
],
|
||||
}).compile();
|
||||
|
||||
outputDatetimeTransformer = module.get<OutputDateTimeTransformer>(
|
||||
OutputDateTimeTransformer,
|
||||
);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(outputDatetimeTransformer).toBeDefined();
|
||||
});
|
||||
|
||||
describe('fromDate', () => {
|
||||
it('should return fromDate as is if frequency is recurrent', () => {
|
||||
const transformedFromDate: string = outputDatetimeTransformer.fromDate(
|
||||
{
|
||||
date: '2023-07-30',
|
||||
time: '07:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(transformedFromDate).toBe('2023-07-30');
|
||||
});
|
||||
it('should return transformed fromDate if frequency is punctual and coordinates are those of Nancy', () => {
|
||||
const transformedFromDate: string = outputDatetimeTransformer.fromDate(
|
||||
{
|
||||
date: '2023-07-30',
|
||||
time: '07:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(transformedFromDate).toBe('2023-07-30');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toDate', () => {
|
||||
it('should return toDate as is if frequency is recurrent', () => {
|
||||
const transformedToDate: string = outputDatetimeTransformer.toDate(
|
||||
'2024-07-29',
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '10:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(transformedToDate).toBe('2024-07-29');
|
||||
});
|
||||
it('should return transformed fromDate if frequency is punctual', () => {
|
||||
const transformedToDate: string = outputDatetimeTransformer.toDate(
|
||||
'2024-07-30',
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '08:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(transformedToDate).toBe('2023-07-20');
|
||||
});
|
||||
});
|
||||
|
||||
describe('day', () => {
|
||||
it('should not change day if frequency is recurrent and converted local time is on the same day', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-24',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(1);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted local time is on the next day', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
0,
|
||||
{
|
||||
date: '2023-07-23',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(1);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted local time is on the next day and given day is saturday', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
6,
|
||||
{
|
||||
date: '2023-07-23',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(0);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted local time is on the previous day', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-25',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 30.82,
|
||||
lat: 49.37,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(0);
|
||||
});
|
||||
it('should change day if frequency is recurrent and converted local time is on the previous day and given day is sunday(0)', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
0,
|
||||
{
|
||||
date: '2023-07-30',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 30.82,
|
||||
lat: 49.37,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(day).toBe(6);
|
||||
});
|
||||
it('should return local fromDate day if frequency is punctual', () => {
|
||||
const day: number = outputDatetimeTransformer.day(
|
||||
1,
|
||||
{
|
||||
date: '2023-07-20',
|
||||
time: '00:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(day).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('time', () => {
|
||||
it('should transform utc time to local time if frequency is recurrent', () => {
|
||||
const time: string = outputDatetimeTransformer.time(
|
||||
{
|
||||
date: '2023-07-23',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.RECURRENT,
|
||||
);
|
||||
expect(time).toBe('00:15');
|
||||
});
|
||||
it('should return local time if frequency is punctual', () => {
|
||||
const time: string = outputDatetimeTransformer.time(
|
||||
{
|
||||
date: '2023-07-19',
|
||||
time: '23:15',
|
||||
coordinates: {
|
||||
lon: 6.175,
|
||||
lat: 48.685,
|
||||
},
|
||||
},
|
||||
Frequency.PUNCTUAL,
|
||||
);
|
||||
expect(time).toBe('00:15');
|
||||
});
|
||||
});
|
||||
});
|
||||
311
tests/unit/ad/infrastructure/time-converter.spec.ts
Normal file
311
tests/unit/ad/infrastructure/time-converter.spec.ts
Normal file
@@ -0,0 +1,311 @@
|
||||
import { TimeConverter } from '@modules/ad/infrastructure/time-converter';
|
||||
|
||||
describe('Time Converter', () => {
|
||||
it('should be defined', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(timeConverter).toBeDefined();
|
||||
});
|
||||
|
||||
describe('localStringTimeToUtcStringTime', () => {
|
||||
it('should convert a paris time to utc time', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisTime = '08:00';
|
||||
const utcDatetime = timeConverter.localStringTimeToUtcStringTime(
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
expect(utcDatetime).toBe('07:00');
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const fooBarTime = '08:00';
|
||||
expect(() => {
|
||||
timeConverter.localStringTimeToUtcStringTime(fooBarTime, 'Foo/Bar');
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('utcStringTimeToLocalStringTime', () => {
|
||||
it('should convert a utc time to a paris time', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcTime = '07:00';
|
||||
const parisTime = timeConverter.utcStringTimeToLocalStringTime(
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
expect(parisTime).toBe('08:00');
|
||||
});
|
||||
it('should throw an error if time is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcTime = '27:00';
|
||||
expect(() => {
|
||||
timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Europe/Paris');
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcTime = '07:00';
|
||||
expect(() => {
|
||||
timeConverter.utcStringTimeToLocalStringTime(utcTime, 'Foo/Bar');
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('localStringDateTimeToUtcDate', () => {
|
||||
it('should convert a summer paris date and time to a utc date with dst', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-06-22';
|
||||
const parisTime = '12:00';
|
||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
true,
|
||||
);
|
||||
expect(utcDate.toISOString()).toBe('2023-06-22T10:00:00.000Z');
|
||||
});
|
||||
it('should convert a winter paris date and time to a utc date with dst', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-02-02';
|
||||
const parisTime = '12:00';
|
||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
true,
|
||||
);
|
||||
expect(utcDate.toISOString()).toBe('2023-02-02T11:00:00.000Z');
|
||||
});
|
||||
it('should convert a summer paris date and time to a utc date without dst', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-06-22';
|
||||
const parisTime = '12:00';
|
||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
expect(utcDate.toISOString()).toBe('2023-06-22T11:00:00.000Z');
|
||||
});
|
||||
it('should convert a tonga date and time to a utc date', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const tongaDate = '2023-02-02';
|
||||
const tongaTime = '12:00';
|
||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
||||
tongaDate,
|
||||
tongaTime,
|
||||
'Pacific/Tongatapu',
|
||||
);
|
||||
expect(utcDate.toISOString()).toBe('2023-02-01T23:00:00.000Z');
|
||||
});
|
||||
it('should convert a papeete date and time to a utc date', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const papeeteDate = '2023-02-02';
|
||||
const papeeteTime = '15:00';
|
||||
const utcDate = timeConverter.localStringDateTimeToUtcDate(
|
||||
papeeteDate,
|
||||
papeeteTime,
|
||||
'Pacific/Tahiti',
|
||||
);
|
||||
expect(utcDate.toISOString()).toBe('2023-02-03T01:00:00.000Z');
|
||||
});
|
||||
it('should throw an error if date is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-06-32';
|
||||
const parisTime = '08:00';
|
||||
expect(() => {
|
||||
timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if time is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-06-22';
|
||||
const parisTime = '28:00';
|
||||
expect(() => {
|
||||
timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const parisDate = '2023-06-22';
|
||||
const parisTime = '12:00';
|
||||
expect(() => {
|
||||
timeConverter.localStringDateTimeToUtcDate(
|
||||
parisDate,
|
||||
parisTime,
|
||||
'Foo/Bar',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('utcStringDateTimeToLocalIsoString', () => {
|
||||
it('should convert a utc string date and time to a summer paris date isostring with dst', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-06-22';
|
||||
const utcTime = '10:00';
|
||||
const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
true,
|
||||
);
|
||||
expect(localIsoString).toBe('2023-06-22T12:00:00.000+02:00');
|
||||
});
|
||||
it('should convert a utc string date and time to a winter paris date isostring with dst', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-02-02';
|
||||
const utcTime = '10:00';
|
||||
const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
true,
|
||||
);
|
||||
expect(localIsoString).toBe('2023-02-02T11:00:00.000+01:00');
|
||||
});
|
||||
it('should convert a utc string date and time to a summer paris date isostring', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-06-22';
|
||||
const utcTime = '10:00';
|
||||
const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
expect(localIsoString).toBe('2023-06-22T11:00:00.000+01:00');
|
||||
});
|
||||
it('should convert a utc date to a tonga date isostring', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-02-01';
|
||||
const utcTime = '23:00';
|
||||
const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Pacific/Tongatapu',
|
||||
);
|
||||
expect(localIsoString).toBe('2023-02-02T12:00:00.000+13:00');
|
||||
});
|
||||
it('should convert a utc date to a papeete date isostring', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-02-03';
|
||||
const utcTime = '01:00';
|
||||
const localIsoString = timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Pacific/Tahiti',
|
||||
);
|
||||
expect(localIsoString).toBe('2023-02-02T15:00:00.000-10:00');
|
||||
});
|
||||
it('should throw an error if date is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-06-32';
|
||||
const utcTime = '07:00';
|
||||
expect(() => {
|
||||
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if time is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-06-22';
|
||||
const utcTime = '27:00';
|
||||
expect(() => {
|
||||
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Europe/Paris',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
const utcDate = '2023-06-22';
|
||||
const utcTime = '07:00';
|
||||
expect(() => {
|
||||
timeConverter.utcStringDateTimeToLocalIsoString(
|
||||
utcDate,
|
||||
utcTime,
|
||||
'Foo/Bar',
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('utcUnixEpochDayFromTime', () => {
|
||||
it('should get the utc day of paris at 12:00', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.utcUnixEpochDayFromTime('12:00', 'Europe/Paris'),
|
||||
).toBe(4);
|
||||
});
|
||||
it('should get the utc day of paris at 00:00', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.utcUnixEpochDayFromTime('00:00', 'Europe/Paris'),
|
||||
).toBe(3);
|
||||
});
|
||||
it('should get the utc day of papeete at 16:00', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.utcUnixEpochDayFromTime('16:00', 'Pacific/Tahiti'),
|
||||
).toBe(5);
|
||||
});
|
||||
it('should throw an error if time is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(() => {
|
||||
timeConverter.utcUnixEpochDayFromTime('28:00', 'Europe/Paris');
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(() => {
|
||||
timeConverter.utcUnixEpochDayFromTime('12:00', 'Foo/Bar');
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('localUnixEpochDayFromTime', () => {
|
||||
it('should get the day of paris at 12:00 utc', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.localUnixEpochDayFromTime('12:00', 'Europe/Paris'),
|
||||
).toBe(4);
|
||||
});
|
||||
it('should get the day of paris at 23:00 utc', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.localUnixEpochDayFromTime('23:00', 'Europe/Paris'),
|
||||
).toBe(5);
|
||||
});
|
||||
it('should get the day of papeete at 05:00 utc', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(
|
||||
timeConverter.localUnixEpochDayFromTime('05:00', 'Pacific/Tahiti'),
|
||||
).toBe(3);
|
||||
});
|
||||
it('should throw an error if time is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(() => {
|
||||
timeConverter.localUnixEpochDayFromTime('28:00', 'Europe/Paris');
|
||||
}).toThrow();
|
||||
});
|
||||
it('should throw an error if timezone is invalid', () => {
|
||||
const timeConverter: TimeConverter = new TimeConverter();
|
||||
expect(() => {
|
||||
timeConverter.localUnixEpochDayFromTime('12:00', 'Foo/Bar');
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
14
tests/unit/ad/infrastructure/timezone-finder.spec.ts
Normal file
14
tests/unit/ad/infrastructure/timezone-finder.spec.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { TimezoneFinder } from '@modules/ad/infrastructure/timezone-finder';
|
||||
|
||||
describe('Timezone Finder', () => {
|
||||
it('should be defined', () => {
|
||||
const timezoneFinder: TimezoneFinder = new TimezoneFinder();
|
||||
expect(timezoneFinder).toBeDefined();
|
||||
});
|
||||
it('should get timezone for Nancy(France) as Europe/Paris', () => {
|
||||
const timezoneFinder: TimezoneFinder = new TimezoneFinder();
|
||||
const timezones = timezoneFinder.timezones(6.179373, 48.687913);
|
||||
expect(timezones.length).toBe(1);
|
||||
expect(timezones[0]).toBe('Europe/Paris');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user