parseInt data.hidden add tests

v1.18.x
Baris Usakli 7 years ago
parent 3340db9636
commit ecc2b9560d

@ -8,13 +8,14 @@ var db = require('../database');
module.exports = function (Groups) {
Groups.create = function (data, callback) {
var system = isSystemGroup(data);
var isSystem = isSystemGroup(data);
var groupData;
var timestamp = data.timestamp || Date.now();
var disableJoinRequests = parseInt(data.disableJoinRequests, 10) === 1 ? 1 : 0;
if (data.name === 'administrators') {
disableJoinRequests = 1;
}
var isHidden = parseInt(data.hidden, 10) === 1;
async.waterfall([
function (next) {
validateGroupName(data.name, next);
@ -38,8 +39,8 @@ module.exports = function (Groups) {
description: data.description || '',
memberCount: memberCount,
deleted: 0,
hidden: parseInt(data.hidden, 10) === 1 ? 1 : 0,
system: system ? 1 : 0,
hidden: isHidden ? 1 : 0,
system: isSystem ? 1 : 0,
private: isPrivate,
disableJoinRequests: disableJoinRequests,
};
@ -58,7 +59,7 @@ module.exports = function (Groups) {
groupData.ownerUid = data.ownerUid;
}
if (!data.hidden && !system) {
if (!isHidden && !isSystem) {
tasks.push(async.apply(db.sortedSetAdd, 'groups:visible:createtime', timestamp, groupData.name));
tasks.push(async.apply(db.sortedSetAdd, 'groups:visible:memberCount', groupData.memberCount, groupData.name));
tasks.push(async.apply(db.sortedSetAdd, 'groups:visible:name', 0, groupData.name.toLowerCase() + ':' + groupData.name));

@ -265,6 +265,47 @@ describe('Groups', function () {
});
});
it('should create a hidden group if hidden is 1', function (done) {
Groups.create({
name: 'hidden group',
hidden: '1',
}, function (err) {
assert.ifError(err);
db.isSortedSetMember('groups:visible:memberCount', 'visible group', function (err, isMember) {
assert.ifError(err);
assert(!isMember);
done();
});
});
});
it('should create a visible group if hidden is 0', function (done) {
Groups.create({
name: 'visible group',
hidden: '0',
}, function (err) {
assert.ifError(err);
db.isSortedSetMember('groups:visible:memberCount', 'visible group', function (err, isMember) {
assert.ifError(err);
assert(isMember);
done();
});
});
});
it('should create a visible group if hidden is not passed in', function (done) {
Groups.create({
name: 'visible group 2',
}, function (err) {
assert.ifError(err);
db.isSortedSetMember('groups:visible:memberCount', 'visible group 2', function (err, isMember) {
assert.ifError(err);
assert(isMember);
done();
});
});
});
it('should fail to create group with duplicate group name', function (done) {
Groups.create({ name: 'foo' }, function (err) {
assert(err);

Loading…
Cancel
Save