mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
controllers/category tests
This commit is contained in:
@@ -271,16 +271,14 @@ var privileges = require('./privileges');
|
|||||||
|
|
||||||
Categories.flattenCategories = function (allCategories, categoryData) {
|
Categories.flattenCategories = function (allCategories, categoryData) {
|
||||||
categoryData.forEach(function (category) {
|
categoryData.forEach(function (category) {
|
||||||
if (!category) {
|
if (category) {
|
||||||
return;
|
if (!category.parent) {
|
||||||
}
|
allCategories.push(category);
|
||||||
|
}
|
||||||
|
|
||||||
if (!category.parent) {
|
if (Array.isArray(category.children) && category.children.length) {
|
||||||
allCategories.push(category);
|
Categories.flattenCategories(allCategories, category.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(category.children) && category.children.length) {
|
|
||||||
Categories.flattenCategories(allCategories, category.children);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ module.exports = function (Categories) {
|
|||||||
post_count: 0,
|
post_count: 0,
|
||||||
disabled: 0,
|
disabled: 0,
|
||||||
order: order,
|
order: order,
|
||||||
link: '',
|
link: data.link || '',
|
||||||
numRecentReplies: 1,
|
numRecentReplies: 1,
|
||||||
class: (data.class ? data.class : 'col-md-3 col-xs-6'),
|
class: (data.class ? data.class : 'col-md-3 col-xs-6'),
|
||||||
imageClass: 'cover',
|
imageClass: 'cover',
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var helpers = require('./helpers');
|
|||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
|
|
||||||
var categoryController = {};
|
var categoryController = module.exports;
|
||||||
|
|
||||||
categoryController.get = function (req, res, callback) {
|
categoryController.get = function (req, res, callback) {
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
@@ -129,97 +129,102 @@ categoryController.get = function (req, res, callback) {
|
|||||||
|
|
||||||
if (categoryData.link) {
|
if (categoryData.link) {
|
||||||
db.incrObjectField('category:' + categoryData.cid, 'timesClicked');
|
db.incrObjectField('category:' + categoryData.cid, 'timesClicked');
|
||||||
return res.redirect(categoryData.link);
|
return helpers.redirect(res, categoryData.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
var breadcrumbs = [
|
buildBreadcrumbs(categoryData, next);
|
||||||
{
|
|
||||||
text: categoryData.name,
|
|
||||||
url: nconf.get('relative_path') + '/category/' + categoryData.slug,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, function (err, crumbs) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
|
|
||||||
next(null, categoryData);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
function (categoryData, next) {
|
||||||
if (!categoryData.children.length) {
|
if (!categoryData.children.length) {
|
||||||
return next(null, categoryData);
|
return next(null, categoryData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var allCategories = [];
|
var allCategories = [];
|
||||||
categories.flattenCategories(allCategories, categoryData.children);
|
categories.flattenCategories(allCategories, categoryData.children);
|
||||||
categories.getRecentTopicReplies(allCategories, req.uid, function (err) {
|
categories.getRecentTopicReplies(allCategories, req.uid, function (err) {
|
||||||
next(err, categoryData);
|
next(err, categoryData);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
], function (err, categoryData) {
|
function (categoryData) {
|
||||||
if (err) {
|
categoryData.description = translator.escape(categoryData.description);
|
||||||
return callback(err);
|
categoryData.privileges = userPrivileges;
|
||||||
}
|
categoryData.showSelect = categoryData.privileges.editable;
|
||||||
|
|
||||||
categoryData.description = translator.escape(categoryData.description);
|
addTags(categoryData, res);
|
||||||
categoryData.privileges = userPrivileges;
|
|
||||||
categoryData.showSelect = categoryData.privileges.editable;
|
|
||||||
|
|
||||||
res.locals.metaTags = [
|
if (parseInt(req.uid, 10)) {
|
||||||
{
|
categories.markAsRead([cid], req.uid);
|
||||||
name: 'title',
|
}
|
||||||
content: categoryData.name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:title',
|
|
||||||
content: categoryData.name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'description',
|
|
||||||
content: categoryData.description,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:type',
|
|
||||||
content: 'website',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (categoryData.backgroundImage) {
|
categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
||||||
res.locals.metaTags.push({
|
categoryData.rssFeedUrl = nconf.get('relative_path') + '/category/' + categoryData.cid + '.rss';
|
||||||
name: 'og:image',
|
categoryData.title = translator.escape(categoryData.name);
|
||||||
content: categoryData.backgroundImage,
|
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
|
||||||
|
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
|
||||||
|
categoryData.pagination.rel.forEach(function (rel) {
|
||||||
|
rel.href = nconf.get('url') + '/category/' + categoryData.slug + rel.href;
|
||||||
|
res.locals.linkTags.push(rel);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
res.locals.linkTags = [
|
res.render('category', categoryData);
|
||||||
{
|
},
|
||||||
rel: 'alternate',
|
], callback);
|
||||||
type: 'application/rss+xml',
|
|
||||||
href: nconf.get('url') + '/category/' + cid + '.rss',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rel: 'up',
|
|
||||||
href: nconf.get('url'),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (parseInt(req.uid, 10)) {
|
|
||||||
categories.markAsRead([cid], req.uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
|
||||||
categoryData.rssFeedUrl = nconf.get('relative_path') + '/category/' + categoryData.cid + '.rss';
|
|
||||||
categoryData.title = translator.escape(categoryData.name);
|
|
||||||
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
|
|
||||||
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
|
|
||||||
categoryData.pagination.rel.forEach(function (rel) {
|
|
||||||
rel.href = nconf.get('url') + '/category/' + categoryData.slug + rel.href;
|
|
||||||
res.locals.linkTags.push(rel);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.render('category', categoryData);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function buildBreadcrumbs(categoryData, callback) {
|
||||||
|
var breadcrumbs = [
|
||||||
|
{
|
||||||
|
text: categoryData.name,
|
||||||
|
url: nconf.get('relative_path') + '/category/' + categoryData.slug,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
helpers.buildCategoryBreadcrumbs(categoryData.parentCid, next);
|
||||||
|
},
|
||||||
|
function (crumbs, next) {
|
||||||
|
categoryData.breadcrumbs = crumbs.concat(breadcrumbs);
|
||||||
|
next(null, categoryData);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = categoryController;
|
function addTags(categoryData, res) {
|
||||||
|
res.locals.metaTags = [
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
content: categoryData.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:title',
|
||||||
|
content: categoryData.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
content: categoryData.description,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:type',
|
||||||
|
content: 'website',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (categoryData.backgroundImage) {
|
||||||
|
res.locals.metaTags.push({
|
||||||
|
name: 'og:image',
|
||||||
|
content: categoryData.backgroundImage,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.locals.linkTags = [
|
||||||
|
{
|
||||||
|
rel: 'alternate',
|
||||||
|
type: 'application/rss+xml',
|
||||||
|
href: nconf.get('url') + '/category/' + categoryData.cid + '.rss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rel: 'up',
|
||||||
|
href: nconf.get('url'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,12 +12,15 @@ var user = require('../src/user');
|
|||||||
var groups = require('../src/groups');
|
var groups = require('../src/groups');
|
||||||
var meta = require('../src/meta');
|
var meta = require('../src/meta');
|
||||||
var translator = require('../src/translator');
|
var translator = require('../src/translator');
|
||||||
|
var privileges = require('../src/privileges');
|
||||||
|
var helpers = require('./helpers');
|
||||||
|
|
||||||
describe('Controllers', function () {
|
describe('Controllers', function () {
|
||||||
var tid;
|
var tid;
|
||||||
var cid;
|
var cid;
|
||||||
var pid;
|
var pid;
|
||||||
var fooUid;
|
var fooUid;
|
||||||
|
var category;
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
groups.resetCache();
|
groups.resetCache();
|
||||||
@@ -41,6 +44,7 @@ describe('Controllers', function () {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
category = results.category;
|
||||||
cid = results.category.cid;
|
cid = results.category.cid;
|
||||||
fooUid = results.user;
|
fooUid = results.user;
|
||||||
|
|
||||||
@@ -586,7 +590,7 @@ describe('Controllers', function () {
|
|||||||
var uid;
|
var uid;
|
||||||
var jar;
|
var jar;
|
||||||
var csrf_token;
|
var csrf_token;
|
||||||
var helpers = require('./helpers');
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
user.create({ username: 'revokeme', password: 'barbar' }, function (err, _uid) {
|
user.create({ username: 'revokeme', password: 'barbar' }, function (err, _uid) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
@@ -791,7 +795,6 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('account pages', function () {
|
describe('account pages', function () {
|
||||||
var helpers = require('./helpers');
|
|
||||||
var jar;
|
var jar;
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
helpers.loginUser('foo', 'barbar', function (err, _jar) {
|
helpers.loginUser('foo', 'barbar', function (err, _jar) {
|
||||||
@@ -811,7 +814,7 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should 404 if uid is not a number', function (done) {
|
it('should 404 if uid is not a number', function (done) {
|
||||||
request(nconf.get('url') + '/api/uid/test', { json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/uid/test', { json: true }, function (err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 404);
|
assert.equal(res.statusCode, 404);
|
||||||
done();
|
done();
|
||||||
@@ -828,7 +831,7 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should 404 if user does not exist', function (done) {
|
it('should 404 if user does not exist', function (done) {
|
||||||
request(nconf.get('url') + '/api/uid/123123', { json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/uid/123123', { json: true }, function (err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 404);
|
assert.equal(res.statusCode, 404);
|
||||||
done();
|
done();
|
||||||
@@ -836,7 +839,7 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should 401 if user is not logged in', function (done) {
|
it('should 401 if user is not logged in', function (done) {
|
||||||
request(nconf.get('url') + '/api/admin', { json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/admin', { json: true }, function (err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 401);
|
assert.equal(res.statusCode, 401);
|
||||||
done();
|
done();
|
||||||
@@ -844,7 +847,7 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should 403 if user is not admin', function (done) {
|
it('should 403 if user is not admin', function (done) {
|
||||||
request(nconf.get('url') + '/api/admin', { jar: jar, json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/admin', { jar: jar, json: true }, function (err, res) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 403);
|
assert.equal(res.statusCode, 403);
|
||||||
done();
|
done();
|
||||||
@@ -1307,6 +1310,260 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('category', function () {
|
||||||
|
var jar;
|
||||||
|
before(function (done) {
|
||||||
|
helpers.loginUser('foo', 'barbar', function (err, _jar) {
|
||||||
|
assert.ifError(err);
|
||||||
|
jar = _jar;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 404 if cid is not a number', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/category/fail', function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 404 if topic index is not a number', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '/invalidtopicindex', function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should 404 if category does not exist', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/category/123123', function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should 404 if category is disabled', function (done) {
|
||||||
|
categories.create({ name: 'disabled' }, function (err, category) {
|
||||||
|
assert.ifError(err);
|
||||||
|
categories.setCategoryField(category.cid, 'disabled', 1, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug, function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 401 if not allowed to read', function (done) {
|
||||||
|
categories.create({ name: 'hidden' }, function (err, category) {
|
||||||
|
assert.ifError(err);
|
||||||
|
privileges.categories.rescind(['read'], category.cid, 'guests', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug, function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 401);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should redirect if topic index is negative', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '/-10', function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 308);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should 404 if page is not found', function (done) {
|
||||||
|
user.setSetting(fooUid, 'usePagination', 1, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '?page=100', { jar: jar, json: true }, function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should load page 1 if req.query.page is not sent', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug, { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.pagination.currentPage, 1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sort topics by most posts', function (done) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'most-posts-category' }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: 'topic 1', content: 'topic 1 OP' }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: 'topic 2', content: 'topic 2 OP' }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
topics.reply({ uid: fooUid, content: 'topic 2 reply', tid: data.topicData.tid }, next);
|
||||||
|
},
|
||||||
|
function (postData, next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '?sort=most_posts', { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.topics[0].title, 'topic 2');
|
||||||
|
assert.equal(body.topics[0].postcount, 2);
|
||||||
|
assert.equal(body.topics[1].postcount, 1);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should load a specific users topics from a category with tags', function (done) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'filtered-category' }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: 'topic 1', content: 'topic 1 OP', tags: ['java', 'cpp'] }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: 'topic 2', content: 'topic 2 OP', tags: ['node', 'javascript'] }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: 'topic 3', content: 'topic 3 OP', tags: ['java', 'cpp', 'best'] }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '?tag=node&author=foo', { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.topics[0].title, 'topic 2');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug + '?tag[]=java&tag[]=cpp', { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.topics[0].title, 'topic 3');
|
||||||
|
assert.equal(body.topics[1].title, 'topic 1');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should redirect if category is a link', function (done) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'redirect', link: 'https://nodebb.org' }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug, { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 308);
|
||||||
|
assert.equal(body, 'https://nodebb.org');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get recent topic replies from children categories', function (done) {
|
||||||
|
var parentCategory;
|
||||||
|
var childCategory1;
|
||||||
|
var childCategory2;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'parent category', backgroundImage: 'path/to/some/image' }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
parentCategory = category;
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'child category 1', parentCid: category.cid }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
childCategory1 = category;
|
||||||
|
categories.create({ name: 'child category 2', parentCid: parentCategory.cid }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
childCategory2 = category;
|
||||||
|
topics.post({ uid: fooUid, cid: childCategory2.cid, title: 'topic 1', content: 'topic 1 OP' }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + parentCategory.slug, { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.children[1].posts[0].content, 'topic 1 OP');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create 2 pages of topics', function (done) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.create({ name: 'category with 2 pages' }, next);
|
||||||
|
},
|
||||||
|
function (category, next) {
|
||||||
|
var titles = [];
|
||||||
|
for (var i = 0; i < 30; i++) {
|
||||||
|
titles.push('topic title ' + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
async.eachSeries(titles, function (title, next) {
|
||||||
|
topics.post({ uid: fooUid, cid: category.cid, title: title, content: 'does not really matter' }, next);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
user.getSettings(fooUid, next);
|
||||||
|
},
|
||||||
|
function (settings, next) {
|
||||||
|
request(nconf.get('url') + '/api/category/' + category.slug, { jar: jar, json: true }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body.topics.length, settings.topicsPerPage);
|
||||||
|
assert.equal(body.pagination.pageCount, 2);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], function (err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
], done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
after(function (done) {
|
after(function (done) {
|
||||||
var analytics = require('../src/analytics');
|
var analytics = require('../src/analytics');
|
||||||
analytics.writeData(function (err) {
|
analytics.writeData(function (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user