mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
more group tests
This commit is contained in:
@@ -77,7 +77,7 @@ function isOwner(next) {
|
||||
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
||||
isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName)
|
||||
}, function (err, results) {
|
||||
if (err || (!isOwner && !results.isAdmin)) {
|
||||
if (err || (!results.isOwner && !results.isAdmin)) {
|
||||
return callback(err || new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
next(socket, data, callback);
|
||||
|
||||
@@ -536,7 +536,27 @@ describe('Groups', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject membership of user', function (done) {
|
||||
socketGroups.reject({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) {
|
||||
assert.ifError(err);
|
||||
Groups.isInvited(testUid, 'PrivateCanJoin', function (err, invited) {
|
||||
assert.ifError(err);
|
||||
assert.equal(invited, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if not owner or admin', function (done) {
|
||||
socketGroups.accept({uid: 0}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should accept membership of user', function (done) {
|
||||
socketGroups.join({uid: testUid}, {groupName: 'PrivateCanJoin'}, function (err) {
|
||||
assert.ifError(err);
|
||||
socketGroups.accept({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) {
|
||||
assert.ifError(err);
|
||||
Groups.isMember(testUid, 'PrivateCanJoin', function (err, isMember) {
|
||||
@@ -546,6 +566,62 @@ describe('Groups', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject/accept all memberships requests', function (done) {
|
||||
function requestMembership(uids, callback) {
|
||||
async.series([
|
||||
function (next) {
|
||||
socketGroups.join({uid: uids.uid1}, {groupName: 'PrivateCanJoin'}, next);
|
||||
},
|
||||
function (next) {
|
||||
socketGroups.join({uid: uids.uid2}, {groupName: 'PrivateCanJoin'}, next);
|
||||
}
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
var uids;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
uid1: function (next) {
|
||||
User.create({username: 'groupuser1'}, next);
|
||||
},
|
||||
uid2: function (next) {
|
||||
User.create({username: 'groupuser2'}, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
uids = results;
|
||||
requestMembership(results, next);
|
||||
},
|
||||
function (next) {
|
||||
socketGroups.rejectAll({uid: adminUid}, {groupName: 'PrivateCanJoin'}, next);
|
||||
},
|
||||
function (next) {
|
||||
Groups.getPending('PrivateCanJoin', next);
|
||||
},
|
||||
function (pending, next) {
|
||||
assert.equal(pending.length, 0);
|
||||
requestMembership(uids, next);
|
||||
},
|
||||
function (next) {
|
||||
socketGroups.acceptAll({uid: adminUid}, {groupName: 'PrivateCanJoin'}, next);
|
||||
},
|
||||
function (next) {
|
||||
Groups.isMembers([uids.uid1, uids.uid2], 'PrivateCanJoin', next);
|
||||
},
|
||||
function (isMembers, next) {
|
||||
assert(isMembers[0]);
|
||||
assert(isMembers[1]);
|
||||
next();
|
||||
}
|
||||
], function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should grant ownership to user', function (done) {
|
||||
socketGroups.grant({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) {
|
||||
@@ -580,6 +656,8 @@ describe('Groups', function () {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('admin socket methods', function () {
|
||||
|
||||
Reference in New Issue
Block a user