Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
annyhe committed Dec 19, 2016
1 parent 3fdd53b commit 00f6fa7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/v1/helpers/verbs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ module.exports = {
doPatch,
doPost,
doPut,
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"test-db": "npm run checkdb && mocha -R dot --recursive tests/db",
"test-realtime": "mocha -R dot --recursive tests/realtime",
"test-view": "NODE_ENV=test mocha -R dot --recursive --compilers js:babel-core/register --require ./tests/view/setup.js tests/view",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/db tests/config && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-realtime && npm run test-token-req && npm run test-token-notreq && npm run test-disablehttp && npm run test-jobQueue",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/db tests/config && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-realtime && npm run test-token-req && npm run test-token-notreq && npm run test-disablehttp && npm run test-jobQueue && npm run test-enforced",
"undo-migratedb": "node db/migrateUndo.js",
"view": "NODE_ENV=production gulp browserifyViews && npm start"
},
Expand Down
54 changes: 26 additions & 28 deletions tests/enforceToken/verbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* tests/enforceToken/verbs.js
*
* Tests config utilities
* Checks whether token-enforced path behaves as expected.
*/

const expect = require('chai').expect;
Expand All @@ -18,7 +18,6 @@ const supertest = require('supertest');
const api = supertest(require('../../index').app);
const u = require('../testUtils');
const registerPath = '/v1/register';
const tokenPath = '/v1/token';
const { OK, CREATED, FORBIDDEN } = constants.httpStatus;

const STABLE_PATH = '/v1/subjects';
Expand All @@ -28,18 +27,17 @@ describe('API verb token enforced tests', () => {
it('GET docs without token should succeed', (done) => {
api.get('/v1/docs')
.expect(constants.httpStatus.OK)
.end((err, res) => {
.end((err /* res */) => {
if (err) {
return done(err);
}
done();
});
});

describe('CRUD should require tokens',
() => {
describe('CRUD should require tokens', () => {
let defaultToken;
// before: create a resource with a token should succeed
// before: create a resource with NO token should succeed
before((done) => {
api.post(registerPath)
.send(u.fakeUserCredentials)
Expand Down Expand Up @@ -87,15 +85,15 @@ describe('API verb token enforced tests', () => {
function testProtectedPath(verb, path, OBJ, expectedSuccessStatus) {
const VERB = verb.toUpperCase();
it(VERB + ' ' + path + ' ' +
"missing token returns FORBIDDEN", (done) => {
'missing token returns FORBIDDEN', (done) => {
const call = api[verb](path);
if (OBJ) {
call.send(OBJ)
call.send(OBJ);
}
call
.expect(FORBIDDEN)
.expect(/No authorization token was found/)
.end((err, res) => {
.end((err /* res */) => {
if (err) {
return done(err);
}
Expand All @@ -106,28 +104,28 @@ describe('API verb token enforced tests', () => {

it(VERB + ' ' + path + ' ' +
'wrong token provided returns FORBIDDEN', (done) => {
const call = api[verb](path);
if (OBJ) {
call.send(OBJ)
const call = api[verb](path);
if (OBJ) {
call.send(OBJ);
}
call
.set('Authorization', `${defaultToken}xyz`)
.expect(FORBIDDEN)
.expect(/Invalid Token/)
.end((err) => {
if (err) {
return done(err);
}
call
.set('Authorization', `${defaultToken}xyz`)
.expect(FORBIDDEN)
.expect(/Invalid Token/)
.end((err) => {
if (err) {
return done(err);
}

done();
});

done();
});
});

it(VERB + ' ' + path + ' ' +
'appropriate token returns OK', (done) => {
const call = api[verb](path);
if (OBJ) {
call.send(OBJ)
call.send(OBJ);
}
const expectedStatus = expectedSuccessStatus || OK;
call
Expand All @@ -141,15 +139,15 @@ describe('API verb token enforced tests', () => {
done();
});
});
};
}

testProtectedPath('get', STABLE_PATH + '/' + NEW_SUBJECT);
testProtectedPath('post', STABLE_PATH + '/',
{ name: NEW_SUBJECT + NEW_SUBJECT + NEW_SUBJECT}, CREATED);
{ name: NEW_SUBJECT + NEW_SUBJECT + NEW_SUBJECT }, CREATED);
testProtectedPath('patch', STABLE_PATH + '/' + NEW_SUBJECT,
{ name: NEW_SUBJECT + NEW_SUBJECT});
{ name: NEW_SUBJECT + NEW_SUBJECT });
testProtectedPath('put', STABLE_PATH + '/' + NEW_SUBJECT,
{ name: NEW_SUBJECT + NEW_SUBJECT});
{ name: NEW_SUBJECT + NEW_SUBJECT });
testProtectedPath('delete', STABLE_PATH + '/' + NEW_SUBJECT);
});
});
Expand Down

0 comments on commit 00f6fa7

Please sign in to comment.