import { describe, it, expect } from 'vitest' import { checkSystemHealth } from '@/lib/monitoring/monitoring-service' describe('MonitoringService', () => { describe('checkSystemHealth', () => { it('returns CPU, memory, disk, load, and uptime', async () => { const health = await checkSystemHealth() expect(health.cpuUsagePercent).toBeGreaterThanOrEqual(0) expect(health.cpuUsagePercent).toBeLessThanOrEqual(100) expect(health.memoryTotalMB).toBeGreaterThan(0) expect(health.memoryUsedMB).toBeGreaterThan(0) expect(health.memoryUsagePercent).toBeGreaterThanOrEqual(0) expect(health.memoryUsagePercent).toBeLessThanOrEqual(100) expect(health.diskTotalGB).toBeGreaterThan(0) expect(health.diskUsedGB).toBeGreaterThanOrEqual(0) expect(health.uptime).toBeGreaterThan(0) expect(health.loadAvg1).toBeGreaterThanOrEqual(0) expect(health.loadAvg5).toBeGreaterThanOrEqual(0) }) it('returns rounded values with correct decimal precision', async () => { const health = await checkSystemHealth() // memoryUsagePercent should have at most 1 decimal place const memDecimal = health.memoryUsagePercent.toString().split('.')[1] if (memDecimal) { expect(memDecimal.length).toBeLessThanOrEqual(1) } // cpuUsagePercent should have at most 1 decimal place const cpuDecimal = health.cpuUsagePercent.toString().split('.')[1] if (cpuDecimal) { expect(cpuDecimal.length).toBeLessThanOrEqual(1) } // loadAvg1 should have at most 2 decimal places const loadDecimal = health.loadAvg1.toString().split('.')[1] if (loadDecimal) { expect(loadDecimal.length).toBeLessThanOrEqual(2) } }) it('returns integer values for memoryUsedMB, memoryTotalMB, and uptime', async () => { const health = await checkSystemHealth() expect(Number.isInteger(health.memoryUsedMB)).toBe(true) expect(Number.isInteger(health.memoryTotalMB)).toBe(true) expect(Number.isInteger(health.uptime)).toBe(true) }) }) })