Archived
2

/api/ subroutes only available in dev/test

This commit is contained in:
VLE2FE
2020-05-28 12:18:38 +02:00
parent 0ea28fa50a
commit 8276e5108c
5 changed files with 43 additions and 10 deletions

View File

@ -5,8 +5,6 @@ import globals from '../globals';
// TODO: restore measurements for m/a
// TODO: coverage!!!
describe('/measurement', () => {
let server;

View File

@ -91,7 +91,7 @@ describe('/', () => {
});
});
describe('A not connected database', () => {
describe('A not connected database', () => { // RUN AS LAST OR RECONNECT DATABASE!!
it('resolves to an 500 error', done => {
db.disconnect(() => {
TestHelper.request(server, done, {
@ -102,6 +102,39 @@ describe('/', () => {
});
});
});
});
// describe('API') // TODO not in production
describe('The /api/{url} redirect', () => {
let server;
let counter = 0; // count number of current test method
before(done => {
process.env.port = '2999';
db.connect('test', done);
});
beforeEach(done => {
process.env.NODE_ENV = counter === 1 ? 'production' : 'test';
counter ++;
server = TestHelper.beforeEach(server, done);
});
afterEach(done => TestHelper.afterEach(server, done));
after(done => TestHelper.after(done));
it('returns the right method', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/api/authorized',
auth: {basic: 'admin'},
httpStatus: 200,
res: {status: 'Authorization successful', method: 'basic'}
});
});
it('is disabled in production', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/api/authorized',
auth: {basic: 'admin'},
httpStatus: 404
});
});
});