Add groups route tests

This commit is contained in:
Girish Ramakrishnan
2016-02-09 15:26:34 -08:00
parent e20b3f75e4
commit 82cf667f3b
4 changed files with 206 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
exports = module.exports = {
get: get,
getWithMembers: getWithMembers,
getAll: getAll,
add: add,
del: del,
@@ -35,6 +36,24 @@ function get(groupId, callback) {
});
}
function getWithMembers(groupId, callback) {
assert.strictEqual(typeof groupId, 'string');
assert.strictEqual(typeof callback, 'function');
database.query('SELECT ' + GROUPS_FIELDS + ',GROUP_CONCAT(groupMembers.userId) AS userIds ' +
' FROM groups LEFT OUTER JOIN groupMembers ON groups.id = groupMembers.groupId ' +
' WHERE groups.id = ? ' +
' GROUP BY groups.id', [ groupId ], function (error, results) {
if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error));
if (results.length === 0) return callback(new DatabaseError(DatabaseError.NOT_FOUND));
var result = results[0];
result.userIds = result.userIds ? result.userIds.split(',') : [ ];
callback(null, result);
});
}
function getAll(callback) {
assert.strictEqual(typeof callback, 'function');