import { describe, expect, it, vi } from 'vitest' vi.mock('@/lib/db', () => ({ db: { $queryRaw: vi.fn(async () => [{ '?column?': 1 }]), serviceHeartbeat: { findUnique: vi.fn(async () => ({ service: 'worker', status: 'up', detail: null, at: new Date() })) }, }, })) vi.mock('@/lib/env', () => ({ getEnv: () => ({ CLAMAV_ADDRESS: 'clamav:3310' }), })) vi.mock('@/lib/files/clamav', () => ({ pingClamav: vi.fn(async () => true) })) describe('collectHealth', () => { it('meldet betriebsbereit, wenn alle drei Abhaengigkeiten antworten', async () => { const { collectHealth } = await import('@/lib/health/check') const report = await collectHealth() expect(report.status).toBe('up') expect(report.components.database.status).toBe('up') expect(report.components.discordGateway.status).toBe('up') expect(report.components.clamav.status).toBe('up') }) it('bleibt nur eingeschraenkt, wenn allein die Virenpruefung ausfaellt', async () => { const clamav = await import('@/lib/files/clamav') vi.mocked(clamav.pingClamav).mockResolvedValueOnce(false) const { collectHealth } = await import('@/lib/health/check') const report = await collectHealth() expect(report.status).toBe('degraded') }) })