2013-06-25 15:43:15 +04:00
|
|
|
/*globals describe, it, beforeEach */
|
|
|
|
var should = require('should'),
|
|
|
|
helpers = require('./helpers'),
|
2013-07-11 23:02:18 +04:00
|
|
|
errors = require('../../server/errorHandling'),
|
|
|
|
Models = require('../../server/models');
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
describe("Role Model", function () {
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
var RoleModel = Models.Role;
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
should.exist(RoleModel);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-08-25 00:51:58 +04:00
|
|
|
before(function (done) {
|
|
|
|
helpers.clearData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
beforeEach(function (done) {
|
2013-08-25 00:51:58 +04:00
|
|
|
this.timeout(5000);
|
|
|
|
helpers.initData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
helpers.clearData().then(function () {
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can browse roles", function (done) {
|
|
|
|
RoleModel.browse().then(function (foundRoles) {
|
|
|
|
should.exist(foundRoles);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
foundRoles.models.length.should.be.above(0);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can read roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can edit roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
return foundRole.set({name: "updated"}).save();
|
|
|
|
}).then(function () {
|
|
|
|
return RoleModel.read({id: 1});
|
|
|
|
}).then(function (updatedRole) {
|
|
|
|
should.exist(updatedRole);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
updatedRole.get("name").should.equal("updated");
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can add roles", function (done) {
|
|
|
|
var newRole = {
|
|
|
|
name: "test1",
|
|
|
|
description: "test1 description"
|
|
|
|
};
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
RoleModel.add(newRole).then(function (createdRole) {
|
|
|
|
should.exist(createdRole);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
createdRole.attributes.name.should.equal(newRole.name);
|
|
|
|
createdRole.attributes.description.should.equal(newRole.description);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can delete roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
return RoleModel['delete'](1);
|
|
|
|
}).then(function () {
|
|
|
|
return RoleModel.browse();
|
|
|
|
}).then(function (foundRoles) {
|
|
|
|
var hasRemovedId = foundRoles.any(function (role) {
|
|
|
|
return role.id === 1;
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
hasRemovedId.should.equal(false);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-05 07:47:11 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
describe("Permission Model", function () {
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
var PermissionModel = Models.Permission;
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
should.exist(PermissionModel);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-08-25 00:51:58 +04:00
|
|
|
before(function (done) {
|
|
|
|
helpers.clearData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
beforeEach(function (done) {
|
2013-08-25 00:51:58 +04:00
|
|
|
this.timeout(5000);
|
|
|
|
helpers.initData().then(function () {
|
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
helpers.clearData().then(function () {
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can browse permissions", function (done) {
|
|
|
|
PermissionModel.browse().then(function (foundPermissions) {
|
|
|
|
should.exist(foundPermissions);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
foundPermissions.models.length.should.be.above(0);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can read permissions", function (done) {
|
|
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
|
|
should.exist(foundPermission);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can edit permissions", function (done) {
|
|
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
|
|
should.exist(foundPermission);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
return foundPermission.set({name: "updated"}).save();
|
|
|
|
}).then(function () {
|
|
|
|
return PermissionModel.read({id: 1});
|
|
|
|
}).then(function (updatedPermission) {
|
|
|
|
should.exist(updatedPermission);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
updatedPermission.get("name").should.equal("updated");
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can add permissions", function (done) {
|
|
|
|
var newPerm = {
|
|
|
|
name: "testperm1"
|
|
|
|
};
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
PermissionModel.add(newPerm).then(function (createdPerm) {
|
|
|
|
should.exist(createdPerm);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
createdPerm.attributes.name.should.equal(newPerm.name);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
it("can delete permissions", function (done) {
|
|
|
|
PermissionModel.read({id: 1}).then(function (foundPermission) {
|
|
|
|
should.exist(foundPermission);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
return PermissionModel['delete'](1);
|
|
|
|
}).then(function () {
|
|
|
|
return PermissionModel.browse();
|
|
|
|
}).then(function (foundPermissions) {
|
|
|
|
var hasRemovedId = foundPermissions.any(function (permission) {
|
|
|
|
return permission.id === 1;
|
|
|
|
});
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
hasRemovedId.should.equal(false);
|
2013-06-05 07:47:11 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
done();
|
2013-07-11 16:50:31 +04:00
|
|
|
}).then(null, done);
|
2013-06-05 07:47:11 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|