2013-09-06 17:07:25 +01:00
|
|
|
/*globals describe, it, before, beforeEach, afterEach */
|
|
|
|
var testUtils = require('./testUtils'),
|
|
|
|
should = require('should'),
|
2013-07-11 20:02:18 +01:00
|
|
|
errors = require('../../server/errorHandling'),
|
2013-09-06 17:07:25 +01:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2013-07-11 20:02:18 +01:00
|
|
|
Models = require('../../server/models');
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
describe("Role Model", function () {
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
var RoleModel = Models.Role;
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
should.exist(RoleModel);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-08-24 15:51:58 -05:00
|
|
|
before(function (done) {
|
2013-09-06 17:07:25 +01:00
|
|
|
testUtils.clearData().then(function () {
|
2013-08-24 15:51:58 -05:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
beforeEach(function (done) {
|
2013-09-06 17:07:25 +01:00
|
|
|
testUtils.initData().then(function () {
|
2013-08-24 15:51:58 -05:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2013-09-06 17:07:25 +01:00
|
|
|
testUtils.clearData().then(function () {
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
|
|
|
}, done);
|
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
it("can browse roles", function (done) {
|
|
|
|
RoleModel.browse().then(function (foundRoles) {
|
|
|
|
should.exist(foundRoles);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
foundRoles.models.length.should.be.above(0);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
2013-07-11 13:50:31 +01:00
|
|
|
}).then(null, done);
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
it("can read roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
2013-07-11 13:50:31 +01:00
|
|
|
}).then(null, done);
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
it("can edit roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
return foundRole.set({name: "updated"}).save();
|
|
|
|
}).then(function () {
|
|
|
|
return RoleModel.read({id: 1});
|
|
|
|
}).then(function (updatedRole) {
|
|
|
|
should.exist(updatedRole);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
updatedRole.get("name").should.equal("updated");
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
2013-07-11 13:50:31 +01:00
|
|
|
}).then(null, done);
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
it("can add roles", function (done) {
|
|
|
|
var newRole = {
|
|
|
|
name: "test1",
|
|
|
|
description: "test1 description"
|
|
|
|
};
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
RoleModel.add(newRole).then(function (createdRole) {
|
|
|
|
should.exist(createdRole);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
createdRole.attributes.name.should.equal(newRole.name);
|
|
|
|
createdRole.attributes.description.should.equal(newRole.description);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
2013-07-11 13:50:31 +01:00
|
|
|
}).then(null, done);
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
it("can delete roles", function (done) {
|
|
|
|
RoleModel.read({id: 1}).then(function (foundRole) {
|
|
|
|
should.exist(foundRole);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01: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-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
hasRemovedId.should.equal(false);
|
2013-06-04 22:47:11 -05:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
done();
|
2013-07-11 13:50:31 +01:00
|
|
|
}).then(null, done);
|
2013-06-04 22:47:11 -05:00
|
|
|
});
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|