- app.js
- controllers/at.js
- controllers/rss.js
- controllers/site.js
- controllers/status.js
- controllers/upload.js
- controllers/user.js
- plugins/onehost.js
app.request().get('/').end(function (res) {
res.should.status(200);
done();
});
searchUsers(text, function (err, users) {
should.not.exist(err);
should.exist(users);
users.should.length(3);
for (var i = 0; i < users.length; i++) {
var user = users[i];
user.name.should.match(/^testuser\d$/);
}
done();
});
should found 0 user in text.
searchUsers('no users match in text @ @@@@ @ @@@ @哈哈 @ testuser1', function (err, users) {
should.not.exist(err);
should.exist(users);
users.should.length(0);
done();
});
should found 0 user in db.
searchUsers('@testuser123 @suqian2012 @ testuser1 no users match in db @ @@@@ @ @@@',
function (err, users) {
should.not.exist(err);
should.exist(users);
users.should.length(0);
done();
});
mentionUser.linkUsers(text, function (err, text2) {
should.not.exist(err);
text2.should.equal(linkedText);
done();
});
mentionUser.linkUsers(text, function (err, text2) {
should.exist(err);
err.message.should.equal('mock searchUsers() error');
should.not.exist(text2);
done();
});
mentionUser.sendMessageToMentionUsers(text, '4fb9db9c1dc2160000000005', '4fcae41e1eb86c0000000003',
function (err) {
should.not.exist(err);
done();
});
should not send message to no mention users.
mentionUser.sendMessageToMentionUsers('abc no mentions', '4fb9db9c1dc2160000000005', '4fcae41e1eb86c0000000003',
function (err) {
should.not.exist(err);
done();
});
mentionUser.sendMessageToMentionUsers(text, '4fb9db9c1dc2160000000005', '4fcae41e1eb86c0000000003',
function (err) {
should.exist(err);
err.message.should.equal('mock send_at_message() error');
done();
});
app.request().get('/rss').end(function (res) {
res.should.status(200);
res.should.header('content-type', 'application/xml');
var body = res.body.toString();
body.indexOf('<?xml version="1.0" encoding="utf-8"?>').should.equal(0);
body.should.include('<rss version="2.0">');
body.should.include('<channel><title>' + config.rss.title + '</title>');
done();
});
app.request().get('/rss').end(function (res) {
res.should.status(404);
res.body.toString().should.equal('Please set `rss` in config.js');
done();
});
app.request().get('/rss').end(function (res) {
res.should.status(500);
res.body.toString().should.include('mock get_topics_by_query() error');
done();
});
app.request().get('/').end(function (res) {
res.should.status(200);
done();
});
should /?q=neverexistskeyword 200.
app.request().get('/?q=neverexistskeyword').end(function (res) {
res.should.status(200);
res.body.toString().should.include('无话题');
done();
});
should /?q=neverexistskeyword&q=foo2 200.
app.request().get('/?q=neverexistskeyword&q=foo2').end(function (res) {
res.should.status(200);
res.body.toString().should.include('无话题');
done();
});
app.request().get('/status').end(function (res) {
res.should.status(200);
res.should.header('content-type', 'application/json; charset=utf-8');
var json;
try {
json = JSON.parse(res.body.toString());
} catch (e) {
done(e);
}
json.should.have.property("status", "success");
json.should.have.property("now");
done();
});
upload.uploadImage({}, {
send: function (data) {
data.should.have.property('status', 'forbidden');
done();
}
}, function () {
throw new Error('should not call this method');
});
should failed when no file upload.
upload.uploadImage(mockRequest, {
send: function (data) {
data.should.have.property('status', 'failed');
data.should.have.property('message', 'no file');
done();
}
}, function () {
throw new Error('should not call this method');
});
should upload file success.
upload.uploadImage(mockLoginedRequest, {
send: function (data) {
data.should.have.property('status', 'success');
data.should.have.property('url');
data.url.should.match(/^\/upload\/mock_user_id\/\d+\_tmp_test_file\.png$/);
var uploadfile = path.join(tmpdirpath, data.url.replace('/upload/', ''));
should.ok(path.existsSync(uploadfile));
done();
}
}, function () {
throw new Error('should not call this method');
});
should return mock ndir.mkdir() error.
var upload2 = rewire('../../controllers/upload');
upload2.__set__({
ndir: {
mkdir: function (dir, callback) {
process.nextTick(function () {
callback(new Error('mock ndir.mkdir() error'));
});
}
}
});
upload2.uploadImage(mockLoginedRequest, {
send: function (data) {
throw new Error('should not call this method');
}
}, function (err) {
should.exist(err);
err.message.should.equal('mock ndir.mkdir() error');
done();
});
should return mock fs.rename() error.
var upload3 = rewire('../../controllers/upload');
upload3.__set__({
fs: {
rename: function (from, to, callback) {
process.nextTick(function () {
callback(new Error('mock fs.rename() error'));
});
}
}
});
upload3.uploadImage(mockLoginedRequest, {
send: function (data) {
throw new Error('should not call this method');
}
}, function (err) {
should.exist(err);
err.message.should.equal('mock fs.rename() error');
done();
});
app.request().get('/user/testuser1').end(function (res) {
res.should.status(200);
done();
});
/stars should 200.
app.request().get('/stars').end(function (res) {
res.should.status(200);
done();
});
/users/top100 should 200.
app.request().get('/users/top100').end(function (res) {
res.should.status(200);
done();
});
/setting should 302 when not login.
app.request().get('/setting').end(function (res) {
res.should.status(302);
done();
});
app.request().get('/foo/bar').end(function (res) {
res.should.status(301);
res.headers.location.should.equal('http://' + bindHost + '/foo/bar');
done();
});
should 301 when GET request 127.0.0.1:port.
app.request({ address: '127.0.0.1', port: app.address().port }).get('/foo/bar').end(function (res) {
res.should.status(301);
res.headers.location.should.equal('http://' + bindHost + '/foo/bar');
done();
});
should no redirect for post
.
app.request()[method]('/foo/bar').end(function (res) {
res.should.status(200);
res.headers.should.not.have.property('location');
if (method === 'head') {
res.body.should.length(0);
} else {
res.body.toString().should.equal(method.toUpperCase() + ' /foo/bar');
}
done();
});
should no redirect for put
.
app.request()[method]('/foo/bar').end(function (res) {
res.should.status(200);
res.headers.should.not.have.property('location');
if (method === 'head') {
res.body.should.length(0);
} else {
res.body.toString().should.equal(method.toUpperCase() + ' /foo/bar');
}
done();
});
should no redirect for delete
.
app.request()[method]('/foo/bar').end(function (res) {
res.should.status(200);
res.headers.should.not.have.property('location');
if (method === 'head') {
res.body.should.length(0);
} else {
res.body.toString().should.equal(method.toUpperCase() + ' /foo/bar');
}
done();
});
should no redirect for head
.
app.request()[method]('/foo/bar').end(function (res) {
res.should.status(200);
res.headers.should.not.have.property('location');
if (method === 'head') {
res.body.should.length(0);
} else {
res.body.toString().should.equal(method.toUpperCase() + ' /foo/bar');
}
done();
});
app.request().get('/foo/bar').end(function (res) {
res.should.status(301);
res.headers.location.should.equal('http://' + bindHost + '/foo/bar');
done();
});
should 200 when request GET exclude host.
app2.request({ address: '127.0.0.1', port: 58964 }).get('/foo/bar').end(function (res) {
res.should.status(200);
res.body.toString().should.equal('GET /foo/bar');
done();
});