import { describe, expect, it, vi } from 'vitest' import axios from 'axios' import { checkApiHealth } from './api-health' describe('checkApiHealth', () => { it('returns online for the live response', async () => { const request = vi.fn().mockResolvedValue({ data: { status: 'ok' } }) await expect(checkApiHealth(request)).resolves.toBe('online') expect(request).toHaveBeenCalledWith('/api/v1/health/live', { timeout: 3000 }) }) it('returns offline for invalid status', async () => { await expect(checkApiHealth(vi.fn().mockResolvedValue({ data: { status: 'degraded' } }))).resolves.toBe('offline') await expect(checkApiHealth(vi.fn().mockResolvedValue({ data: null }))).resolves.toBe('offline') }) it('returns offline when the request rejects', async () => { await expect(checkApiHealth(vi.fn().mockRejectedValue(new Error('network unavailable')))).resolves.toBe('offline') }) it('uses Axios by default', async () => { const request = vi.spyOn(axios, 'get').mockResolvedValue({ data: { status: 'ok' } } as never) await expect(checkApiHealth()).resolves.toBe('online') expect(request).toHaveBeenCalledOnce() request.mockRestore() }) })