mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: medium tests for user and sync service (#16304)
Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
parent
ae61ea7984
commit
7c851893b4
15 changed files with 634 additions and 24 deletions
|
|
@ -157,6 +157,6 @@ export function mapUserAdmin(entity: UserEntity): UserAdminResponseDto {
|
|||
quotaSizeInBytes: entity.quotaSizeInBytes,
|
||||
quotaUsageInBytes: entity.quotaUsageInBytes,
|
||||
status: entity.status,
|
||||
license: license ?? null,
|
||||
license: license ? { ...license, activatedAt: new Date(license?.activatedAt) } : null,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,5 +115,5 @@ export const getDefaultPreferences = (user: { email: string }): UserPreferences
|
|||
|
||||
export interface UserMetadata extends Record<UserMetadataKey, Record<string, any>> {
|
||||
[UserMetadataKey.PREFERENCES]: DeepPartial<UserPreferences>;
|
||||
[UserMetadataKey.LICENSE]: { licenseKey: string; activationKey: string; activatedAt: Date };
|
||||
[UserMetadataKey.LICENSE]: { licenseKey: string; activationKey: string; activatedAt: string };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ export class UserRepository {
|
|||
await this.db.deleteFrom('user_metadata').where('userId', '=', id).where('key', '=', key).execute();
|
||||
}
|
||||
|
||||
delete(user: UserEntity, hard?: boolean): Promise<UserEntity> {
|
||||
delete(user: { id: string }, hard?: boolean): Promise<UserEntity> {
|
||||
return hard
|
||||
? (this.db.deleteFrom('users').where('id', '=', user.id).execute() as unknown as Promise<UserEntity>)
|
||||
: (this.db
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ export class UserService extends BaseService {
|
|||
if (!license) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return license.value;
|
||||
return { ...license.value, activatedAt: new Date(license.value.activatedAt) };
|
||||
}
|
||||
|
||||
async deleteLicense({ user }: AuthDto): Promise<void> {
|
||||
|
|
@ -170,17 +170,14 @@ export class UserService extends BaseService {
|
|||
throw new BadRequestException('Invalid license key');
|
||||
}
|
||||
|
||||
const licenseData = {
|
||||
...license,
|
||||
activatedAt: new Date(),
|
||||
};
|
||||
const activatedAt = new Date();
|
||||
|
||||
await this.userRepository.upsertMetadata(auth.user.id, {
|
||||
key: UserMetadataKey.LICENSE,
|
||||
value: licenseData,
|
||||
value: { ...license, activatedAt: activatedAt.toISOString() },
|
||||
});
|
||||
|
||||
return licenseData;
|
||||
return { ...license, activatedAt };
|
||||
}
|
||||
|
||||
@OnJob({ name: JobName.USER_SYNC_USAGE, queue: QueueName.BACKGROUND_TASK })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue