mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor: convert activity stub to a factory (#16702)
This commit is contained in:
parent
f82786a297
commit
2d106755f6
5 changed files with 135 additions and 127 deletions
54
server/test/small.factory.ts
Normal file
54
server/test/small.factory.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { AuthUser, User } from 'src/database';
|
||||
import { ActivityItem } from 'src/types';
|
||||
|
||||
export const newUuid = () => randomUUID() as string;
|
||||
export const newUuids = () =>
|
||||
Array.from({ length: 100 })
|
||||
.fill(0)
|
||||
.map(() => newUuid());
|
||||
export const newDate = () => new Date();
|
||||
export const newUpdateId = () => 'uuid-v7';
|
||||
|
||||
const authUser = (authUser: Partial<AuthUser>) => ({
|
||||
id: newUuid(),
|
||||
isAdmin: false,
|
||||
name: 'Test User',
|
||||
email: 'test@immich.cloud',
|
||||
quotaUsageInBytes: 0,
|
||||
quotaSizeInBytes: null,
|
||||
...authUser,
|
||||
});
|
||||
|
||||
const user = (user: Partial<User>) => ({
|
||||
id: newUuid(),
|
||||
name: 'Test User',
|
||||
email: 'test@immich.cloud',
|
||||
profileImagePath: '',
|
||||
profileChangedAt: newDate(),
|
||||
...user,
|
||||
});
|
||||
|
||||
export const factory = {
|
||||
auth: (user: Partial<AuthUser> = {}) => ({
|
||||
user: authUser(user),
|
||||
}),
|
||||
authUser,
|
||||
user,
|
||||
activity: (activity: Partial<ActivityItem> = {}) => {
|
||||
const userId = activity.userId || newUuid();
|
||||
return {
|
||||
id: newUuid(),
|
||||
comment: null,
|
||||
isLiked: false,
|
||||
userId,
|
||||
user: user({ id: userId }),
|
||||
assetId: newUuid(),
|
||||
albumId: newUuid(),
|
||||
createdAt: newDate(),
|
||||
updatedAt: newDate(),
|
||||
updateId: newUpdateId(),
|
||||
...activity,
|
||||
};
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue