Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Module2/Demo/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function AuthController(){
function isAuthorized(neededRole){
return roles.indexOf(neededRole) >= 0;
}

function isAuthorizedAsync(neededRole, cb){
setTimeout(function(){cb(roles.indexOf(neededRole) >= 0)}, 0);
}
Expand Down
12 changes: 7 additions & 5 deletions Module2/Demo/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "code",
"name": "mod2",
"version": "1.0.0",
"description": "",
"description": "package.json for mod 2\u001b[D\u001b[Dule",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha './test/**/*.spec.js'"
"test": "mocha ./test/**/*.spec.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"chai": "3.5.0",
"mocha": "3.2.0"
"mocha": "^3.4.2"
}
}
65 changes: 37 additions & 28 deletions Module2/Demo/test/controllers/auth.controller.spec.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
var assert = require('assert');
var authController = require('../../controllers/auth.controller');



describe('AuthController', function () {
beforeEach(function settingUpRoles() {
console.log('running before each');
authController.setRoles(['user']);
let assert = require('assert');
let authController = require('../../controllers/auth.controller');
// import * as auth from '../../controllers/auth.controller'

describe('AuthController', () => {
beforeEach(function settingUpRoles () {
// console.log('running before each test');
authController.setRoles(['user'])
});

describe('isAuthorized', function () {

it('Should return false if not authorized', function () {
///////////////////// example of a bad beforeEach function //////////////
// beforeEach('this function may throw bad errors', function () {
// throw({error: 'error'})
// })
describe('isAuthorized', () => {
it('should return false if not authorized', () => {
assert.equal(false, authController.isAuthorized('admin'));
})
it('Should return true if authorized', function () {
authController.setRoles(['user', 'admin']);
});

it('should return true if authorized', () => {
authController.setRoles(['user', 'admin'])
assert.equal(true, authController.isAuthorized('admin'));
})
it('should not allow a get if not authorized');
it('should allow get if authorized');
});

// Setting up a test that will register as pending
it('should not allow a get if not authorized')
it('should allow a get if authorized')
})
describe('isAuthorizedAsync', function () {

it('Should return false if not authorized', function (done) {
authController.isAuthorizedAsync('admin',
function (isAuth) {
assert.equal(false, isAuth);
done();
});
describe('isAuthorizedAsync', () => {
it('should return false if not authorized', (done) => {
authController.setRoles(['user']);
authController.isAuthorizedAsync('admin', function (isAuth) {
assert.equal(false, isAuth);
done();
});
});

it.skip('should return true if authorized', function (done) {
authController.setRoles(['user', 'admin']);
authController.isAuthorizedAsync('admin', function (isAuth) {
assert(true, isAuth)
})
})
})

});
})
1 change: 0 additions & 1 deletion Module2/Demo/test/starting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ var assert = require('assert');
describe('Basic Mocha Test', function () {
it('should throw errors', function () {


})
});