Node.js based forum software built for the modern web
follow tests
barisusaklic3980d0c2ef4
diff --git a/src/user/follow.js b/src/user/follow.jsindex 0812c1004d..e6c9624018 100644--- a/src/user/follow.js+++ b/src/user/follow.js@@ -1,9 +1,9 @@'use strict';-var async = require('async'),- plugins = require('../plugins'),- db = require('../database');+var async = require('async');+var plugins = require('../plugins');+var db = require('../database');module.exports = function (User) {@@ -73,25 +73,22 @@ module.exports = function (User) {if (!parseInt(uid, 10)) {return callback(null, []);}-- db.getSortedSetRevRange(type + ':' + uid, start, stop, function (err, uids) {- if (err) {- return callback(err);+ async.waterfall([+ function (next) {+ db.getSortedSetRevRange(type + ':' + uid, start, stop, next);+ },+ function (uids, next) {+ plugins.fireHook('filter:user.' + type, {+ uids: uids,+ uid: uid,+ start: start,+ stop: stop+ }, next);+ },+ function (data, next) {+ User.getUsers(data.uids, uid, next);}-- plugins.fireHook('filter:user.' + type, {- uids: uids,- uid: uid,- start: start,- stop: stop- }, function (err, data) {- if (err) {- return callback(err);- }-- User.getUsers(data.uids, uid, callback);- });- });+ ], callback);}User.isFollowing = function (uid, theirid, callback) {diff --git a/test/controllers.js b/test/controllers.jsindex 04bbf26c1b..03d7d38e11 100644--- a/test/controllers.js+++ b/test/controllers.js@@ -785,7 +785,47 @@ describe('Controllers', function () {done();});});+ });++ describe('account follow page', function () {+ var uid;+ before(function (done) {+ user.create({username: 'follower'}, function (err, _uid) {+ assert.ifError(err);+ uid = _uid;+ user.follow(uid, fooUid, done);+ });+ });++ it('should get followers page', function (done) {+ request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {+ assert.ifError(err);+ assert.equal(res.statusCode, 200);+ assert.equal(body.users[0].username, 'follower');+ done();+ });+ });++ it('should get following page', function (done) {+ request(nconf.get('url') + '/api/user/follower/following', {json: true}, function (err, res, body) {+ assert.ifError(err);+ assert.equal(res.statusCode, 200);+ assert.equal(body.users[0].username, 'foo');+ done();+ });+ });+ it('should return empty after unfollow', function (done ) {+ user.unfollow(uid, fooUid, function (err) {+ assert.ifError(err);+ request(nconf.get('url') + '/api/user/foo/followers', {json: true}, function (err, res, body) {+ assert.ifError(err);+ assert.equal(res.statusCode, 200);+ assert.equal(body.users.length, 0);+ done();+ });+ });+ });});after(function (done) {