mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
835fd6c45b
no issue - this mock eat already too much of my/our time - the idea of adding a knex mock was definitely a failed approach/try - it's too much to maintaince and have not found a module which does this already - we have to support any query format - this is too crazy - the idea was to use the knex mock for model unit tests, because if we want to unit test models we have to run through bookshelf, because the whole model layer depends on bookshelf e.g. events - for now we simply use the real database - we could use the sqlite3 memory mode, but that would mean every unit test runs on sqlite3 - something to consider for later e.g. run unit tests on one matrix - run the rest on another matrix for sqlite + mysql
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
const should = require('should'),
|
|
sinon = require('sinon'),
|
|
models = require('../../../server/models'),
|
|
testUtils = require('../../utils'),
|
|
configUtils = require('../../utils/configUtils'),
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('Unit: models/permission', function () {
|
|
before(function () {
|
|
models.init();
|
|
});
|
|
|
|
after(function () {
|
|
sandbox.restore();
|
|
configUtils.restore();
|
|
});
|
|
|
|
before(testUtils.teardown);
|
|
|
|
describe('add', function () {
|
|
beforeEach(testUtils.setup('roles'));
|
|
afterEach(testUtils.teardown);
|
|
|
|
it('without roles', function () {
|
|
return models.Permission.add({name: 'test', object_type: 'something', action_type: 'read something'})
|
|
.then(function (permission) {
|
|
permission.get('name').should.eql('test');
|
|
permission.get('object_type').should.eql('something');
|
|
permission.get('action_type').should.eql('read something');
|
|
});
|
|
});
|
|
|
|
it('with roles', function () {
|
|
return models.Permission.add({
|
|
name: 'test',
|
|
object_type: 'something',
|
|
action_type: 'write something',
|
|
roles: [testUtils.DataGenerator.forKnex.roles[1]]
|
|
}).then(function (permission) {
|
|
permission.get('name').should.eql('test');
|
|
permission.get('object_type').should.eql('something');
|
|
permission.get('action_type').should.eql('write something');
|
|
permission.related('roles').models[0].id.should.eql(testUtils.DataGenerator.forKnex.roles[1].id);
|
|
});
|
|
});
|
|
|
|
it('[error] validation', function () {
|
|
return models.Permission.add({})
|
|
.then(function () {
|
|
'Should fail'.should.be.true();
|
|
})
|
|
.catch(function (err) {
|
|
err.length.should.eql(3);
|
|
});
|
|
});
|
|
});
|
|
});
|