import { test, expect, API_BASE } from "./fixtures"

test.describe("API Health", () => {
    test("should respond to API base endpoint", async ({ api }) => {
        // tibi-server responds to the base API path
        const res = await api.get(`${API_BASE}/`)
        // Accept any successful response (200-299), 401 (auth required), or 404 (no root handler)
        expect([200, 204, 401, 404]).toContain(res.status())
    })

    test("should respond to SSR collection", async ({ api }) => {
        // The ssr collection is part of the starter kit
        const res = await api.get(`${API_BASE}/ssr`)
        expect(res.status()).toBeLessThan(500)
    })

    test("should reject invalid action commands", async ({ api }) => {
        const res = await api.post(`${API_BASE}/action`, {
            params: { cmd: "nonexistent_action" },
            data: {},
        })
        // Should return an error, not crash
        expect(res.status()).toBeGreaterThanOrEqual(400)
        expect(res.status()).toBeLessThan(500)
    })
})
