follow tests

v1.18.x
barisusakli 8 years ago
parent 5cf8006640
commit c3980d0c2e

@ -1,9 +1,9 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
plugins = require('../plugins'), var plugins = require('../plugins');
db = require('../database'); var db = require('../database');
module.exports = function (User) { module.exports = function (User) {
@ -73,25 +73,22 @@ module.exports = function (User) {
if (!parseInt(uid, 10)) { if (!parseInt(uid, 10)) {
return callback(null, []); return callback(null, []);
} }
async.waterfall([
db.getSortedSetRevRange(type + ':' + uid, start, stop, function (err, uids) { function (next) {
if (err) { db.getSortedSetRevRange(type + ':' + uid, start, stop, next);
return callback(err); },
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);
} }
], callback);
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);
});
});
} }
User.isFollowing = function (uid, theirid, callback) { User.isFollowing = function (uid, theirid, callback) {

@ -785,7 +785,47 @@ describe('Controllers', function () {
done(); 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) { after(function (done) {

Loading…
Cancel
Save