refactor: test utils (#16588)

This commit is contained in:
Jason Rasmussen
2025-03-04 11:15:41 -05:00
committed by GitHub
parent 1423cfd53c
commit 63c01b78e2
8 changed files with 245 additions and 216 deletions

View File

@@ -15,7 +15,7 @@ export class APIKeyService extends BaseService {
throw new BadRequestException('Cannot grant permissions you do not have');
}
const entity = await this.keyRepository.create({
const entity = await this.apiKeyRepository.create({
key: this.cryptoRepository.hashSha256(secret),
name: dto.name || 'API Key',
userId: auth.user.id,
@@ -26,27 +26,27 @@ export class APIKeyService extends BaseService {
}
async update(auth: AuthDto, id: string, dto: APIKeyUpdateDto): Promise<APIKeyResponseDto> {
const exists = await this.keyRepository.getById(auth.user.id, id);
const exists = await this.apiKeyRepository.getById(auth.user.id, id);
if (!exists) {
throw new BadRequestException('API Key not found');
}
const key = await this.keyRepository.update(auth.user.id, id, { name: dto.name });
const key = await this.apiKeyRepository.update(auth.user.id, id, { name: dto.name });
return this.map(key);
}
async delete(auth: AuthDto, id: string): Promise<void> {
const exists = await this.keyRepository.getById(auth.user.id, id);
const exists = await this.apiKeyRepository.getById(auth.user.id, id);
if (!exists) {
throw new BadRequestException('API Key not found');
}
await this.keyRepository.delete(auth.user.id, id);
await this.apiKeyRepository.delete(auth.user.id, id);
}
async getById(auth: AuthDto, id: string): Promise<APIKeyResponseDto> {
const key = await this.keyRepository.getById(auth.user.id, id);
const key = await this.apiKeyRepository.getById(auth.user.id, id);
if (!key) {
throw new BadRequestException('API Key not found');
}
@@ -54,7 +54,7 @@ export class APIKeyService extends BaseService {
}
async getAll(auth: AuthDto): Promise<APIKeyResponseDto[]> {
const keys = await this.keyRepository.getByUserId(auth.user.id);
const keys = await this.apiKeyRepository.getByUserId(auth.user.id);
return keys.map((key) => this.map(key));
}

View File

@@ -307,7 +307,7 @@ export class AuthService extends BaseService {
private async validateApiKey(key: string): Promise<AuthDto> {
const hashedKey = this.cryptoRepository.hashSha256(key);
const apiKey = await this.keyRepository.getKey(hashedKey);
const apiKey = await this.apiKeyRepository.getKey(hashedKey);
if (apiKey?.user) {
return {
user: apiKey.user,

View File

@@ -57,17 +57,17 @@ export class BaseService {
protected logger: LoggingRepository,
protected accessRepository: AccessRepository,
protected activityRepository: ActivityRepository,
protected auditRepository: AuditRepository,
protected albumRepository: AlbumRepository,
protected albumUserRepository: AlbumUserRepository,
protected apiKeyRepository: ApiKeyRepository,
protected assetRepository: AssetRepository,
protected auditRepository: AuditRepository,
protected configRepository: ConfigRepository,
protected cronRepository: CronRepository,
protected cryptoRepository: CryptoRepository,
protected databaseRepository: DatabaseRepository,
protected eventRepository: EventRepository,
protected jobRepository: JobRepository,
protected keyRepository: ApiKeyRepository,
protected libraryRepository: LibraryRepository,
protected machineLearningRepository: MachineLearningRepository,
protected mapRepository: MapRepository,