2020-01-14 13:25:13 +01:00
|
|
|
import supertest from 'supertest';
|
|
|
|
import should from 'should/as-function';
|
2020-04-22 17:24:15 +02:00
|
|
|
import db from '../db';
|
2020-01-14 13:25:13 +01:00
|
|
|
|
|
|
|
|
2020-04-22 17:24:15 +02:00
|
|
|
describe('/', () => {
|
|
|
|
let server;
|
2020-01-14 13:25:13 +01:00
|
|
|
|
2020-04-22 17:24:15 +02:00
|
|
|
before(done => {
|
|
|
|
process.env.port = '2999';
|
|
|
|
db.connect('test', done);
|
|
|
|
});
|
|
|
|
beforeEach(done => {
|
|
|
|
delete require.cache[require.resolve('../index')]; // prevent loading from cache
|
|
|
|
server = require('../index');
|
|
|
|
db.drop(err => { // reset database
|
|
|
|
if (err) return done(err);
|
|
|
|
db.loadJson(require('../test/db.json'), done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
afterEach(done => {
|
|
|
|
server.close(done);
|
|
|
|
});
|
|
|
|
it('returns the root message', done => {
|
|
|
|
supertest(server)
|
2020-01-14 13:25:13 +01:00
|
|
|
.get('/')
|
|
|
|
.expect('Content-type', /json/)
|
2020-04-22 17:24:15 +02:00
|
|
|
.expect(200, (err, res) => {
|
2020-01-14 13:25:13 +01:00
|
|
|
should(res.body).be.eql({message: 'API server up and running!'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 17:24:15 +02:00
|
|
|
|
|
|
|
describe('Testing unknown routes', () => {
|
|
|
|
let server;
|
|
|
|
|
|
|
|
before(done => {
|
|
|
|
db.connect('test', done);
|
|
|
|
});
|
|
|
|
beforeEach(done => {
|
|
|
|
delete require.cache[require.resolve('../index')]; // prevent loading from cache
|
|
|
|
server = require('../index');
|
|
|
|
db.drop(err => { // reset database
|
|
|
|
if (err) return done(err);
|
|
|
|
db.loadJson(require('../test/db.json'), done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
afterEach(done => {
|
|
|
|
server.close(done);
|
|
|
|
});
|
|
|
|
it('returns a 404 message', done => {
|
|
|
|
supertest(server)
|
|
|
|
.get('/unknownroute')
|
|
|
|
.expect(404);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|