mirror of
https://github.com/immich-app/immich.git
synced 2026-06-23 21:03:00 +08:00
Some checks are pending
CLI Build / Publish (push) Waiting to run
CLI Build / Docker (push) Blocked by required conditions
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker / Build and Push (., cpu, server/Dockerfile, immich-server, linux/amd64,linux/arm64) (push) Waiting to run
Docker / Build and Push (machine-learning, armnn, machine-learning/Dockerfile, immich-machine-learning, linux/arm64, -armnn) (push) Waiting to run
Docker / Build and Push (machine-learning, cpu, machine-learning/Dockerfile, immich-machine-learning, linux/amd64,linux/arm64) (push) Waiting to run
Docker / Build and Push (machine-learning, cuda, machine-learning/Dockerfile, immich-machine-learning, linux/amd64, -cuda) (push) Waiting to run
Docker / Build and Push (machine-learning, openvino, machine-learning/Dockerfile, immich-machine-learning, linux/amd64, -openvino) (push) Waiting to run
Static Code Analysis / Run Dart Code Analysis (push) Waiting to run
Test / Server (push) Waiting to run
Test / CLI (push) Waiting to run
Test / CLI (Windows) (push) Waiting to run
Test / Web (push) Waiting to run
Test / End-to-End Tests (push) Waiting to run
Test / Mobile (push) Waiting to run
Test / Machine Learning (push) Waiting to run
Test / ShellCheck (push) Waiting to run
Test / OpenAPI Clients (push) Waiting to run
Test / TypeORM Checks (push) Waiting to run
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { plainToInstance } from 'class-transformer';
|
|
import { validate } from 'class-validator';
|
|
import { DateTime } from 'luxon';
|
|
import { IsDateStringFormat, MaxDateString } from 'src/validation';
|
|
|
|
describe('Validation', () => {
|
|
describe('MaxDateString', () => {
|
|
const maxDate = DateTime.fromISO('2000-01-01', { zone: 'utc' });
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|