fixing groups tests

v1.18.x
Julian Lam 11 years ago
parent 8432d8827e
commit 49a686af78

@ -78,10 +78,12 @@
return callback(err);
}
// User counts
results.base.count = numUsers || results.users.length;
results.base.members = results.users;
results.base.memberCount = numUsers || results.users.length;
results.base.slug = utils.slugify(results.base.name);
results.base.deleted = !!parseInt(results.base.deleted, 10);
results.base.hidden = !!parseInt(results.base.hidden, 10);
results.base.system = !!parseInt(results.base.system, 10);
@ -131,7 +133,20 @@
};
Groups.exists = function(name, callback) {
db.isSetMember('groups', name, callback);
name = utils.slugify(name);
db.getSetMembers('groups', function(err, groupNames) {
if (err) {
return callback(err);
}
var matches = groupNames.map(function(groupName) {
return utils.slugify(groupName);
}).filter(function(groupName) {
return groupName === name;
});
callback(null, matches.length > 0 ? true : false);
});
};
Groups.create = function(name, description, callback) {

@ -167,11 +167,12 @@ describe('Groups', function() {
});
});
it('should also check slugified name for existence', function(done) {
it('should properly resolve a non-slugified group to slugs', function(done) {
Groups.exists('Test();', function(err, exists) {
if (err) return done(err);
assert.strictEqual(exists, true);
done();
});
});
});

Loading…
Cancel
Save