mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
category tests
This commit is contained in:
@@ -12,6 +12,7 @@ var Categories = require('../src/categories');
|
||||
var Topics = require('../src/topics');
|
||||
var User = require('../src/user');
|
||||
var groups = require('../src/groups');
|
||||
var privileges = require('../src/privileges');
|
||||
|
||||
describe('Categories', function () {
|
||||
var categoryObj;
|
||||
@@ -312,7 +313,7 @@ describe('Categories', function () {
|
||||
var socketCategories = require('../src/socket.io/admin/categories');
|
||||
var cid;
|
||||
before(function (done) {
|
||||
Categories.create({
|
||||
socketCategories.create({uid: adminUid}, {
|
||||
name: 'update name',
|
||||
description: 'update description',
|
||||
parentCid: categoryObj.cid,
|
||||
@@ -388,6 +389,137 @@ describe('Categories', function () {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all categories', function (done) {
|
||||
socketCategories.getAll({uid: adminUid}, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all category names', function (done) {
|
||||
socketCategories.getNames({uid: adminUid}, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should give privilege', function (done) {
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: categoryObj.cid, privilege: ['groups:topics:delete'], set: true, member: 'registered-users'}, function (err) {
|
||||
assert.ifError(err);
|
||||
privileges.categories.can('topics:delete', categoryObj.cid, posterUid, function (err, canDeleteTopcis) {
|
||||
assert.ifError(err);
|
||||
assert(canDeleteTopcis);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove privilege', function (done) {
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: categoryObj.cid, privilege: 'groups:topics:delete', set: false, member: 'registered-users'}, function (err) {
|
||||
assert.ifError(err);
|
||||
privileges.categories.can('topics:delete', categoryObj.cid, posterUid, function (err, canDeleteTopcis) {
|
||||
assert.ifError(err);
|
||||
assert(!canDeleteTopcis);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get privilege settings', function (done) {
|
||||
socketCategories.getPrivilegeSettings({uid: adminUid}, categoryObj.cid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should copy privileges to children', function (done) {
|
||||
var parentCid;
|
||||
var child1Cid;
|
||||
var child2Cid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent'}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1', parentCid: parentCid}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
Categories.create({name: 'child2', parentCid: child1Cid}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child2Cid = category.cid;
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users'}, next);
|
||||
},
|
||||
function (next) {
|
||||
socketCategories.copyPrivilegesToChildren({uid: adminUid}, parentCid, next);
|
||||
},
|
||||
function (next) {
|
||||
privileges.categories.can('topics:delete', child2Cid, posterUid, next);
|
||||
},
|
||||
function (canDelete, next) {
|
||||
assert(canDelete);
|
||||
next();
|
||||
}
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should copy settings from', function (done) {
|
||||
var child1Cid;
|
||||
var parentCid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent', description: 'copy me'}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1'}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
socketCategories.copySettingsFrom({uid: adminUid}, {fromCid: parentCid, toCid: child1Cid}, next);
|
||||
},
|
||||
function (canDelete, next) {
|
||||
Categories.getCategoryField(child1Cid, 'description', next);
|
||||
},
|
||||
function (description, next) {
|
||||
assert.equal(description, 'copy me');
|
||||
next();
|
||||
}
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should copy privileges from', function (done) {
|
||||
var child1Cid;
|
||||
var parentCid;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Categories.create({name: 'parent', description: 'copy me'}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
parentCid = category.cid;
|
||||
Categories.create({name: 'child1'}, next);
|
||||
},
|
||||
function (category, next) {
|
||||
child1Cid = category.cid;
|
||||
socketCategories.setPrivilege({uid: adminUid}, {cid: parentCid, privilege: 'groups:topics:delete', set: true, member: 'registered-users'}, next);
|
||||
},
|
||||
function (next) {
|
||||
socketCategories.copyPrivilegesFrom({uid: adminUid}, {fromCid: parentCid, toCid: child1Cid}, next);
|
||||
},
|
||||
function (next) {
|
||||
privileges.categories.can('topics:delete', child1Cid, posterUid, next);
|
||||
},
|
||||
function (canDelete, next) {
|
||||
assert(canDelete);
|
||||
next();
|
||||
}
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should get active users', function (done) {
|
||||
|
||||
Reference in New Issue
Block a user