/**
 * API Integration Smoke Tests
 * Covers core backend endpoints with lightweight end-to-end requests to confirm
 * the server wiring responds successfully for the main route groups.
 */
const request = require('supertest');
const app = require('../../server');

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

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

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

    describe('GET /annotations', () => {
        it('should return list of annotations', 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('GET /', () => {
        it('should return server status', async () => {
            const res = await request(app).get('/');
            expect(res.status).toBe(200);
            expect(res.text).toContain('running');
        });
    });

    describe('POST /annotations - error handling', () => {
        it('should reject requests without required fields', async () => {
            const res = await request(app).post('/annotations');
            // App validates and returns error (400 or 500)
            expect(res.status).toBeGreaterThanOrEqual(400);
        });
    });
});