mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(server): correct person birth date across timezones (#11369)
* fix(server): correct person birth date across timezones * fix test * update e2e tests * use Optional decorator
This commit is contained in:
parent
ebc71e428d
commit
434bcec5cc
7 changed files with 132 additions and 18 deletions
56
server/src/validation.spec.ts
Normal file
56
server/src/validation.spec.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { plainToInstance } from 'class-transformer';
|
||||
import { validate } from 'class-validator';
|
||||
import { IsDateStringFormat, MaxDateString } from 'src/validation';
|
||||
|
||||
describe('Validation', () => {
|
||||
describe('MaxDateString', () => {
|
||||
const maxDate = new Date(2000, 0, 1);
|
||||
|
||||
class MyDto {
|
||||
@MaxDateString(maxDate)
|
||||
date!: string;
|
||||
}
|
||||
|
||||
it('passes when date is before maxDate', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '1999-12-31' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('passes when date is equal to maxDate', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '2000-01-01' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('fails when date is after maxDate', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '2010-01-01' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('IsDateStringFormat', () => {
|
||||
class MyDto {
|
||||
@IsDateStringFormat('yyyy-MM-dd')
|
||||
date!: string;
|
||||
}
|
||||
|
||||
it('passes when date is valid', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '1999-12-31' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('fails when date has invalid format', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '2000-01-01T00:00:00Z' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(1);
|
||||
});
|
||||
|
||||
it('fails when empty string', async () => {
|
||||
const dto = plainToInstance(MyDto, { date: '' });
|
||||
await expect(validate(dto)).resolves.toHaveLength(1);
|
||||
});
|
||||
|
||||
it('fails when undefined', async () => {
|
||||
const dto = plainToInstance(MyDto, {});
|
||||
await expect(validate(dto)).resolves.toHaveLength(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue