mirror of
https://github.com/immich-app/immich.git
synced 2025-12-24 03:59:04 -08:00
refactor: memory stub (#16704)
This commit is contained in:
34
server/test/fixtures/memory.stub.ts
vendored
34
server/test/fixtures/memory.stub.ts
vendored
@@ -1,34 +0,0 @@
|
||||
import { MemoryType } from 'src/enum';
|
||||
import { assetStub } from 'test/fixtures/asset.stub';
|
||||
import { userStub } from 'test/fixtures/user.stub';
|
||||
|
||||
export const memoryStub = {
|
||||
empty: {
|
||||
id: 'memoryEmpty',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
memoryAt: new Date(2024),
|
||||
ownerId: userStub.admin.id,
|
||||
owner: userStub.admin,
|
||||
type: MemoryType.ON_THIS_DAY,
|
||||
data: { year: 2024 },
|
||||
isSaved: false,
|
||||
assets: [],
|
||||
deletedAt: null,
|
||||
seenAt: null,
|
||||
} as unknown as any,
|
||||
memory1: {
|
||||
id: 'memory1',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
memoryAt: new Date(2024),
|
||||
ownerId: userStub.admin.id,
|
||||
owner: userStub.admin,
|
||||
type: MemoryType.ON_THIS_DAY,
|
||||
data: { year: 2024 },
|
||||
isSaved: false,
|
||||
assets: [assetStub.image1],
|
||||
deletedAt: null,
|
||||
seenAt: null,
|
||||
} as unknown as any,
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { AuthUser, User } from 'src/database';
|
||||
import { ActivityItem } from 'src/types';
|
||||
import { Asset, AuthUser, User } from 'src/database';
|
||||
import { OnThisDayData } from 'src/entities/memory.entity';
|
||||
import { AssetStatus, AssetType, MemoryType } from 'src/enum';
|
||||
import { ActivityItem, MemoryItem } from 'src/types';
|
||||
|
||||
export const newUuid = () => randomUUID() as string;
|
||||
export const newUuids = () =>
|
||||
@@ -9,6 +11,7 @@ export const newUuids = () =>
|
||||
.map(() => newUuid());
|
||||
export const newDate = () => new Date();
|
||||
export const newUpdateId = () => 'uuid-v7';
|
||||
export const newSha1 = () => Buffer.from('this is a fake hash');
|
||||
|
||||
const authUser = (authUser: Partial<AuthUser>) => ({
|
||||
id: newUuid(),
|
||||
@@ -35,6 +38,38 @@ export const factory = {
|
||||
}),
|
||||
authUser,
|
||||
user,
|
||||
asset: (asset: Partial<Asset> = {}) => ({
|
||||
id: newUuid(),
|
||||
createdAt: newDate(),
|
||||
updatedAt: newDate(),
|
||||
deletedAt: null,
|
||||
updateId: newUpdateId(),
|
||||
status: AssetStatus.ACTIVE,
|
||||
checksum: newSha1(),
|
||||
deviceAssetId: '',
|
||||
deviceId: '',
|
||||
duplicateId: null,
|
||||
duration: null,
|
||||
encodedVideoPath: null,
|
||||
fileCreatedAt: newDate(),
|
||||
fileModifiedAt: newDate(),
|
||||
isArchived: false,
|
||||
isExternal: false,
|
||||
isFavorite: false,
|
||||
isOffline: false,
|
||||
isVisible: true,
|
||||
libraryId: null,
|
||||
livePhotoVideoId: null,
|
||||
localDateTime: newDate(),
|
||||
originalFileName: 'IMG_123.jpg',
|
||||
originalPath: `upload/12/34/IMG_123.jpg`,
|
||||
ownerId: newUuid(),
|
||||
sidecarPath: null,
|
||||
stackId: null,
|
||||
thumbhash: null,
|
||||
type: AssetType.IMAGE,
|
||||
...asset,
|
||||
}),
|
||||
activity: (activity: Partial<ActivityItem> = {}) => {
|
||||
const userId = activity.userId || newUuid();
|
||||
return {
|
||||
@@ -51,4 +86,21 @@ export const factory = {
|
||||
...activity,
|
||||
};
|
||||
},
|
||||
memory: (memory: Partial<MemoryItem> = {}) => ({
|
||||
id: newUuid(),
|
||||
createdAt: newDate(),
|
||||
updatedAt: newDate(),
|
||||
updateId: newUpdateId(),
|
||||
deletedAt: null,
|
||||
ownerId: newUuid(),
|
||||
type: MemoryType.ON_THIS_DAY,
|
||||
data: { year: 2024 } as OnThisDayData,
|
||||
isSaved: false,
|
||||
memoryAt: newDate(),
|
||||
seenAt: null,
|
||||
showAt: newDate(),
|
||||
hideAt: newDate(),
|
||||
assets: [],
|
||||
...memory,
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user