// # 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 should = require('should'), supertest = require('supertest'), sinon = require('sinon'), testUtils = require('../../utils'), cheerio = require('cheerio'), config = require('../../../../core/server/config'), settingsCache = require('../../../../core/server/settings/cache'), ghost = testUtils.startGhost, sandbox = sinon.sandbox.create(), request; 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) { // Default is always casper. We use the old compatible 1.4 casper theme for these tests. Available in the test content folder. var originalSettingsCacheGetFn = settingsCache.get; sandbox.stub(settingsCache, 'get').callsFake(function (key, options) { if (key === 'active_theme') { return 'casper-1.4'; } return originalSettingsCacheGetFn(key, options); }); ghost().then(function (_ghostServer) { ghostServer = _ghostServer; return ghostServer.start(); }).then(function () { request = supertest.agent(config.get('url')); done(); }).catch(function (e) { console.log('Ghost Error: ', e); console.log(e.stack); done(e); }); }); after(testUtils.teardown); after(function () { sandbox.restore(); 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(5); $('.poweredby').text().should.equal('Proudly published with Ghost'); $('body.home-template').length.should.equal(1); $('article.post').length.should.equal(5); $('article.tag-getting-started').length.should.equal(5); done(); }); }); it('should not have a third page', function (done) { request.get('/page/3/') .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"\?>