import { describe, it, expect, afterAll } from 'vitest' import { buildApp } from '../app.js' import type { AppConfig } from '../config.js' import { repos } from '@evofw/db' const testConfig: AppConfig = { databaseUrl: 'sqlite::memory:', jwtSecret: 'test', jwtTtlHours: 24, serverPort: 8080, staticDir: null, logLevel: 'error', authRequired: false, authIssuer: 'https://auth.test', authPortalUrl: 'http://localhost:5175', publicBaseUrl: 'https://fw.example.com', enrollSeed: 'test-seed', corsOrigins: [], authAuditIngestSecret: null, secretKey: null, statsRetentionDays: 30, } describe('settings + bumpAgentsForList', () => { const appPromise = buildApp({ memory: true, config: testConfig }) afterAll(async () => { const app = await appPromise await app.close() }) it('rejects unknown settings keys', async () => { const app = await appPromise await app.ready() const res = await app.inject({ method: 'PUT', url: '/api/v1/settings', payload: { unknown_key: 'x' }, }) expect(res.statusCode).toBeGreaterThanOrEqual(400) }) it('accepts show_quick_actions', async () => { const app = await appPromise await app.ready() const res = await app.inject({ method: 'PUT', url: '/api/v1/settings', payload: { show_quick_actions: 'false' }, }) expect(res.statusCode).toBe(200) const get = await app.inject({ method: 'GET', url: '/api/v1/settings' }) expect(get.json().show_quick_actions).toBe('false') }) it('bumpAgentsForList no-ops when list has no rules', async () => { const app = await appPromise await app.ready() const db = app.db const agent = repos.insertAgent(db, { id: 'ag-bump-1', name: 'bump-test', platform: 'linux', tokenPrefix: 'tok', tokenHash: 'hash-bump-1', status: 'approved', defaultAction: 'accept', policyGeneration: 1, settingsJson: '{}', }) expect(agent?.policyGeneration).toBe(1) const list = repos.insertIpList(db, { id: 'list-unused', name: 'unused', type: 'static', configJson: '{}', }) expect(list).toBeTruthy() repos.bumpAgentsForList(db, 'list-unused') const after = repos.getAgent(db, 'ag-bump-1') expect(after?.policyGeneration).toBe(1) }) })