From eac11601c83cf881b573858f493305c9c1f3ab17 Mon Sep 17 00:00:00 2001 From: nicolaslabbe Date: Thu, 24 Nov 2016 15:04:15 +0100 Subject: [PATCH] fix: UT handlebars --- src/cli/users/manager.js | 3 +++ test/fixtures/templates/isAuthorized.html | 3 +++ test/fixtures/templates/isAuthorizedTrue.html | 3 +++ test/manager.js | 4 ++-- test/users.js | 20 +++++++++++++------ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/templates/isAuthorized.html create mode 100644 test/fixtures/templates/isAuthorizedTrue.html diff --git a/src/cli/users/manager.js b/src/cli/users/manager.js index d6388cdc..e5d1fd37 100644 --- a/src/cli/users/manager.js +++ b/src/cli/users/manager.js @@ -33,8 +33,11 @@ class Manager { if (coreUtils.file.exist(this._file)) { return JSON.parse(fs.readFileSync(this._file, 'utf8')) }else { + this._users = [] var admin = User.operations.add(config.users.default) + this.save() User.operations.activate(admin.user.id) + return JSON.parse(fs.readFileSync(this._file, 'utf8')) } } return [] diff --git a/test/fixtures/templates/isAuthorized.html b/test/fixtures/templates/isAuthorized.html new file mode 100644 index 00000000..e35f6232 --- /dev/null +++ b/test/fixtures/templates/isAuthorized.html @@ -0,0 +1,3 @@ +{{#isAuthorized '/abe' 'review'}} +test +{{/isAuthorized}} \ No newline at end of file diff --git a/test/fixtures/templates/isAuthorizedTrue.html b/test/fixtures/templates/isAuthorizedTrue.html new file mode 100644 index 00000000..d6139d83 --- /dev/null +++ b/test/fixtures/templates/isAuthorizedTrue.html @@ -0,0 +1,3 @@ +{{#isAuthorized '/abe' 'admin'}} +test +{{/isAuthorized}} \ No newline at end of file diff --git a/test/manager.js b/test/manager.js index 7bb5eec5..86ba3093 100644 --- a/test/manager.js +++ b/test/manager.js @@ -28,14 +28,14 @@ describe('Manager', function() { it('getStructureAndTemplates()', function() { const data = Manager.instance.getStructureAndTemplates() chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') - chai.assert.equal(data['templates'].length, 8, 'failed !') + chai.assert.equal(data['templates'].length, 10, 'failed !') }); it('updateStructureAndTemplates()', function() { Manager.instance.updateStructureAndTemplates() const data = Manager.instance.getStructureAndTemplates() chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') - chai.assert.equal(data['templates'].length, 8, 'failed !') + chai.assert.equal(data['templates'].length, 10, 'failed !') }); it('getList()', function() { diff --git a/test/users.js b/test/users.js index 7bc27a65..6ad190ad 100644 --- a/test/users.js +++ b/test/users.js @@ -9,11 +9,7 @@ var path = require('path'); var bcrypt = require('bcrypt-nodejs'); var Cookies = require('cookies'); var jwt = require('jwt-simple'); -// var child_process = require('child_process') -// import {Promise} from 'bluebird' -// var events = require('events') -// import which from 'which' -// const npm = which.sync('npm') +var Handlebars =require('../src/cli').Handlebars var coreUtils = require('../src/cli').coreUtils var config = require('../src/cli').config @@ -25,10 +21,22 @@ describe('users', function() { before( function() { config.users.enable = true this.fixture = { - users: JSON.parse(fs.readFileSync(__dirname + '/fixtures/users/users.json', 'utf8')), + htmlIsAuthorized: fs.readFileSync(path.join(__dirname, 'fixtures', 'templates', 'isAuthorized.html'), 'utf8'), + htmlIsAuthorizedTrue: fs.readFileSync(path.join(__dirname, 'fixtures', 'templates', 'isAuthorizedTrue.html'), 'utf8'), + users: JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'users', 'users.json'), 'utf8')) } }); + it('Handlebars.helpers.isAuthorized', function() { + var template = Handlebars.compile(this.fixture.htmlIsAuthorized) + var resHtml = template({}) + chai.expect(resHtml).to.be.equal(""); + + template = Handlebars.compile(this.fixture.htmlIsAuthorizedTrue) + resHtml = template({}) + chai.expect(resHtml).to.not.be.equal(""); + }); + it('User.utils.getUserRoutes', function(){ var sinonInstance = sinon.sandbox.create(); var role = User.utils.getUserRoutes("review")