mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor!: migrate class-validator to zod (#26597)
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
||||
import { ExifResponseSchema } from 'src/dtos/exif.dto';
|
||||
import { AssetType, AssetVisibility } from 'src/enum';
|
||||
import { getExifCount, suggestDuplicate, suggestDuplicateKeepAssetIds } from 'src/utils/duplicate';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { z } from 'zod';
|
||||
|
||||
type ExifInfoInput = Partial<z.infer<typeof ExifResponseSchema>>;
|
||||
|
||||
const createAsset = (
|
||||
id: string,
|
||||
fileSizeInByte: number | null = null,
|
||||
exifFields: Record<string, unknown> = {},
|
||||
exifFields: ExifInfoInput = {},
|
||||
): AssetResponseDto => ({
|
||||
id,
|
||||
type: AssetType.Image,
|
||||
@@ -33,7 +37,9 @@ const createAsset = (
|
||||
visibility: AssetVisibility.Timeline,
|
||||
checksum: 'checksum',
|
||||
exifInfo:
|
||||
fileSizeInByte !== null || Object.keys(exifFields).length > 0 ? { fileSizeInByte, ...exifFields } : undefined,
|
||||
fileSizeInByte !== null || Object.keys(exifFields).length > 0
|
||||
? ExifResponseSchema.parse({ fileSizeInByte, ...exifFields })
|
||||
: undefined,
|
||||
});
|
||||
|
||||
describe('duplicate utils', () => {
|
||||
@@ -46,7 +52,7 @@ describe('duplicate utils', () => {
|
||||
|
||||
it('should return 0 for empty exifInfo', () => {
|
||||
const asset = createAsset('asset-1');
|
||||
asset.exifInfo = {};
|
||||
asset.exifInfo = ExifResponseSchema.parse({});
|
||||
expect(getExifCount(asset)).toBe(0);
|
||||
});
|
||||
|
||||
@@ -54,7 +60,7 @@ describe('duplicate utils', () => {
|
||||
const asset = createAsset('asset-1', 1000, {
|
||||
make: 'Canon',
|
||||
model: 'EOS 5D',
|
||||
dateTimeOriginal: new Date(),
|
||||
dateTimeOriginal: new Date().toISOString(),
|
||||
timeZone: 'UTC',
|
||||
latitude: 40.7128,
|
||||
longitude: -74.006,
|
||||
@@ -107,7 +113,7 @@ describe('duplicate utils', () => {
|
||||
const moreExif = createAsset('more-exif', 1000, {
|
||||
make: 'Canon',
|
||||
model: 'EOS 5D',
|
||||
dateTimeOriginal: new Date(),
|
||||
dateTimeOriginal: new Date().toISOString(),
|
||||
city: 'New York',
|
||||
});
|
||||
|
||||
@@ -125,7 +131,7 @@ describe('duplicate utils', () => {
|
||||
|
||||
it('should handle assets with exifInfo but no fileSizeInByte', () => {
|
||||
const noFileSize = createAsset('no-file-size');
|
||||
noFileSize.exifInfo = { make: 'Canon', model: 'EOS 5D' };
|
||||
noFileSize.exifInfo = ExifResponseSchema.parse({ make: 'Canon', model: 'EOS 5D' });
|
||||
const withFileSize = createAsset('with-file-size', 1000);
|
||||
|
||||
expect(suggestDuplicate([noFileSize, withFileSize])?.id).toBe('with-file-size');
|
||||
@@ -148,7 +154,7 @@ describe('duplicate utils', () => {
|
||||
const smallWithMoreExif = createAsset('small-more-exif', 1000, {
|
||||
make: 'Canon',
|
||||
model: 'EOS 5D',
|
||||
dateTimeOriginal: new Date(),
|
||||
dateTimeOriginal: new Date().toISOString(),
|
||||
city: 'New York',
|
||||
state: 'NY',
|
||||
country: 'USA',
|
||||
|
||||
Reference in New Issue
Block a user