import { describe, it, expect } from 'vitest'

// Solo en entorno con DNS `backend` (p. ej. red Docker) y con backend levantado; en Jenkins/CI se omite.
const skipHttpIntegration = process.env.CI === 'true' || Boolean(process.env.JENKINS_URL)

describe.skipIf(skipHttpIntegration)('backend — health check', () => {

    it('el backend esta corriendo y responde', async () => {
        const response = await fetch('http://backend:8000/api/health')
        expect(response.status).toBe(200)
    })

    it('el endpoint de facturas responde', async () => {
        const response = await fetch('http://backend:8000/api/v1/a76/invoices/?company_id=1', {
            headers: { 'Authorization': 'Bearer test' }
        })
        // 200 con datos o 401/403 sin token valido — ambos significan que el backend esta vivo
        expect([200, 401, 403, 422]).toContain(response.status)
    })

})