From 33c9ea1c9c65db2fc8c9f821d6e44ded9fd38f38 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:49:54 -0400 Subject: [PATCH] update tests --- .../src/services/asset-media.service.spec.ts | 4 ++-- server/src/services/asset.service.spec.ts | 19 +++++++++++++++++-- server/src/services/media.service.spec.ts | 18 ++++++++++++++++++ server/src/services/media.service.ts | 2 +- server/test/fixtures/asset.stub.ts | 12 +++++++++++- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/server/src/services/asset-media.service.spec.ts b/server/src/services/asset-media.service.spec.ts index 97736b905c..9499e788f4 100644 --- a/server/src/services/asset-media.service.spec.ts +++ b/server/src/services/asset-media.service.spec.ts @@ -584,7 +584,7 @@ describe(AssetMediaService.name, () => { sut.viewThumbnail(authStub.admin, assetStub.image.id, { size: AssetMediaSize.PREVIEW }), ).resolves.toEqual( new ImmichFileResponse({ - path: assetStub.image.files[0].path, + path: '/uploads/user-id/thumbs/path.jpg', cacheControl: CacheControl.PRIVATE_WITH_CACHE, contentType: 'image/jpeg', fileName: 'asset-id_preview.jpg', @@ -599,7 +599,7 @@ describe(AssetMediaService.name, () => { sut.viewThumbnail(authStub.admin, assetStub.image.id, { size: AssetMediaSize.THUMBNAIL }), ).resolves.toEqual( new ImmichFileResponse({ - path: assetStub.image.files[1].path, + path: '/uploads/user-id/webp/path.ext', cacheControl: CacheControl.PRIVATE_WITH_CACHE, contentType: 'application/octet-stream', fileName: 'asset-id_thumbnail.ext', diff --git a/server/src/services/asset.service.spec.ts b/server/src/services/asset.service.spec.ts index b977dd6d70..470f29fb3d 100755 --- a/server/src/services/asset.service.spec.ts +++ b/server/src/services/asset.service.spec.ts @@ -578,6 +578,7 @@ describe(AssetService.name, () => { files: [ '/uploads/user-id/webp/path.ext', '/uploads/user-id/thumbs/path.jpg', + '/uploads/user-id/fullsize/path.webp', assetWithFace.encodedVideoPath, assetWithFace.sidecarPath, assetWithFace.originalPath, @@ -637,7 +638,14 @@ describe(AssetService.name, () => { { name: JobName.DELETE_FILES, data: { - files: [undefined, undefined, undefined, undefined, 'fake_path/asset_1.jpeg'], + files: [ + '/uploads/user-id/webp/path.ext', + '/uploads/user-id/thumbs/path.jpg', + '/uploads/user-id/fullsize/path.webp', + undefined, + undefined, + 'fake_path/asset_1.jpeg', + ], }, }, ], @@ -658,7 +666,14 @@ describe(AssetService.name, () => { { name: JobName.DELETE_FILES, data: { - files: [undefined, undefined, undefined, undefined, 'fake_path/asset_1.jpeg'], + files: [ + '/uploads/user-id/webp/path.ext', + '/uploads/user-id/thumbs/path.jpg', + '/uploads/user-id/fullsize/path.webp', + undefined, + undefined, + 'fake_path/asset_1.jpeg', + ], }, }, ], diff --git a/server/src/services/media.service.spec.ts b/server/src/services/media.service.spec.ts index 354cf25b9d..a754fc47d0 100644 --- a/server/src/services/media.service.spec.ts +++ b/server/src/services/media.service.spec.ts @@ -234,6 +234,24 @@ describe(MediaService.name, () => { }); await expect(sut.handleAssetMigration({ id: assetStub.image.id })).resolves.toBe(JobStatus.SUCCESS); + expect(mocks.move.create).toHaveBeenCalledWith({ + entityId: assetStub.image.id, + pathType: AssetPathType.FULLSIZE, + oldPath: '/uploads/user-id/fullsize/path.webp', + newPath: 'upload/thumbs/user-id/as/se/asset-id-fullsize.jpeg', + }); + expect(mocks.move.create).toHaveBeenCalledWith({ + entityId: assetStub.image.id, + pathType: AssetPathType.PREVIEW, + oldPath: '/uploads/user-id/thumbs/path.jpg', + newPath: 'upload/thumbs/user-id/as/se/asset-id-preview.jpeg', + }); + expect(mocks.move.create).toHaveBeenCalledWith({ + entityId: assetStub.image.id, + pathType: AssetPathType.THUMBNAIL, + oldPath: '/uploads/user-id/webp/path.ext', + newPath: 'upload/thumbs/user-id/as/se/asset-id-thumbnail.webp', + }); expect(mocks.move.create).toHaveBeenCalledTimes(3); }); }); diff --git a/server/src/services/media.service.ts b/server/src/services/media.service.ts index 4e459db69a..5318cdc97f 100644 --- a/server/src/services/media.service.ts +++ b/server/src/services/media.service.ts @@ -140,7 +140,7 @@ export class MediaService extends BaseService { return JobStatus.FAILED; } - await this.storageCore.moveAssetImage(asset, AssetPathType.FULLSIZE, ImageFormat.JPEG); + await this.storageCore.moveAssetImage(asset, AssetPathType.FULLSIZE, image.fullsize.format); await this.storageCore.moveAssetImage(asset, AssetPathType.PREVIEW, image.preview.format); await this.storageCore.moveAssetImage(asset, AssetPathType.THUMBNAIL, image.thumbnail.format); await this.storageCore.moveAssetVideo(asset); diff --git a/server/test/fixtures/asset.stub.ts b/server/test/fixtures/asset.stub.ts index ce85da670f..d56c5f6efd 100644 --- a/server/test/fixtures/asset.stub.ts +++ b/server/test/fixtures/asset.stub.ts @@ -26,7 +26,16 @@ const thumbnailFile: AssetFileEntity = { updatedAt: new Date('2023-02-23T05:06:29.716Z'), }; -const files: AssetFileEntity[] = [previewFile, thumbnailFile]; +const fullsizeFile: AssetFileEntity = { + id: 'file-3', + assetId: 'asset-id', + type: AssetFileType.FULLSIZE, + path: '/uploads/user-id/fullsize/path.webp', + createdAt: new Date('2023-02-23T05:06:29.716Z'), + updatedAt: new Date('2023-02-23T05:06:29.716Z'), +}; + +const files: AssetFileEntity[] = [fullsizeFile, previewFile, thumbnailFile]; export const stackStub = (stackId: string, assets: AssetEntity[]): StackEntity => { return { @@ -553,6 +562,7 @@ export const assetStub = { fileSizeInByte: 25_000, timeZone: `America/New_York`, }, + files, } as AssetEntity), livePhotoWithOriginalFileName: Object.freeze({