account/posts controller tests

v1.18.x
barisusakli 8 years ago
parent a4ebb7f56e
commit 02aadf79b5

@ -97,56 +97,63 @@ postsController.getTopics = function (req, res, next) {
getFromUserSet(data, req, res, next);
};
function getFromUserSet(data, req, res, next) {
async.parallel({
settings: function (next) {
user.getSettings(req.uid, next);
function getFromUserSet(data, req, res, callback) {
var userData;
var itemsPerPage;
var page = Math.max(1, parseInt(req.query.page, 10) || 1);
async.waterfall([
function (next) {
async.parallel({
settings: function (next) {
user.getSettings(req.uid, next);
},
userData: function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
}
}, next);
},
userData: function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
}
}, function (err, results) {
if (err || !results.userData) {
return next(err);
}
function (results, next) {
if (!results.userData) {
return callback();
}
var userData = results.userData;
userData = results.userData;
var setName = 'uid:' + userData.uid + ':' + data.set;
var setName = 'uid:' + userData.uid + ':' + data.set;
var page = Math.max(1, parseInt(req.query.page, 10) || 1);
var itemsPerPage = (data.template === 'account/topics' || data.template === 'account/watched') ? results.settings.topicsPerPage : results.settings.postsPerPage;
itemsPerPage = (data.template === 'account/topics' || data.template === 'account/watched') ? results.settings.topicsPerPage : results.settings.postsPerPage;
async.parallel({
itemCount: function (next) {
if (results.settings.usePagination) {
db.sortedSetCard(setName, next);
} else {
next(null, 0);
async.parallel({
itemCount: function (next) {
if (results.settings.usePagination) {
db.sortedSetCard(setName, next);
} else {
next(null, 0);
}
},
data: function (next) {
var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1;
data.method(setName, req.uid, start, stop, next);
}
},
data: function (next) {
var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1;
data.method(setName, req.uid, start, stop, next);
}
}, function (err, results) {
if (err) {
return next(err);
}
}, next);
}
], function (err, results) {
if (err) {
return callback(err);
}
userData[data.type] = results.data[data.type];
userData.nextStart = results.data.nextStart;
userData[data.type] = results.data[data.type];
userData.nextStart = results.data.nextStart;
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount);
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount);
userData.noItemsFoundKey = data.noItemsFoundKey;
userData.title = '[[pages:' + data.template + ', ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: data.crumb}]);
userData.noItemsFoundKey = data.noItemsFoundKey;
userData.title = '[[pages:' + data.template + ', ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: data.crumb}]);
res.render(data.template, userData);
});
res.render(data.template, userData);
});
}

@ -703,6 +703,91 @@ describe('Controllers', function () {
});
});
describe('account post pages', function () {
var helpers = require('./helpers');
var jar;
before(function (done) {
helpers.loginUser('foo', 'barbar', function (err, _jar) {
assert.ifError(err);
jar = _jar;
done();
});
});
it('should load /user/foo/posts', function (done) {
request(nconf.get('url') + '/api/user/foo/posts', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should 401 if not logged in', function (done) {
request(nconf.get('url') + '/api/user/foo/bookmarks', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 401);
assert(body);
done();
});
});
it('should load /user/foo/bookmarks', function (done) {
request(nconf.get('url') + '/api/user/foo/bookmarks', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/upvoted', function (done) {
request(nconf.get('url') + '/api/user/foo/upvoted', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/downvoted', function (done) {
request(nconf.get('url') + '/api/user/foo/downvoted', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/best', function (done) {
request(nconf.get('url') + '/api/user/foo/best', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/watched', function (done) {
request(nconf.get('url') + '/api/user/foo/watched', {jar: jar}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load /user/foo/topics', function (done) {
request(nconf.get('url') + '/api/user/foo/topics', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
});
after(function (done) {
var analytics = require('../src/analytics');
analytics.writeData(function (err) {

Loading…
Cancel
Save