2021-08-06 14:17:49 +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-10-06 16:40:39 +03:00
|
|
|
const testUtils = require('../utils');
|
|
|
|
const config = require('../../core/shared/config');
|
2024-01-22 17:20:50 +03:00
|
|
|
const {DateTime} = require('luxon');
|
2021-08-06 14:17:49 +03:00
|
|
|
let request;
|
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
function assertCorrectFrontendHeaders(res) {
|
|
|
|
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-06 14:17:49 +03:00
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
describe('Frontend Routing: Preview Routes', function () {
|
|
|
|
async function addPosts() {
|
|
|
|
await testUtils.clearData();
|
|
|
|
await testUtils.initData();
|
|
|
|
await testUtils.fixtures.insertPostsAndTags();
|
2021-08-06 14:17:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
2021-08-06 14:17:49 +03:00
|
|
|
});
|
|
|
|
|
2022-11-02 08:10:49 +03:00
|
|
|
after(async function () {
|
|
|
|
await testUtils.stopGhost();
|
|
|
|
});
|
|
|
|
|
2021-08-06 14:17:49 +03:00
|
|
|
before(addPosts);
|
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
it('should display draft posts accessed via uuid', async function () {
|
|
|
|
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/')
|
2021-08-06 14:17:49 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect(200)
|
2021-10-06 17:51:03 +03:00
|
|
|
.expect(assertCorrectFrontendHeaders)
|
|
|
|
.expect((res) => {
|
2021-08-06 14:17:49 +03:00
|
|
|
const $ = 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('Not finished yet');
|
|
|
|
$('meta[name="description"]').attr('content').should.equal('meta description for draft post');
|
|
|
|
|
|
|
|
// @TODO: use theme from fixtures and don't rely on content/themes/casper
|
|
|
|
// $('.content .post').length.should.equal(1);
|
|
|
|
// $('.poweredby').text().should.equal('Proudly published with Ghost');
|
|
|
|
// $('body.post-template').length.should.equal(1);
|
|
|
|
// $('article.post').length.should.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-17 11:04:53 +03:00
|
|
|
it('should redirect draft posts accessed via uuid and edit to admin post edit screen', async function () {
|
|
|
|
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c903/edit/')
|
|
|
|
.expect('Content-Type', /text\/plain/)
|
|
|
|
.expect(302)
|
|
|
|
.expect('Location', /ghost\/#\/editor\/post\/\w+/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should redirect draft page accessed via uuid and edit to admin page edit screen', async function () {
|
|
|
|
await request.get('/p/d52c42ae-2755-455c-80ec-70b2ec55c904/edit/')
|
|
|
|
.expect('Content-Type', /text\/plain/)
|
|
|
|
.expect(302)
|
|
|
|
.expect('Location', /ghost\/#\/editor\/page\/\w+/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
|
|
|
});
|
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
it('should redirect published posts to their live url', async function () {
|
|
|
|
await request.get('/p/2ac6b4f6-e1f3-406c-9247-c94a0496d39d/')
|
2021-08-06 14:17:49 +03:00
|
|
|
.expect(301)
|
|
|
|
.expect('Location', '/short-and-sweet/')
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
2021-10-06 17:51:03 +03:00
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2021-08-06 14:17:49 +03:00
|
|
|
});
|
|
|
|
|
2024-01-22 17:20:50 +03:00
|
|
|
it('should render scheduled email-only posts', async function () {
|
|
|
|
const scheduledEmail = await testUtils.fixtures.insertPosts([{
|
|
|
|
title: 'test newsletter',
|
|
|
|
status: 'scheduled',
|
|
|
|
published_at: DateTime.now().plus({days: 1}).toISODate(),
|
|
|
|
posts_meta: {
|
|
|
|
email_only: true
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
|
|
|
await request.get(`/p/${scheduledEmail[0].get('uuid')}/`)
|
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect(200)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
|
|
|
});
|
|
|
|
|
2023-11-14 22:31:41 +03:00
|
|
|
it('should redirect sent email-only posts to /email/:uuid from /p/:uuid', async function () {
|
|
|
|
const emailedPost = await testUtils.fixtures.insertPosts([{
|
|
|
|
title: 'test newsletter',
|
|
|
|
status: 'sent',
|
|
|
|
posts_meta: {
|
|
|
|
email_only: true
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
|
|
|
await request.get(`/p/${emailedPost[0].get('uuid')}/`)
|
|
|
|
.expect(301)
|
|
|
|
.expect('Location', `/email/${emailedPost[0].get('uuid')}/`)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
|
|
|
.expect(assertCorrectFrontendHeaders);
|
|
|
|
});
|
|
|
|
|
2021-10-06 17:51:03 +03:00
|
|
|
it('404s unknown uuids', async function () {
|
2021-08-06 14:17:49 +03:00
|
|
|
request.get('/p/aac6b4f6-e1f3-406c-9247-c94a0496d39f/')
|
|
|
|
.expect(404)
|
2021-10-06 17:51:03 +03:00
|
|
|
.expect(assertCorrectFrontendHeaders);
|
2021-08-06 14:17:49 +03:00
|
|
|
});
|
|
|
|
});
|