feat: medium tests for user and sync service (#16304)

Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
Jason Rasmussen 2025-02-25 11:31:07 -05:00 committed by GitHub
parent ae61ea7984
commit 7c851893b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 634 additions and 24 deletions

View file

@ -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,
};
}

View file

@ -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 };
}

View file

@ -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

View file

@ -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 })