/
model_permissions_spec.js
100 lines (76 loc) · 2.73 KB
/
model_permissions_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*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) {
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);
});
});