2021-08-09 12:33:04 +03:00
|
|
|
// # 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');
|
|
|
|
|
2021-11-17 13:51:14 +03:00
|
|
|
const testUtils = require('../utils');
|
|
|
|
const config = require('../../core/shared/config');
|
2021-08-09 12:33:04 +03:00
|
|
|
|
|
|
|
describe('Frontend Routing: Email Routes', function () {
|
|
|
|
let request;
|
|
|
|
let emailPosts;
|
|
|
|
|
|
|
|
before(async function () {
|
2021-11-17 13:51:14 +03:00
|
|
|
await testUtils.startGhost({forceStart: true});
|
2021-08-09 12:33:04 +03:00
|
|
|
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
|
|
|
|
emailPosts = await testUtils.fixtures.insertPosts([{
|
|
|
|
title: 'I am visible through email route!',
|
2021-08-13 11:09:11 +03:00
|
|
|
status: 'sent',
|
|
|
|
posts_meta: {
|
|
|
|
email_only: true
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
title: 'I am NOT visible through email route!',
|
2021-08-09 12:33:04 +03:00
|
|
|
status: 'draft',
|
|
|
|
posts_meta: {
|
|
|
|
email_only: true
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display email_only post', async function () {
|
2021-08-19 11:27:45 +03:00
|
|
|
const res = await request.get(`/email/${emailPosts[0].get('uuid')}/`)
|
2021-08-09 12:33:04 +03:00
|
|
|
.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);
|
|
|
|
});
|
|
|
|
|
2021-08-13 11:09:11 +03:00
|
|
|
it('404s for draft email only post', function () {
|
2021-08-19 11:27:45 +03:00
|
|
|
return request.get(`/email/${emailPosts[1].get('uuid')}/`)
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('404s known slug', function () {
|
|
|
|
return request.get(`/email/${emailPosts[0].get('slug')}/`)
|
2021-08-09 12:33:04 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2021-08-13 11:09:11 +03:00
|
|
|
it('404s unknown slug', function () {
|
|
|
|
return request.get('/email/random-slug/')
|
2021-08-09 12:33:04 +03:00
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
});
|