unread tests

v1.18.x
Baris Usakli 8 years ago
parent d1dd0cd6df
commit 69b5bb39ec

@ -55,11 +55,7 @@ unreadController.get = function (req, res, next) {
cutoff: cutoff,
}, next);
},
], function (err, data) {
if (err) {
return next(err);
}
function (data) {
data.pageCount = Math.max(1, Math.ceil(data.topicCount / settings.topicsPerPage));
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))) : '';
res.render('unread', data);
});
},
], next);
};
unreadController.unreadTotal = function (req, res, next) {
var filter = req.params.filter || '';
async.waterfall([
function (next) {
plugins.fireHook('filter:unread.getValidFilters', { filters: validFilter }, next);
},
function (data, _next) {
if (!validFilter[filter]) {
return next();
}
topics.getTotalUnread(req.uid, filter, function (err, data) {
if (err) {
return next(err);
}
topics.getTotalUnread(req.uid, filter, _next);
},
function (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) {
var analytics = require('../src/analytics');
analytics.writeData(function (err) {

Loading…
Cancel
Save