Skip to content

Commit

Permalink
test: add GET config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowgate15 committed Aug 10, 2021
1 parent 73bc6c5 commit a27e31c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
25 changes: 25 additions & 0 deletions test/api/v1/config.js
Original file line number Diff line number Diff line change
@@ -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'));
});
12 changes: 6 additions & 6 deletions test/api/v1.js → test/api/v1/index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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));
});
1 change: 1 addition & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a27e31c

Please sign in to comment.