0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/test/unit/models/permission_spec.js
Katharina Irrgang fb044e6d88
Bumped sinon from 4.4.6 to 7.3.2 (#10400)
refs #9389

- https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md

Breaking changes for Ghost:

- no need to create a sandbox anymore, each file get's it's own sandbox
- just require sinon and use this sandbox
- you can still create separate sandboxes with .createSandbox
- reset single stubs: use .resetHistory instead of .reset

This is a global replace for any sandbox creation.

---

From https://sinonjs.org/releases/v7.2.3/sandbox/

> Default sandbox
> Since sinon@5.0.0, the sinon object is a default sandbox. Unless you have a very advanced setup or need a special configuration, you probably want to just use that one.
2019-01-21 17:53:44 +01:00

56 lines
2 KiB
JavaScript

const should = require('should'),
sinon = require('sinon'),
models = require('../../../server/models'),
testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils');
describe('Unit: models/permission', function () {
before(function () {
models.init();
});
after(function () {
sinon.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);
});
});
});
});