Skip to content

Commit

Permalink
fix: UT handlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 24, 2016
1 parent 66249a7 commit eac1160
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/cli/users/manager.js
Expand Up @@ -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 []
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/templates/isAuthorized.html
@@ -0,0 +1,3 @@
{{#isAuthorized '/abe' 'review'}}
test
{{/isAuthorized}}
3 changes: 3 additions & 0 deletions test/fixtures/templates/isAuthorizedTrue.html
@@ -0,0 +1,3 @@
{{#isAuthorized '/abe' 'admin'}}
test
{{/isAuthorized}}
4 changes: 2 additions & 2 deletions test/manager.js
Expand Up @@ -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() {
Expand Down
20 changes: 14 additions & 6 deletions test/users.js
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit eac1160

Please sign in to comment.