feat: синхронизация бэкенда с документацией (AGENT_TASK_BACKEND_SYNC)
- Добвлен @fastify/cookie и настройку httpOnly cookie для refresh token
- Добавлен префикс /api/v1 для auth, profile, tests, admin
- Скорректировано в Login: возвращать user (id, nickname, avatarUrl, role, emailVerified),
ставить refreshToken в Set-Cookie
- Скорректировано в Logout: Bearer + cookie, пустое тело, 200 + { message }, очищать cookie
- Скорректировано в Refresh: token из cookie, пустое тело, 200 + { accessToken }, Set-Cookie
- Добавлено в getPrivateProfile: поля role и plan
- Скорректировано в Tests: score = количество правильных, ответ { score, totalQuestions, percentage }
- Добавлено в question_cache_meta: поля valid, retryCount, questionsGenerated
- Обновлены тесты
This commit is contained in:
@@ -91,10 +91,14 @@ describe('AuthService', () => {
|
||||
});
|
||||
|
||||
describe('login', () => {
|
||||
it('returns tokens when credentials are valid', async () => {
|
||||
it('returns user and tokens when credentials are valid', async () => {
|
||||
const mockUser = {
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
nickname: 'tester',
|
||||
avatarUrl: null,
|
||||
role: 'free',
|
||||
emailVerifiedAt: null,
|
||||
passwordHash: 'hashed',
|
||||
};
|
||||
(mockDb.select as ReturnType<typeof vi.fn>).mockReturnValueOnce(
|
||||
@@ -109,6 +113,9 @@ describe('AuthService', () => {
|
||||
password: 'password123',
|
||||
});
|
||||
|
||||
expect(result.user).toBeDefined();
|
||||
expect(result.user.id).toBe('user-1');
|
||||
expect(result.user.email).toBe('test@example.com');
|
||||
expect(result.accessToken).toBe('access-token');
|
||||
expect(result.refreshToken).toBe('refresh-token');
|
||||
expect(verifyPassword).toHaveBeenCalledWith('hashed', 'password123');
|
||||
|
||||
@@ -214,7 +214,7 @@ describe('TestsService', () => {
|
||||
describe('getHistory', () => {
|
||||
it('returns paginated test history', async () => {
|
||||
const mockTests = [
|
||||
{ id: 't-1', userId: 'user-1', stack: 'js', level: 'beginner', questionCount: 1, mode: 'fixed', status: 'completed', score: 100, startedAt: new Date(), finishedAt: new Date(), timeLimitSeconds: null },
|
||||
{ id: 't-1', userId: 'user-1', stack: 'js', level: 'beginner', questionCount: 1, mode: 'fixed', status: 'completed', score: 1, startedAt: new Date(), finishedAt: new Date(), timeLimitSeconds: null },
|
||||
];
|
||||
const mockTqRows = [];
|
||||
(mockDb.select as ReturnType<typeof vi.fn>)
|
||||
|
||||
Reference in New Issue
Block a user