// # Channel Route Tests // As it stands, these tests depend on the database, and as such are integration tests. // These tests are here to cover the headers sent with requests and high-level redirects that can't be // tested with the unit tests var request = require('supertest'), should = require('should'), cheerio = require('cheerio'), testUtils = require('../../utils'), config = require('../../../../core/server/config'), ghost = testUtils.startGhost; describe('Channel Routes', function () { var ghostServer; function doEnd(done) { return function (err, res) { if (err) { return done(err); } should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['X-CSRF-Token']); should.not.exist(res.headers['set-cookie']); should.exist(res.headers.date); done(); }; } before(function (done) { ghost().then(function (_ghostServer) { ghostServer = _ghostServer; return ghostServer.start(); }).then(function () { request = request(config.get('url')); done(); }).catch(function (e) { console.log('Ghost Error: ', e); console.log(e.stack); done(e); }); }); after(testUtils.teardown); after(function () { return ghostServer.stop(); }); describe('Index', function () { it('should respond with html', function (done) { request.get('/') .expect('Content-Type', /html/) .expect('Cache-Control', testUtils.cacheRules.public) .expect(200) .end(function (err, res) { if (err) { return done(err); } var $ = cheerio.load(res.text); should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['X-CSRF-Token']); should.not.exist(res.headers['set-cookie']); should.exist(res.headers.date); $('title').text().should.equal('Ghost'); $('.content .post').length.should.equal(1); $('.poweredby').text().should.equal('Proudly published with Ghost'); $('body.home-template').length.should.equal(1); $('article.post').length.should.equal(1); $('article.tag-getting-started').length.should.equal(1); done(); }); }); it('should not have as second page', function (done) { request.get('/page/2/') .expect('Cache-Control', testUtils.cacheRules.private) .expect(404) .expect(/Page not found/) .end(doEnd(done)); }); describe('RSS', function () { before(testUtils.teardown); before(function (done) { testUtils.initData().then(function () { return testUtils.fixtures.overrideOwnerUser(); }).then(function () { done(); }); }); after(testUtils.teardown); it('should 301 redirect with CC=1year without slash', function (done) { request.get('/rss') .expect('Location', '/rss/') .expect('Cache-Control', testUtils.cacheRules.year) .expect(301) .end(doEnd(done)); }); it('should respond with 200 & CC=public', function (done) { request.get('/rss/') .expect('Content-Type', 'text/xml; charset=utf-8') .expect('Cache-Control', testUtils.cacheRules.public) .expect(200) .end(function (err, res) { if (err) { return done(err); } should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['X-CSRF-Token']); should.not.exist(res.headers['set-cookie']); should.exist(res.headers.date); // The remainder of the XML is tested in the unit/xml_spec.js res.text.should.match(/^<\?xml version="1.0" encoding="UTF-8"\?>