diff --git a/src/flags.js b/src/flags.js index b88dac6b2f..8be774b467 100644 --- a/src/flags.js +++ b/src/flags.js @@ -126,7 +126,9 @@ Flags.getTarget = function (type, id, uid, callback) { break; case 'user': - user.getUsersData(id, callback); + user.getUsersData([id], function (err, users) { + callback(err, users ? users[0] : undefined); + }); break; } }; diff --git a/test/flags.js b/test/flags.js index ed879fba49..c5e69aa973 100644 --- a/test/flags.js +++ b/test/flags.js @@ -101,6 +101,48 @@ describe('Flags', function () { }); }); + describe('.getTarget()', function() { + it('should return a post\'s data if queried with type "post"', function (done) { + Flags.getTarget('post', 1, 1, function (err, data) { + assert.ifError(err); + var compare = { + uid: 1, + pid: 1, + content: 'This is flaggable content' + }; + + for(var key in compare) { + if (compare.hasOwnProperty(key)) { + assert.ok(data[key]); + assert.strictEqual(data[key], compare[key]); + } + } + + done(); + }); + }); + + it('should return a user\'s data if queried with type "user"', function (done) { + Flags.getTarget('user', 1, 1, function (err, data) { + assert.ifError(err); + var compare = { + uid: 1, + username: 'testUser', + email: 'b@c.com' + }; + + for(var key in compare) { + if (compare.hasOwnProperty(key)) { + assert.ok(data[key]); + assert.strictEqual(data[key], compare[key]); + } + } + + done(); + }); + }); + });; + after(function (done) { db.emptydb(done); });