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