2020-05-08 09:58:12 +02:00
|
|
|
import TestHelper from "../test/helper";
|
2020-01-14 13:25:13 +01:00
|
|
|
|
|
|
|
|
2020-04-27 11:44:28 +02:00
|
|
|
describe('/', () => {
|
2020-04-22 17:24:15 +02:00
|
|
|
let server;
|
2020-04-27 11:44:28 +02:00
|
|
|
before(done => TestHelper.before(done));
|
|
|
|
beforeEach(done => server = TestHelper.beforeEach(server, done));
|
|
|
|
afterEach(done => TestHelper.afterEach(server, done));
|
2020-01-14 13:25:13 +01:00
|
|
|
|
2020-04-27 11:44:28 +02:00
|
|
|
describe('GET /', () => {
|
|
|
|
it('returns the root message', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/',
|
|
|
|
httpStatus: 200,
|
|
|
|
res: {status: 'API server up and running!'}
|
2020-01-14 13:25:13 +01:00
|
|
|
});
|
2020-04-22 17:24:15 +02:00
|
|
|
});
|
|
|
|
});
|
2020-04-23 13:59:45 +02:00
|
|
|
|
2020-04-27 11:44:28 +02:00
|
|
|
describe('Unknown routes', () => {
|
|
|
|
it('return a 404 message', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/unknownroute',
|
|
|
|
httpStatus: 404
|
|
|
|
});
|
2020-04-23 13:59:45 +02:00
|
|
|
});
|
|
|
|
});
|
2020-04-27 11:44:28 +02:00
|
|
|
|
|
|
|
describe('An unauthorized request', () => {
|
|
|
|
it('returns a 401 message', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/authorized',
|
|
|
|
httpStatus: 401
|
2020-04-23 13:59:45 +02:00
|
|
|
});
|
2020-04-27 11:44:28 +02:00
|
|
|
});
|
|
|
|
it('does not work with correct username', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/authorized',
|
|
|
|
auth: {name: 'admin', pass: 'Abc123!!'},
|
|
|
|
httpStatus: 401
|
2020-04-23 13:59:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-27 11:44:28 +02:00
|
|
|
|
|
|
|
describe('An authorized request', () => {
|
|
|
|
it('works with an API key', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/authorized',
|
|
|
|
auth: {key: 'admin'},
|
|
|
|
httpStatus: 200,
|
|
|
|
res: {status: 'Authorization successful', method: 'key'}
|
2020-04-23 13:59:45 +02:00
|
|
|
});
|
2020-04-27 11:44:28 +02:00
|
|
|
});
|
|
|
|
it('works with basic auth', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
url: '/authorized',
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
httpStatus: 200,
|
|
|
|
res: {status: 'Authorization successful', method: 'basic'}
|
2020-04-23 13:59:45 +02:00
|
|
|
});
|
2020-04-27 11:44:28 +02:00
|
|
|
});
|
2020-04-22 17:24:15 +02:00
|
|
|
});
|
|
|
|
});
|