From f4a6527ce6e54b8d9e6c202cc5ef71e8e05fd5a9 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 10 Feb 2017 15:26:17 +0300 Subject: [PATCH] getRecentPosterUids test --- src/posts/recent.js | 14 +++++++------- test/posts.js | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/posts/recent.js b/src/posts/recent.js index aec0ea4637..5cc5cd1fae 100644 --- a/src/posts/recent.js +++ b/src/posts/recent.js @@ -1,8 +1,8 @@ 'use strict'; -var async = require('async'), - db = require('../database'), - privileges = require('../privileges'); +var async = require('async'); +var db = require('../database'); +var privileges = require('../privileges'); module.exports = function (Posts) { @@ -42,12 +42,12 @@ module.exports = function (Posts) { Posts.getPostsFields(pids, ['uid'], next); }, function (postData, next) { - postData = postData.map(function (post) { + var uids = postData.map(function (post) { return post && post.uid; - }).filter(function (value, index, array) { - return value && array.indexOf(value) === index; + }).filter(function (uid, index, array) { + return uid && array.indexOf(uid) === index; }); - next(null, postData); + next(null, uids); } ], callback); }; diff --git a/test/posts.js b/test/posts.js index 5a4f2cdda7..84b5934724 100644 --- a/test/posts.js +++ b/test/posts.js @@ -737,6 +737,24 @@ describe('Post\'s', function () { }); }); + it('should get recent poster uids', function (done) { + topics.reply({ + uid: voterUid, + tid: topicData.tid, + timestamp: Date.now(), + content: 'some content' + }, function (err) { + assert.ifError(err); + posts.getRecentPosterUids(0, 1, function (err, uids) { + assert.ifError(err); + assert(Array.isArray(uids)); + assert.equal(uids.length, 2); + assert.equal(uids[0], voterUid); + done(); + }); + }); + }); + after(function (done) { db.emptydb(done); });