forked from cnodejs/nodeclub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrss.test.js
More file actions
71 lines (63 loc) · 2.11 KB
/
rss.test.js
File metadata and controls
71 lines (63 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*!
* nodeclub - rss controller test
* Copyright(c) 2012 fengmk2 <fengmk2@gmail.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var request = require('supertest');
var app = require('../../app');
var config = require('../../config');
describe('test/controllers/rss.test.js', function () {
describe('/rss', function () {
it('should return `application/xml` Content-Type', function (done) {
request(app).get('/rss').end(function (err, res) {
res.status.should.equal(200);
res.headers.should.property('content-type', 'application/xml; charset=utf-8');
res.text.indexOf('<?xml version="1.0" encoding="utf-8"?>').should.equal(0);
res.text.should.containEql('<rss version="2.0">');
res.text.should.containEql('<channel><title>' + config.rss.title + '</title>');
done(err);
});
});
describe('mock `config.rss` not set', function () {
var rss = config.rss;
before(function () {
config.rss = null;
});
after(function () {
config.rss = rss;
});
it('should return waring message', function (done) {
request(app).get('/rss').end(function (err, res) {
res.status.should.equal(404);
res.text.should.equal('Please set `rss` in config.js');
done(err);
});
});
});
describe('mock `topic.getTopicsByQuery()` error', function () {
var topic = require('../../proxy').Topic;
var getTopicsByQuery = topic.getTopicsByQuery;
before(function () {
topic.getTopicsByQuery = function () {
var callback = arguments[arguments.length - 1];
process.nextTick(function () {
callback(new Error('mock getTopicsByQuery() error'));
});
};
});
after(function () {
topic.getTopicsByQuery = getTopicsByQuery;
});
it('should return error', function (done) {
request(app).get('/rss').end(function (err, res) {
res.status.should.equal(500);
res.text.should.containEql('mock getTopicsByQuery() error');
done(err);
});
});
});
});
});