test(api): общий хелпер с фиксированным RSA-ключом

Фиксированный ключ (OIDC_RSA_PRIVATE_KEY) вместо generateKeyPair
на каждое построение приложения: фаза тестов 9.9с → 1.6с (×6).
Локальные копии buildTestApp/adminToken в 4 файлах заменены на helpers.ts
This commit is contained in:
Denozordec
2026-09-23 14:51:38 +07:00
parent c48132e89e
commit e135150c2d
5 changed files with 73 additions and 84 deletions
+3 -19
View File
@@ -1,17 +1,9 @@
import { describe, expect, it } from 'vitest'
import { buildApp } from '../src/app.js'
import { loadConfig } from '../src/config.js'
import { buildTestApp } from './helpers.js'
describe('app-switcher API', () => {
it('GET /api/v1/app-switcher is public and returns defaults', async () => {
const config = loadConfig({
...process.env,
JWT_SECRET: 'test-secret-at-least-8',
ADMIN_PASSWORD: 'admin',
DATABASE_URL: 'sqlite::memory:',
NODE_ENV: 'test',
})
const app = await buildApp({ config, databaseUrl: 'sqlite::memory:' })
const app = await buildTestApp()
const res = await app.inject({ method: 'GET', url: '/api/v1/app-switcher' })
expect(res.statusCode).toBe(200)
const body = res.json() as { menuLabel: string; apps: { id: string }[] }
@@ -38,15 +30,7 @@ describe('app-switcher API', () => {
})
it('PUT /api/v1/admin/app-switcher requires admin and persists', async () => {
const config = loadConfig({
...process.env,
JWT_SECRET: 'test-secret-at-least-8',
ADMIN_EMAIL: '[email protected]',
ADMIN_PASSWORD: 'adminpass',
DATABASE_URL: 'sqlite::memory:',
NODE_ENV: 'test',
})
const app = await buildApp({ config, databaseUrl: 'sqlite::memory:' })
const app = await buildTestApp()
const denied = await app.inject({
method: 'PUT',