diff --git a/Module2/Demo/controllers/auth.controller.js b/Module2/Demo/controllers/auth.controller.js index f34ed63..61120f5 100644 --- a/Module2/Demo/controllers/auth.controller.js +++ b/Module2/Demo/controllers/auth.controller.js @@ -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); } diff --git a/Module2/Demo/package.json b/Module2/Demo/package.json index d976d51..dbd806d 100644 --- a/Module2/Demo/package.json +++ b/Module2/Demo/package.json @@ -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" } } diff --git a/Module2/Demo/test/controllers/auth.controller.spec.js b/Module2/Demo/test/controllers/auth.controller.spec.js index d6b0535..eed8543 100644 --- a/Module2/Demo/test/controllers/auth.controller.spec.js +++ b/Module2/Demo/test/controllers/auth.controller.spec.js @@ -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) + }) }) }) - -}); \ No newline at end of file +}) diff --git a/Module2/Demo/test/starting.spec.js b/Module2/Demo/test/starting.spec.js index 9d45dcc..81f8d33 100644 --- a/Module2/Demo/test/starting.spec.js +++ b/Module2/Demo/test/starting.spec.js @@ -3,6 +3,5 @@ var assert = require('assert'); describe('Basic Mocha Test', function () { it('should throw errors', function () { - }) }); \ No newline at end of file