mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
add tests for github controller
This commit is contained in:
parent
a31fb029d2
commit
e27d1917e3
@ -77,6 +77,7 @@ exports.create = function (req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
if (!user) {
|
||||
res.status(403);
|
||||
return res.render('sign/signin', { error: '账号名或密码错误。' });
|
||||
}
|
||||
user.githubId = profile.id;
|
||||
|
||||
@ -18,7 +18,7 @@ var xmlbuilder = require('xmlbuilder');
|
||||
var renderHelpers = require('../common/render_helpers');
|
||||
|
||||
// 主页的缓存工作。主页是需要主动缓存的
|
||||
setInterval(function () {
|
||||
function indexCache() {
|
||||
var limit = config.list_topic_count;
|
||||
// 为所有版块(tab)做缓存
|
||||
[['', '全部']].concat(config.tabs).forEach(function (pair) {
|
||||
@ -36,7 +36,9 @@ setInterval(function () {
|
||||
return topics;
|
||||
});
|
||||
});
|
||||
}, 1000 * 5); // 五秒更新一次
|
||||
}
|
||||
setInterval(indexCache, 1000 * 5); // 五秒更新一次
|
||||
indexCache();
|
||||
// END 主页的缓存工作
|
||||
|
||||
exports.index = function (req, res, next) {
|
||||
|
||||
@ -5,8 +5,13 @@ var github = require('../../controllers/github');
|
||||
var Models = require('../../models');
|
||||
var User = Models.User;
|
||||
var config = require('../../config');
|
||||
var support = require('../support/support');
|
||||
|
||||
describe('test/controllers/github.test.js', function () {
|
||||
before(function (done) {
|
||||
support.ready(done);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
mm.restore();
|
||||
});
|
||||
@ -129,17 +134,17 @@ describe('test/controllers/github.test.js', function () {
|
||||
});
|
||||
|
||||
it('should link a old user', function (done) {
|
||||
var username = 'Alsotang';
|
||||
var username = 'alsotang' + +new Date();
|
||||
var pass = 'hehe';
|
||||
mm(User, 'findOne', function (loginInfo, callback) {
|
||||
loginInfo.loginname.should.equal(username.toLowerCase());
|
||||
callback(null, {save: function () {
|
||||
done();
|
||||
}});
|
||||
support.createUserByNameAndPwd(username, pass, function (user) {
|
||||
request.post('/auth/github/test_create')
|
||||
.send({name: username, pass: pass})
|
||||
.end(function (err, res) {
|
||||
res.status.should.equal(302);
|
||||
res.headers.location.should.equal('/');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
request.post('/auth/github/test_create')
|
||||
.send({name: username, pass: pass})
|
||||
.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -34,4 +34,11 @@ describe('test/controllers/site.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should /sitemap.xml 200', function (done) {
|
||||
request.get('/sitemap.xml')
|
||||
.expect(200, function (err, res) {
|
||||
res.text.should.containEql('<url>');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ var User = require('../../proxy/user');
|
||||
var Topic = require('../../proxy/topic');
|
||||
var ready = require('ready');
|
||||
var eventproxy = require('eventproxy');
|
||||
var utility = require('utility');
|
||||
|
||||
function randomInt() {
|
||||
return (Math.random() * 10000).toFixed(0);
|
||||
@ -12,6 +13,10 @@ var createUser = exports.createUser = function (callback) {
|
||||
User.newAndSave('jackson' + key, 'jackson' + key, 'pass', 'jackson' + key + '@domain.com', '', false, callback);
|
||||
};
|
||||
|
||||
exports.createUserByNameAndPwd = function (loginname, pwd, callback) {
|
||||
User.newAndSave(loginname, loginname, utility.md5(pwd), loginname + +new Date() + '@gmail.com', '', true, callback);
|
||||
};
|
||||
|
||||
var createTopic = exports.createTopic = function (authorId, callback) {
|
||||
var key = new Date().getTime() + '_' + randomInt();
|
||||
Topic.newAndSave('title' + key, 'content' + key, 'share', authorId, callback);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user