feat: add course AI agent backend
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { AiCredentialService } from './ai-credential.service';
|
||||
|
||||
describe('AiCredentialService', () => {
|
||||
it('encrypts and decrypts an API key without storing plaintext', () => {
|
||||
const config = { get: jest.fn().mockReturnValue('a-secure-test-secret-with-more-than-24-characters') } as unknown as ConfigService;
|
||||
const service = new AiCredentialService(config);
|
||||
|
||||
const encrypted = service.encrypt('sk-test-secret');
|
||||
|
||||
expect(encrypted).not.toContain('sk-test-secret');
|
||||
expect(service.decrypt(encrypted)).toBe('sk-test-secret');
|
||||
});
|
||||
|
||||
it('rejects a short encryption secret', () => {
|
||||
const config = { get: jest.fn().mockReturnValue('too-short') } as unknown as ConfigService;
|
||||
const service = new AiCredentialService(config);
|
||||
|
||||
expect(() => service.encrypt('sk-test-secret')).toThrow(BadRequestException);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user