mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
unread tests
This commit is contained in:
@@ -55,11 +55,7 @@ unreadController.get = function (req, res, next) {
|
|||||||
cutoff: cutoff,
|
cutoff: cutoff,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
], function (err, data) {
|
function (data) {
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
|
data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
|
||||||
data.pagination = pagination.create(page, data.pageCount, req.query);
|
data.pagination = pagination.create(page, data.pageCount, req.query);
|
||||||
|
|
||||||
@@ -100,21 +96,25 @@ unreadController.get = function (req, res, next) {
|
|||||||
data.querystring = cid ? ('?cid=' + validator.escape(String(cid))) : '';
|
data.querystring = cid ? ('?cid=' + validator.escape(String(cid))) : '';
|
||||||
|
|
||||||
res.render('unread', data);
|
res.render('unread', data);
|
||||||
});
|
},
|
||||||
|
], next);
|
||||||
};
|
};
|
||||||
|
|
||||||
unreadController.unreadTotal = function (req, res, next) {
|
unreadController.unreadTotal = function (req, res, next) {
|
||||||
var filter = req.params.filter || '';
|
var filter = req.params.filter || '';
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
plugins.fireHook('filter:unread.getValidFilters', { filters: validFilter }, next);
|
||||||
|
},
|
||||||
|
function (data, _next) {
|
||||||
if (!validFilter[filter]) {
|
if (!validFilter[filter]) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
topics.getTotalUnread(req.uid, filter, _next);
|
||||||
topics.getTotalUnread(req.uid, filter, function (err, data) {
|
},
|
||||||
if (err) {
|
function (data) {
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
},
|
||||||
|
], next);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1564,6 +1564,51 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('unread', function () {
|
||||||
|
var jar;
|
||||||
|
before(function (done) {
|
||||||
|
helpers.loginUser('foo', 'barbar', function (err, _jar) {
|
||||||
|
assert.ifError(err);
|
||||||
|
jar = _jar;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should 404 if filter is invalid', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/unread/doesnotexist', { jar: jar }, function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should 404 if filter is invalid', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/unread/doesnotexist/total', { jar: jar }, function (err, res) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return total unread count', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/unread/new/total', { jar: jar }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(body, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should redirect if page is out of bounds', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/unread?page=-1', { jar: jar }, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 308);
|
||||||
|
assert.equal(body, '"/unread?page=1"');
|
||||||
|
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