mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added test coverage for /email/
frontend route
refs https://github.com/TryGhost/Team/issues/948
refs 06a6dcb2d1
- The `/email/` route feature landed in main without test coverage. This changeset gives a start to a test suite covering all things `/email/`
This commit is contained in:
parent
9b82d28dfd
commit
fc6aecceaa
1 changed files with 77 additions and 0 deletions
77
test/regression/site/email_routes.test.js
Normal file
77
test/regression/site/email_routes.test.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
// # Frontend Route tests
|
||||||
|
// As it stands, these tests depend on the database, and as such are integration tests.
|
||||||
|
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
|
||||||
|
// But then again testing real code, rather than mock code, might be more useful...
|
||||||
|
const should = require('should');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const supertest = require('supertest');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
const testUtils = require('../../utils');
|
||||||
|
const config = require('../../../core/shared/config');
|
||||||
|
const settingsCache = require('../../../core/shared/settings-cache');
|
||||||
|
|
||||||
|
describe('Frontend Routing: Email Routes', function () {
|
||||||
|
let request;
|
||||||
|
let emailPosts;
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
const originalSettingsCacheGetFn = settingsCache.get;
|
||||||
|
|
||||||
|
// NOTE: this wacky stubbing can be removed once emailOnlyPosts enters GA stage
|
||||||
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
||||||
|
if (key === 'labs') {
|
||||||
|
return {
|
||||||
|
emailOnlyPosts: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return originalSettingsCacheGetFn(key, options);
|
||||||
|
});
|
||||||
|
|
||||||
|
await testUtils.startGhost();
|
||||||
|
|
||||||
|
request = supertest.agent(config.get('url'));
|
||||||
|
|
||||||
|
emailPosts = await testUtils.fixtures.insertPosts([{
|
||||||
|
title: 'I am visible through email route!',
|
||||||
|
status: 'draft',
|
||||||
|
posts_meta: {
|
||||||
|
email_only: true
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display email_only post', async function () {
|
||||||
|
const res = await request.get(`/email/${emailPosts[0].get('uuid')}/`)
|
||||||
|
.expect('Content-Type', /html/)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const $ = cheerio.load(res.text);
|
||||||
|
|
||||||
|
$('title').text().should.equal('I am visible through email route!');
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('404s when accessed by slug', function () {
|
||||||
|
return request.get(`/${emailPosts[0].get('slug')}/`)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('404s unknown uuids', function () {
|
||||||
|
return request.get('/email/aac6b4f6-e1f3-406c-9247-c94a0496d39f/')
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue