Skip to content

Commit

Permalink
hasAccess test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed Jun 23, 2020
1 parent 5e887ef commit 6e309ca
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test/models/middleware/middleware/hasAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,33 @@ describe('Middleware: hasAccess', () => {

it('is authenticated: cant go through: wrong verb', async () => {
const req = Req.generate();
accessToken.addIsNotAuthenticated(req);
req.baseUrl = '';
req.path = '/test/1';
req.method = 'post';
const decoded = { user: 2 };
await accessToken.addIsAuthenticated(req, decoded);
const res = Res.generate();
let called = false;
const next = () => { called = true; };
middleware.hasAccess(req, res, next);
await middleware.hasAccess(req, res, next);
assert.equal(res.statusToSend, 403);
assert.equal(res.sendingFile.error, 'Access restricted to this data');
assert.equal(called, false);
throw new Error('NOT DONE');
});

it('is authenticated: cant go through', async () => {
it('is authenticated: cant go through (wrong path)', async () => {
const req = Req.generate();
accessToken.addIsNotAuthenticated(req);
req.baseUrl = '';
req.path = '/test/2';
req.method = 'get';
const decoded = { user: 2 };
await accessToken.addIsAuthenticated(req, decoded);
const res = Res.generate();
let called = false;
const next = () => { called = true; };
middleware.hasAccess(req, res, next);
await middleware.hasAccess(req, res, next);
assert.equal(res.statusToSend, 403);
assert.equal(res.sendingFile.error, 'Access restricted to this data');
assert.equal(called, false);
throw new Error('NOT DONE');
});
});

0 comments on commit 6e309ca

Please sign in to comment.