mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): jobs and processors (#1787)
* refactor: jobs and processors * refactor: storage migration processor * fix: tests * fix: code warning * chore: ignore coverage from infra * fix: sync move asset logic between job core and asset core * refactor: move error handling inside of catch * refactor(server): job core into dedicated service calls * refactor: smart info * fix: tests * chore: smart info tests * refactor: use asset repository * refactor: thumbnail processor * chore: coverage reqs
This commit is contained in:
7
server/libs/domain/test/album.repository.mock.ts
Normal file
7
server/libs/domain/test/album.repository.mock.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { IAlbumRepository } from '../src';
|
||||
|
||||
export const newAlbumRepositoryMock = (): jest.Mocked<IAlbumRepository> => {
|
||||
return {
|
||||
deleteAll: jest.fn(),
|
||||
};
|
||||
};
|
||||
@@ -5,6 +5,7 @@ export const newKeyRepositoryMock = (): jest.Mocked<IKeyRepository> => {
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
deleteAll: jest.fn(),
|
||||
getKey: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
getByUserId: jest.fn(),
|
||||
|
||||
10
server/libs/domain/test/asset.repository.mock.ts
Normal file
10
server/libs/domain/test/asset.repository.mock.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IAssetRepository } from '../src';
|
||||
|
||||
export const newAssetRepositoryMock = (): jest.Mocked<IAssetRepository> => {
|
||||
return {
|
||||
getAll: jest.fn(),
|
||||
deleteAll: jest.fn(),
|
||||
save: jest.fn(),
|
||||
findLivePhotoMatch: jest.fn(),
|
||||
};
|
||||
};
|
||||
@@ -91,22 +91,37 @@ export const userEntityStub = {
|
||||
}),
|
||||
};
|
||||
|
||||
export const fileStub = {
|
||||
livePhotoStill: Object.freeze({
|
||||
originalPath: 'fake_path/asset_1.jpeg',
|
||||
mimeType: 'image/jpg',
|
||||
checksum: Buffer.from('file hash', 'utf8'),
|
||||
originalName: 'asset_1.jpeg',
|
||||
}),
|
||||
livePhotoMotion: Object.freeze({
|
||||
originalPath: 'fake_path/asset_1.mp4',
|
||||
mimeType: 'image/jpeg',
|
||||
checksum: Buffer.from('live photo file hash', 'utf8'),
|
||||
originalName: 'asset_1.mp4',
|
||||
}),
|
||||
};
|
||||
|
||||
export const assetEntityStub = {
|
||||
image: Object.freeze<AssetEntity>({
|
||||
id: 'asset-id',
|
||||
deviceAssetId: 'device-asset-id',
|
||||
fileModifiedAt: today.toISOString(),
|
||||
fileCreatedAt: today.toISOString(),
|
||||
fileModifiedAt: '2023-02-23T05:06:29.716Z',
|
||||
fileCreatedAt: '2023-02-23T05:06:29.716Z',
|
||||
owner: userEntityStub.user1,
|
||||
ownerId: 'user-id',
|
||||
deviceId: 'device-id',
|
||||
originalPath: '/original/path',
|
||||
originalPath: '/original/path.ext',
|
||||
resizePath: null,
|
||||
type: AssetType.IMAGE,
|
||||
webpPath: null,
|
||||
encodedVideoPath: null,
|
||||
createdAt: today.toISOString(),
|
||||
updatedAt: today.toISOString(),
|
||||
createdAt: '2023-02-23T05:06:29.716Z',
|
||||
updatedAt: '2023-02-23T05:06:29.716Z',
|
||||
mimeType: null,
|
||||
isFavorite: true,
|
||||
duration: null,
|
||||
@@ -116,6 +131,26 @@ export const assetEntityStub = {
|
||||
tags: [],
|
||||
sharedLinks: [],
|
||||
}),
|
||||
livePhotoMotionAsset: Object.freeze({
|
||||
id: 'live-photo-motion-asset',
|
||||
originalPath: fileStub.livePhotoMotion.originalPath,
|
||||
ownerId: authStub.user1.id,
|
||||
type: AssetType.VIDEO,
|
||||
isVisible: false,
|
||||
fileModifiedAt: '2022-06-19T23:41:36.910Z',
|
||||
fileCreatedAt: '2022-06-19T23:41:36.910Z',
|
||||
} as AssetEntity),
|
||||
|
||||
livePhotoStillAsset: Object.freeze({
|
||||
id: 'live-photo-still-asset',
|
||||
originalPath: fileStub.livePhotoStill.originalPath,
|
||||
ownerId: authStub.user1.id,
|
||||
type: AssetType.IMAGE,
|
||||
livePhotoVideoId: 'live-photo-motion-asset',
|
||||
isVisible: true,
|
||||
fileModifiedAt: '2022-06-19T23:41:36.910Z',
|
||||
fileCreatedAt: '2022-06-19T23:41:36.910Z',
|
||||
} as AssetEntity),
|
||||
};
|
||||
|
||||
const assetInfo: ExifResponseDto = {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
export * from './album.repository.mock';
|
||||
export * from './api-key.repository.mock';
|
||||
export * from './asset.repository.mock';
|
||||
export * from './crypto.repository.mock';
|
||||
export * from './device-info.repository.mock';
|
||||
export * from './fixtures';
|
||||
export * from './job.repository.mock';
|
||||
export * from './machine-learning.repository.mock';
|
||||
export * from './shared-link.repository.mock';
|
||||
export * from './smart-info.repository.mock';
|
||||
export * from './storage.repository.mock';
|
||||
export * from './system-config.repository.mock';
|
||||
export * from './user-token.repository.mock';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { IJobRepository } from '../src';
|
||||
export const newJobRepositoryMock = (): jest.Mocked<IJobRepository> => {
|
||||
return {
|
||||
empty: jest.fn(),
|
||||
add: jest.fn().mockImplementation(() => Promise.resolve()),
|
||||
queue: jest.fn().mockImplementation(() => Promise.resolve()),
|
||||
isActive: jest.fn(),
|
||||
getJobCounts: jest.fn(),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IMachineLearningRepository } from '../src';
|
||||
|
||||
export const newMachineLearningRepositoryMock = (): jest.Mocked<IMachineLearningRepository> => {
|
||||
return {
|
||||
tagImage: jest.fn(),
|
||||
detectObjects: jest.fn(),
|
||||
};
|
||||
};
|
||||
11
server/libs/domain/test/setup.ts
Normal file
11
server/libs/domain/test/setup.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
jest.mock('@nestjs/common', () => ({
|
||||
...jest.requireActual('@nestjs/common'),
|
||||
Logger: jest.fn().mockReturnValue({
|
||||
verbose: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
log: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
7
server/libs/domain/test/smart-info.repository.mock.ts
Normal file
7
server/libs/domain/test/smart-info.repository.mock.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ISmartInfoRepository } from '../src';
|
||||
|
||||
export const newSmartInfoRepositoryMock = (): jest.Mocked<ISmartInfoRepository> => {
|
||||
return {
|
||||
upsert: jest.fn(),
|
||||
};
|
||||
};
|
||||
@@ -3,5 +3,11 @@ import { IStorageRepository } from '../src';
|
||||
export const newStorageRepositoryMock = (): jest.Mocked<IStorageRepository> => {
|
||||
return {
|
||||
createReadStream: jest.fn(),
|
||||
unlink: jest.fn(),
|
||||
unlinkDir: jest.fn(),
|
||||
removeEmptyDirs: jest.fn(),
|
||||
moveFile: jest.fn(),
|
||||
checkFileExists: jest.fn(),
|
||||
mkdirSync: jest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ export const newUserTokenRepositoryMock = (): jest.Mocked<IUserTokenRepository>
|
||||
return {
|
||||
create: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
deleteAll: jest.fn(),
|
||||
get: jest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ export const newUserRepositoryMock = (): jest.Mocked<IUserRepository> => {
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
getDeletedUsers: jest.fn(),
|
||||
restore: jest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user