import TestHelper from "../helpers/test"; describe('/', () => { let server; before(done => TestHelper.before(done)); beforeEach(done => server = TestHelper.beforeEach(server, done)); afterEach(done => TestHelper.afterEach(server, done)); describe('GET /', () => { it('returns the root message', done => { TestHelper.request(server, done, { method: 'get', url: '/', httpStatus: 200, res: {status: 'API server up and running!'} }); }); }); describe('Unknown routes', () => { it('return a 404 message', done => { TestHelper.request(server, done, { method: 'get', url: '/unknownroute', httpStatus: 404 }); }); }); describe('An unauthorized request', () => { it('returns a 401 message', done => { TestHelper.request(server, done, { method: 'get', url: '/authorized', httpStatus: 401 }); }); it('does not work with correct username', done => { TestHelper.request(server, done, { method: 'get', url: '/authorized', auth: {name: 'admin', pass: 'Abc123!!'}, httpStatus: 401 }); }); }); 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'} }); }); 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'} }); }); }); });