Forgot to lint again
Some checks failed
CI/CD Pipeline - Build, Test, and Deploy / 🧪 Test & Lint (push) Successful in 9m31s
CI/CD Pipeline - Build, Test, and Deploy / 🔒 Security Scan (push) Successful in 9m29s
CI/CD Pipeline - Build, Test, and Deploy / 🏗️ Build & Push Image (push) Failing after 11m19s
CI/CD Pipeline - Build, Test, and Deploy / 🛡️ Image Security Scan (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🚀 Deploy to Development (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🏭 Deploy to Production (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🧹 Cleanup (push) Successful in 1s
Some checks failed
CI/CD Pipeline - Build, Test, and Deploy / 🧪 Test & Lint (push) Successful in 9m31s
CI/CD Pipeline - Build, Test, and Deploy / 🔒 Security Scan (push) Successful in 9m29s
CI/CD Pipeline - Build, Test, and Deploy / 🏗️ Build & Push Image (push) Failing after 11m19s
CI/CD Pipeline - Build, Test, and Deploy / 🛡️ Image Security Scan (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🚀 Deploy to Development (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🏭 Deploy to Production (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🧹 Cleanup (push) Successful in 1s
This commit is contained in:
103
tests/health.test.js
Normal file
103
tests/health.test.js
Normal file
@ -0,0 +1,103 @@
|
||||
const request = require('supertest');
|
||||
const app = require('../src/app');
|
||||
|
||||
describe('Health Check Endpoints', () => {
|
||||
describe('GET /health', () => {
|
||||
it('should return basic health status', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('status', 'healthy');
|
||||
expect(response.body).toHaveProperty('timestamp');
|
||||
expect(response.body).toHaveProperty('uptime');
|
||||
expect(response.body).toHaveProperty('service', 'harbor-ci-cd-demo');
|
||||
expect(typeof response.body.uptime).toBe('number');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /health/detailed', () => {
|
||||
it('should return detailed health information', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health/detailed')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('status');
|
||||
expect(response.body).toHaveProperty('timestamp');
|
||||
expect(response.body).toHaveProperty('service', 'harbor-ci-cd-demo');
|
||||
expect(response.body).toHaveProperty('uptime');
|
||||
expect(response.body).toHaveProperty('memory');
|
||||
expect(response.body).toHaveProperty('loadAverage');
|
||||
expect(response.body).toHaveProperty('environment');
|
||||
|
||||
// Check memory structure
|
||||
expect(response.body.memory).toHaveProperty('status');
|
||||
expect(response.body.memory).toHaveProperty('system');
|
||||
expect(response.body.memory).toHaveProperty('process');
|
||||
expect(response.body.memory.system).toHaveProperty('total');
|
||||
expect(response.body.memory.system).toHaveProperty('used');
|
||||
expect(response.body.memory.system).toHaveProperty('percentage');
|
||||
|
||||
// Check uptime structure
|
||||
expect(response.body.uptime).toHaveProperty('process');
|
||||
expect(response.body.uptime).toHaveProperty('system');
|
||||
expect(typeof response.body.uptime.process).toBe('number');
|
||||
expect(typeof response.body.uptime.system).toBe('number');
|
||||
|
||||
// Check load average
|
||||
expect(Array.isArray(response.body.loadAverage)).toBe(true);
|
||||
expect(response.body.loadAverage).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('should include version information', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health/detailed')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('version');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /health/ready', () => {
|
||||
it('should return readiness status', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health/ready')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('status', 'ready');
|
||||
expect(response.body).toHaveProperty('timestamp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /health/live', () => {
|
||||
it('should return liveness status', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health/live')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('status', 'alive');
|
||||
expect(response.body).toHaveProperty('timestamp');
|
||||
expect(response.body).toHaveProperty('uptime');
|
||||
expect(typeof response.body.uptime).toBe('number');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Health status validation', () => {
|
||||
it('should return valid timestamp format', async() => {
|
||||
const response = await request(app)
|
||||
.get('/health')
|
||||
.expect(200);
|
||||
|
||||
const timestamp = new Date(response.body.timestamp);
|
||||
expect(timestamp).toBeInstanceOf(Date);
|
||||
expect(timestamp.getTime()).not.toBeNaN();
|
||||
});
|
||||
|
||||
it('should return consistent service name across endpoints', async() => {
|
||||
const basicHealth = await request(app).get('/health');
|
||||
const detailedHealth = await request(app).get('/health/detailed');
|
||||
|
||||
expect(basicHealth.body.service).toBe(detailedHealth.body.service);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user