mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 17:49:05 +03:00
refactor: enum casing (#19946)
This commit is contained in:
@@ -50,7 +50,7 @@ describe(MetadataService.name, () => {
|
||||
|
||||
mockReadTags();
|
||||
|
||||
mocks.config.getWorker.mockReturnValue(ImmichWorker.MICROSERVICES);
|
||||
mocks.config.getWorker.mockReturnValue(ImmichWorker.Microservices);
|
||||
|
||||
delete process.env.TZ;
|
||||
});
|
||||
@@ -102,11 +102,11 @@ describe(MetadataService.name, () => {
|
||||
it('should queue metadata extraction for all assets without exif values', async () => {
|
||||
mocks.assetJob.streamForMetadataExtraction.mockReturnValue(makeStream([assetStub.image]));
|
||||
|
||||
await expect(sut.handleQueueMetadataExtraction({ force: false })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleQueueMetadataExtraction({ force: false })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.assetJob.streamForMetadataExtraction).toHaveBeenCalledWith(false);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.METADATA_EXTRACTION,
|
||||
name: JobName.MetadataExtraction,
|
||||
data: { id: assetStub.image.id },
|
||||
},
|
||||
]);
|
||||
@@ -115,11 +115,11 @@ describe(MetadataService.name, () => {
|
||||
it('should queue metadata extraction for all assets', async () => {
|
||||
mocks.assetJob.streamForMetadataExtraction.mockReturnValue(makeStream([assetStub.image]));
|
||||
|
||||
await expect(sut.handleQueueMetadataExtraction({ force: true })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleQueueMetadataExtraction({ force: true })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.assetJob.streamForMetadataExtraction).toHaveBeenCalledWith(true);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.METADATA_EXTRACTION,
|
||||
name: JobName.MetadataExtraction,
|
||||
data: { id: assetStub.image.id },
|
||||
},
|
||||
]);
|
||||
@@ -506,7 +506,7 @@ describe(MetadataService.name, () => {
|
||||
it('should not apply motion photos if asset is video', async () => {
|
||||
mocks.assetJob.getForMetadataExtraction.mockResolvedValue({
|
||||
...assetStub.livePhotoMotionAsset,
|
||||
visibility: AssetVisibility.TIMELINE,
|
||||
visibility: AssetVisibility.Timeline,
|
||||
});
|
||||
mocks.media.probe.mockResolvedValue(probeStub.matroskaContainer);
|
||||
|
||||
@@ -516,7 +516,7 @@ describe(MetadataService.name, () => {
|
||||
expect(mocks.job.queue).not.toHaveBeenCalled();
|
||||
expect(mocks.job.queueAll).not.toHaveBeenCalled();
|
||||
expect(mocks.asset.update).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ assetType: AssetType.VIDEO, visibility: AssetVisibility.HIDDEN }),
|
||||
expect.objectContaining({ assetType: AssetType.Video, visibility: AssetVisibility.Hidden }),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -583,13 +583,13 @@ describe(MetadataService.name, () => {
|
||||
fileCreatedAt: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
fileModifiedAt: assetStub.livePhotoWithOriginalFileName.fileModifiedAt,
|
||||
id: fileStub.livePhotoMotion.uuid,
|
||||
visibility: AssetVisibility.HIDDEN,
|
||||
visibility: AssetVisibility.Hidden,
|
||||
libraryId: assetStub.livePhotoWithOriginalFileName.libraryId,
|
||||
localDateTime: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
originalFileName: 'asset_1.mp4',
|
||||
originalPath: 'upload/encoded-video/user-id/li/ve/live-photo-motion-asset-MP.mp4',
|
||||
ownerId: assetStub.livePhotoWithOriginalFileName.ownerId,
|
||||
type: AssetType.VIDEO,
|
||||
type: AssetType.Video,
|
||||
});
|
||||
expect(mocks.user.updateUsage).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.ownerId, 512);
|
||||
expect(mocks.storage.createFile).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.originalPath, video);
|
||||
@@ -599,7 +599,7 @@ describe(MetadataService.name, () => {
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledTimes(3);
|
||||
expect(mocks.job.queue).toHaveBeenCalledExactlyOnceWith({
|
||||
name: JobName.VIDEO_CONVERSION,
|
||||
name: JobName.VideoConversation,
|
||||
data: { id: assetStub.livePhotoMotionAsset.id },
|
||||
});
|
||||
});
|
||||
@@ -641,13 +641,13 @@ describe(MetadataService.name, () => {
|
||||
fileCreatedAt: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
fileModifiedAt: assetStub.livePhotoWithOriginalFileName.fileModifiedAt,
|
||||
id: fileStub.livePhotoMotion.uuid,
|
||||
visibility: AssetVisibility.HIDDEN,
|
||||
visibility: AssetVisibility.Hidden,
|
||||
libraryId: assetStub.livePhotoWithOriginalFileName.libraryId,
|
||||
localDateTime: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
originalFileName: 'asset_1.mp4',
|
||||
originalPath: 'upload/encoded-video/user-id/li/ve/live-photo-motion-asset-MP.mp4',
|
||||
ownerId: assetStub.livePhotoWithOriginalFileName.ownerId,
|
||||
type: AssetType.VIDEO,
|
||||
type: AssetType.Video,
|
||||
});
|
||||
expect(mocks.user.updateUsage).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.ownerId, 512);
|
||||
expect(mocks.storage.createFile).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.originalPath, video);
|
||||
@@ -657,7 +657,7 @@ describe(MetadataService.name, () => {
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledTimes(3);
|
||||
expect(mocks.job.queue).toHaveBeenCalledExactlyOnceWith({
|
||||
name: JobName.VIDEO_CONVERSION,
|
||||
name: JobName.VideoConversation,
|
||||
data: { id: assetStub.livePhotoMotionAsset.id },
|
||||
});
|
||||
});
|
||||
@@ -699,13 +699,13 @@ describe(MetadataService.name, () => {
|
||||
fileCreatedAt: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
fileModifiedAt: assetStub.livePhotoWithOriginalFileName.fileModifiedAt,
|
||||
id: fileStub.livePhotoMotion.uuid,
|
||||
visibility: AssetVisibility.HIDDEN,
|
||||
visibility: AssetVisibility.Hidden,
|
||||
libraryId: assetStub.livePhotoWithOriginalFileName.libraryId,
|
||||
localDateTime: assetStub.livePhotoWithOriginalFileName.fileCreatedAt,
|
||||
originalFileName: 'asset_1.mp4',
|
||||
originalPath: 'upload/encoded-video/user-id/li/ve/live-photo-motion-asset-MP.mp4',
|
||||
ownerId: assetStub.livePhotoWithOriginalFileName.ownerId,
|
||||
type: AssetType.VIDEO,
|
||||
type: AssetType.Video,
|
||||
});
|
||||
expect(mocks.user.updateUsage).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.ownerId, 512);
|
||||
expect(mocks.storage.createFile).toHaveBeenCalledWith(assetStub.livePhotoMotionAsset.originalPath, video);
|
||||
@@ -715,7 +715,7 @@ describe(MetadataService.name, () => {
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledTimes(3);
|
||||
expect(mocks.job.queue).toHaveBeenCalledExactlyOnceWith({
|
||||
name: JobName.VIDEO_CONVERSION,
|
||||
name: JobName.VideoConversation,
|
||||
data: { id: assetStub.livePhotoMotionAsset.id },
|
||||
});
|
||||
});
|
||||
@@ -737,7 +737,7 @@ describe(MetadataService.name, () => {
|
||||
|
||||
await sut.handleMetadataExtraction({ id: assetStub.livePhotoWithOriginalFileName.id });
|
||||
expect(mocks.job.queue).toHaveBeenNthCalledWith(1, {
|
||||
name: JobName.ASSET_DELETION,
|
||||
name: JobName.AssetDeletion,
|
||||
data: { id: assetStub.livePhotoWithOriginalFileName.livePhotoVideoId, deleteOnDisk: true },
|
||||
});
|
||||
});
|
||||
@@ -778,7 +778,7 @@ describe(MetadataService.name, () => {
|
||||
mocks.crypto.hashSha1.mockReturnValue(randomBytes(512));
|
||||
mocks.asset.getByChecksum.mockResolvedValue({
|
||||
...assetStub.livePhotoMotionAsset,
|
||||
visibility: AssetVisibility.TIMELINE,
|
||||
visibility: AssetVisibility.Timeline,
|
||||
});
|
||||
const video = randomBytes(512);
|
||||
mocks.storage.readFile.mockResolvedValue(video);
|
||||
@@ -786,7 +786,7 @@ describe(MetadataService.name, () => {
|
||||
await sut.handleMetadataExtraction({ id: assetStub.livePhotoStillAsset.id });
|
||||
expect(mocks.asset.update).toHaveBeenCalledWith({
|
||||
id: assetStub.livePhotoMotionAsset.id,
|
||||
visibility: AssetVisibility.HIDDEN,
|
||||
visibility: AssetVisibility.Hidden,
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledWith({
|
||||
id: assetStub.livePhotoStillAsset.id,
|
||||
@@ -1106,7 +1106,7 @@ describe(MetadataService.name, () => {
|
||||
boundingBoxX2: 200,
|
||||
boundingBoxY1: 20,
|
||||
boundingBoxY2: 60,
|
||||
sourceType: SourceType.EXIF,
|
||||
sourceType: SourceType.Exif,
|
||||
},
|
||||
],
|
||||
[],
|
||||
@@ -1116,7 +1116,7 @@ describe(MetadataService.name, () => {
|
||||
]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.GENERATE_PERSON_THUMBNAIL,
|
||||
name: JobName.GeneratePersonThumbnail,
|
||||
data: { id: personStub.withName.id },
|
||||
},
|
||||
]);
|
||||
@@ -1145,7 +1145,7 @@ describe(MetadataService.name, () => {
|
||||
boundingBoxX2: 200,
|
||||
boundingBoxY1: 20,
|
||||
boundingBoxY2: 60,
|
||||
sourceType: SourceType.EXIF,
|
||||
sourceType: SourceType.Exif,
|
||||
},
|
||||
],
|
||||
[],
|
||||
@@ -1234,7 +1234,7 @@ describe(MetadataService.name, () => {
|
||||
boundingBoxX2: x2,
|
||||
boundingBoxY1: y1,
|
||||
boundingBoxY2: y2,
|
||||
sourceType: SourceType.EXIF,
|
||||
sourceType: SourceType.Exif,
|
||||
},
|
||||
],
|
||||
[],
|
||||
@@ -1244,7 +1244,7 @@ describe(MetadataService.name, () => {
|
||||
]);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.GENERATE_PERSON_THUMBNAIL,
|
||||
name: JobName.GeneratePersonThumbnail,
|
||||
data: { id: personStub.withName.id },
|
||||
},
|
||||
]);
|
||||
@@ -1308,7 +1308,7 @@ describe(MetadataService.name, () => {
|
||||
expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id);
|
||||
expect(mocks.asset.findLivePhotoMatch).not.toHaveBeenCalled();
|
||||
expect(mocks.asset.update).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ visibility: AssetVisibility.HIDDEN }),
|
||||
expect.objectContaining({ visibility: AssetVisibility.Hidden }),
|
||||
);
|
||||
expect(mocks.album.removeAssetsFromAll).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -1326,10 +1326,10 @@ describe(MetadataService.name, () => {
|
||||
ownerId: assetStub.livePhotoMotionAsset.ownerId,
|
||||
otherAssetId: assetStub.livePhotoMotionAsset.id,
|
||||
libraryId: null,
|
||||
type: AssetType.IMAGE,
|
||||
type: AssetType.Image,
|
||||
});
|
||||
expect(mocks.asset.update).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ visibility: AssetVisibility.HIDDEN }),
|
||||
expect.objectContaining({ visibility: AssetVisibility.Hidden }),
|
||||
);
|
||||
expect(mocks.album.removeAssetsFromAll).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -1346,7 +1346,7 @@ describe(MetadataService.name, () => {
|
||||
livePhotoCID: 'CID',
|
||||
ownerId: assetStub.livePhotoStillAsset.ownerId,
|
||||
otherAssetId: assetStub.livePhotoStillAsset.id,
|
||||
type: AssetType.VIDEO,
|
||||
type: AssetType.Video,
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledWith({
|
||||
id: assetStub.livePhotoStillAsset.id,
|
||||
@@ -1354,7 +1354,7 @@ describe(MetadataService.name, () => {
|
||||
});
|
||||
expect(mocks.asset.update).toHaveBeenCalledWith({
|
||||
id: assetStub.livePhotoMotionAsset.id,
|
||||
visibility: AssetVisibility.HIDDEN,
|
||||
visibility: AssetVisibility.Hidden,
|
||||
});
|
||||
expect(mocks.album.removeAssetsFromAll).toHaveBeenCalledWith([assetStub.livePhotoMotionAsset.id]);
|
||||
});
|
||||
@@ -1457,7 +1457,7 @@ describe(MetadataService.name, () => {
|
||||
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.SIDECAR_SYNC,
|
||||
name: JobName.SidecarSync,
|
||||
data: { id: assetStub.sidecar.id },
|
||||
},
|
||||
]);
|
||||
@@ -1471,7 +1471,7 @@ describe(MetadataService.name, () => {
|
||||
expect(mocks.assetJob.streamForSidecar).toHaveBeenCalledWith(false);
|
||||
expect(mocks.job.queueAll).toHaveBeenCalledWith([
|
||||
{
|
||||
name: JobName.SIDECAR_DISCOVERY,
|
||||
name: JobName.SidecarDiscovery,
|
||||
data: { id: assetStub.image.id },
|
||||
},
|
||||
]);
|
||||
@@ -1481,13 +1481,13 @@ describe(MetadataService.name, () => {
|
||||
describe('handleSidecarSync', () => {
|
||||
it('should do nothing if asset could not be found', async () => {
|
||||
mocks.asset.getByIds.mockResolvedValue([]);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.image.id })).resolves.toBe(JobStatus.FAILED);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.image.id })).resolves.toBe(JobStatus.Failed);
|
||||
expect(mocks.asset.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should do nothing if asset has no sidecar path', async () => {
|
||||
mocks.asset.getByIds.mockResolvedValue([assetStub.image]);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.image.id })).resolves.toBe(JobStatus.FAILED);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.image.id })).resolves.toBe(JobStatus.Failed);
|
||||
expect(mocks.asset.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -1495,7 +1495,7 @@ describe(MetadataService.name, () => {
|
||||
mocks.asset.getByIds.mockResolvedValue([assetStub.sidecar]);
|
||||
mocks.storage.checkFileExists.mockResolvedValue(true);
|
||||
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.storage.checkFileExists).toHaveBeenCalledWith(
|
||||
`${assetStub.sidecar.originalPath}.xmp`,
|
||||
constants.R_OK,
|
||||
@@ -1511,7 +1511,7 @@ describe(MetadataService.name, () => {
|
||||
mocks.storage.checkFileExists.mockResolvedValueOnce(false);
|
||||
mocks.storage.checkFileExists.mockResolvedValueOnce(true);
|
||||
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecarWithoutExt.id })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecarWithoutExt.id })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.storage.checkFileExists).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
assetStub.sidecarWithoutExt.sidecarPath,
|
||||
@@ -1528,7 +1528,7 @@ describe(MetadataService.name, () => {
|
||||
mocks.storage.checkFileExists.mockResolvedValueOnce(true);
|
||||
mocks.storage.checkFileExists.mockResolvedValueOnce(true);
|
||||
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.storage.checkFileExists).toHaveBeenNthCalledWith(1, assetStub.sidecar.sidecarPath, constants.R_OK);
|
||||
expect(mocks.storage.checkFileExists).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
@@ -1545,7 +1545,7 @@ describe(MetadataService.name, () => {
|
||||
mocks.asset.getByIds.mockResolvedValue([assetStub.sidecar]);
|
||||
mocks.storage.checkFileExists.mockResolvedValue(false);
|
||||
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.SUCCESS);
|
||||
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.storage.checkFileExists).toHaveBeenCalledWith(
|
||||
`${assetStub.sidecar.originalPath}.xmp`,
|
||||
constants.R_OK,
|
||||
@@ -1603,14 +1603,14 @@ describe(MetadataService.name, () => {
|
||||
describe('handleSidecarWrite', () => {
|
||||
it('should skip assets that do not exist anymore', async () => {
|
||||
mocks.assetJob.getForSidecarWriteJob.mockResolvedValue(void 0);
|
||||
await expect(sut.handleSidecarWrite({ id: 'asset-123' })).resolves.toBe(JobStatus.FAILED);
|
||||
await expect(sut.handleSidecarWrite({ id: 'asset-123' })).resolves.toBe(JobStatus.Failed);
|
||||
expect(mocks.metadata.writeTags).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should skip jobs with no metadata', async () => {
|
||||
const asset = factory.jobAssets.sidecarWrite();
|
||||
mocks.assetJob.getForSidecarWriteJob.mockResolvedValue(asset);
|
||||
await expect(sut.handleSidecarWrite({ id: asset.id })).resolves.toBe(JobStatus.SKIPPED);
|
||||
await expect(sut.handleSidecarWrite({ id: asset.id })).resolves.toBe(JobStatus.Skipped);
|
||||
expect(mocks.metadata.writeTags).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -1629,7 +1629,7 @@ describe(MetadataService.name, () => {
|
||||
longitude: gps,
|
||||
dateTimeOriginal: date,
|
||||
}),
|
||||
).resolves.toBe(JobStatus.SUCCESS);
|
||||
).resolves.toBe(JobStatus.Success);
|
||||
expect(mocks.metadata.writeTags).toHaveBeenCalledWith(asset.sidecarPath, {
|
||||
Description: description,
|
||||
ImageDescription: description,
|
||||
|
||||
Reference in New Issue
Block a user