Skip to content

Commit

Permalink
Improve ExpressJS support
Browse files Browse the repository at this point in the history
  • Loading branch information
kostia-official committed May 10, 2017
1 parent 95c1194 commit cbf39ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const ruleChecker = require('./rule-checker');
const jwtDecode = require('./jwt-decode');
const denyNotAllowed = require('./deny-not-allowed');

module.exports = (configs, options = {}) => function () {
const app = this;
module.exports = (configs, options = {}) => function (app = this) {
const check = ruleChecker(options);

if (options.jwt) app.use(jwtDecode(options.jwt));
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions test/unit/express.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const test = require('ava');
const lib = require('../../src');
const Supertest = require('supertest');
const express = require('express');

const app = express();

test('should work for express', async (t) => {
const config = [{ url: '/blog', method: 'GET', allow: {} }];
const options = { denyNotAllowed: true };

lib(config, options)(app);
app.get('/blog', (req, res) => {
res.send({ message: 'hi' });
});

app.get('/secret', (req, res) => {
res.send({ message: 'secret' });
});

const supertest = Supertest(app);

const { error: getBlogError } = await supertest.get('/blog');
t.falsy(getBlogError);

const { error: getSecretError } = await supertest.get('/secret');
t.truthy(getSecretError);
});

0 comments on commit cbf39ac

Please sign in to comment.