8ef27f0590
Fixes #362 - There is no need to set the viewport on functional tests anymore unless something other than the default of 1280x1024 is desired. - There is no need to invoke `casper.run` to trigger `test.done` anymore for functional tests. - Each test works independently of the rest; registration is handled once for the lifetime of the test run and then login/logout can be invoked automatically as desired. - Mocha tests all utilize predefined, more realistic fixtures when appropriate. - Renamed old api tests that were really model tests as appropraite. - Added example api test for posts.
101 lines
2.8 KiB
JavaScript
101 lines
2.8 KiB
JavaScript
/*globals describe, it, before, beforeEach, afterEach */
|
|
var testUtils = require('./testUtils'),
|
|
should = require('should'),
|
|
errors = require('../../server/errorHandling'),
|
|
|
|
// Stuff we are testing
|
|
Models = require('../../server/models');
|
|
|
|
describe("Permission Model", function () {
|
|
|
|
var PermissionModel = Models.Permission;
|
|
|
|
should.exist(PermissionModel);
|
|
|
|
before(function (done) {
|
|
testUtils.clearData().then(function () {
|
|
done();
|
|
}, done);
|
|
});
|
|
|
|
beforeEach(function (done) {
|
|
this.timeout(5000);
|
|
testUtils.initData().then(function () {
|
|
done();
|
|
}, done);
|
|
});
|
|
|
|
afterEach(function (done) {
|
|
testUtils.clearData().then(function () {
|
|
done();
|
|
}, done);
|
|
});
|
|
|
|
it("can browse permissions", function (done) {
|
|
PermissionModel.browse().then(function (foundPermissions) {
|
|
should.exist(foundPermissions);
|
|
|
|
foundPermissions.models.length.should.be.above(0);
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
it("can read permissions", function (done) {
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
should.exist(foundPermission);
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
it("can edit permissions", function (done) {
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
should.exist(foundPermission);
|
|
|
|
return foundPermission.set({name: "updated"}).save();
|
|
}).then(function () {
|
|
return PermissionModel.read({id: 1});
|
|
}).then(function (updatedPermission) {
|
|
should.exist(updatedPermission);
|
|
|
|
updatedPermission.get("name").should.equal("updated");
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
it("can add permissions", function (done) {
|
|
var newPerm = {
|
|
name: "testperm1",
|
|
object_type: 'test',
|
|
action_type: 'test'
|
|
};
|
|
|
|
PermissionModel.add(newPerm).then(function (createdPerm) {
|
|
should.exist(createdPerm);
|
|
|
|
createdPerm.attributes.name.should.equal(newPerm.name);
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
|
|
it("can delete permissions", function (done) {
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
should.exist(foundPermission);
|
|
|
|
return PermissionModel['delete'](1);
|
|
}).then(function () {
|
|
return PermissionModel.browse();
|
|
}).then(function (foundPermissions) {
|
|
var hasRemovedId = foundPermissions.any(function (permission) {
|
|
return permission.id === 1;
|
|
});
|
|
|
|
hasRemovedId.should.equal(false);
|
|
|
|
done();
|
|
}).then(null, done);
|
|
});
|
|
}); |