/**
 * Core API Endpoint Tests
 * Verifies base health and route availability for the backend's top-level HTTP
 * endpoints and common request paths.
 */
const request = require('supertest');
const app = require('../../../server');

describe('Core API Endpoints', () => {
    describe('Health Check', () => {
        it('GET / should return server status', async () => {
            const res = await request(app).get('/');
            expect(res.status).toBe(200);
            expect(res.text).toContain('running');
        });
    });

    describe('Atlases Endpoint', () => {
        it('GET /api/atlases should return atlases list', async () => {
            const res = await request(app).get('/api/atlases');
            expect(res.status).toBe(200);
            expect(Array.isArray(res.body)).toBe(true);
        });
    });

    describe('Form Schema Endpoint', () => {
        it('GET /api/form-schema should return schemas', async () => {
            const res = await request(app).get('/api/form-schema');
            expect(res.status).toBe(200);
            expect(Array.isArray(res.body)).toBe(true);
        });
    });

    describe('Models Endpoint', () => {
        it('GET /api/models should return models list', async () => {
            const res = await request(app).get('/api/models');
            expect(res.status).toBe(200);
            expect(Array.isArray(res.body)).toBe(true);
        });
    });

    describe('Annotations Endpoint', () => {
        it('GET /annotations should return annotations list', async () => {
            const res = await request(app).get('/annotations');
            expect(res.status).toBe(200);
            expect(res.body).toHaveProperty('annotations');
            expect(Array.isArray(res.body.annotations)).toBe(true);
        });
    });

    describe('Error Handling', () => {
        it('POST /annotations without required fields should return error', async () => {
            const res = await request(app).post('/annotations');
            // App returns 500 for missing fields, not 400
            expect(res.status).toBe(500);
        });
    });
});