Skip to content

Commit

Permalink
Add test for server entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
n1klaus committed Jul 15, 2023
1 parent 80ec5de commit cc6253c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions backend/tests/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import request from 'supertest';
import { expect } from 'chai';
import app from '../src/server';

describe('Server', () => {
describe('GET /status', () => {
it('should return status', async () => {
const res = await request(app).get('/status');

expect(res.status).to.equal(200);
expect(res.body).to.have.property('status');
});
});

describe('GET /stats', () => {
it('should return stats', async () => {
const res = await request(app).get('/stats');

expect(res.status).to.equal(200);
expect(res.body).to.have.property('stats');
});
});

describe('GET /health', () => {
it('should return health status', async () => {
const res = await request(app).get('/health');

expect(res.status).to.equal(200);
expect(res.body).to.have.property('status', 'success');
});
});

describe('GET unknown route', () => {
it('should return 404', async () => {
const res = await request(app).get('/unknown');

expect(res.status).to.equal(404);
expect(res.body).to.have.property('message');
});
});

describe('Error handling', () => {
it('should handle errors', async () => {
// Cause an error
const res = await request(app).get('/error');

expect(res.status).to.equal(500);
expect(res.body).to.have.property('message');
});
});
});

0 comments on commit cc6253c

Please sign in to comment.