// ============================================================ // Testes automatizados da aplicação // O Jenkins executa estes testes a cada push. // Se QUALQUER teste falhar, o pipeline para e NÃO faz deploy. // Isso é o "firewall de qualidade" do CI/CD. // ============================================================ const request = require('supertest'); const app = require('../src/index'); describe('Rota Principal GET /', () => { test('deve retornar status 200', async () => { const res = await request(app).get('/'); expect(res.statusCode).toBe(200); }); test('deve retornar o nome da aplicação', async () => { const res = await request(app).get('/'); expect(res.body).toHaveProperty('app', 'CI/CD Demo'); }); test('deve retornar status "rodando"', async () => { const res = await request(app).get('/'); expect(res.body).toHaveProperty('status', 'rodando'); }); test('deve conter um timestamp', async () => { const res = await request(app).get('/'); expect(res.body).toHaveProperty('timestamp'); }); }); describe('Health Check GET /health', () => { test('deve retornar status 200', async () => { const res = await request(app).get('/health'); expect(res.statusCode).toBe(200); }); test('deve retornar status "healthy"', async () => { const res = await request(app).get('/health'); expect(res.body).toHaveProperty('status', 'healthy'); }); }); describe('Informações do Sistema GET /info', () => { test('deve retornar versão do Node.js', async () => { const res = await request(app).get('/info'); expect(res.statusCode).toBe(200); expect(res.body).toHaveProperty('node_version'); }); test('deve retornar uptime em segundos', async () => { const res = await request(app).get('/info'); expect(res.body).toHaveProperty('uptime_seconds'); expect(typeof res.body.uptime_seconds).toBe('number'); }); });