feat: add course AI agent backend

This commit is contained in:
2026-10-14 14:25:42 +09:00
parent 5ccdc1e843
commit 56d7f2060c
20 changed files with 788 additions and 3 deletions
+23
View File
@@ -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);
});
});