diff --git a/test/api/v1/config.js b/test/api/v1/config.js new file mode 100644 index 0000000..ed9d07c --- /dev/null +++ b/test/api/v1/config.js @@ -0,0 +1,25 @@ +const test = require('ava'); +const jwt = require('jsonwebtoken'); +const _ = require('lodash'); + +const config = require('../../../config'); + +const utils = require('../../utils'); + +const rootUrl = '/v1/config'; + +test.before(async (t) => { + await utils.setupApiServer(t); + t.context.token = jwt.sign({}, config.jwt.secret); + + t.context.api = t.context.api.auth(t.context.token, { type: 'bearer' }); +}); + +test('GET > successfully', async (t) => { + const { api, bree } = t.context; + + const res = await api.get(rootUrl); + + t.is(res.status, 200); + t.like(res.body, _.omit(bree.config, 'logger')); +}); diff --git a/test/api/v1.js b/test/api/v1/index.js similarity index 76% rename from test/api/v1.js rename to test/api/v1/index.js index f8fa06f..e7c4666 100644 --- a/test/api/v1.js +++ b/test/api/v1/index.js @@ -1,9 +1,9 @@ const test = require('ava'); const jwt = require('jsonwebtoken'); -const config = require('../../config'); +const config = require('../../../config'); -const utils = require('../utils'); +const utils = require('../../utils'); test.before(async (t) => { await utils.setupApiServer(t); @@ -13,20 +13,20 @@ test.before(async (t) => { test('fails when no creds are presented', async (t) => { const { api } = t.context; const res = await api.get('/v1/test'); - t.is(401, res.status); + t.is(res.status, 401); }); test('works with jwt auth', async (t) => { const { api, token } = t.context; const res = await api.get('/v1/test').auth(token, { type: 'bearer' }); - t.is(200, res.status); + t.is(res.status, 200); }); test('has bree in context', async (t) => { const { api, token } = t.context; const res = await api.get('/v1/test').auth(token, { type: 'bearer' }); - t.is(200, res.status); - t.is(Boolean(res.body.breeExists), true); + t.is(res.status, 200); + t.is(true, Boolean(res.body.breeExists)); }); diff --git a/test/utils.js b/test/utils.js index 4a33391..f9ccffa 100644 --- a/test/utils.js +++ b/test/utils.js @@ -44,6 +44,7 @@ exports.setupApiServer = async (t) => { const bree = new Bree(baseConfig); t.context.api = request.agent(bree.api.server); + t.context.bree = bree; }; // Make sure to load the web server first using setupWebServer