2018-10-10 17:34:16 +03:00
|
|
|
const should = require('should');
|
2020-06-18 16:02:40 +03:00
|
|
|
const nock = require('nock');
|
|
|
|
const path = require('path');
|
2018-10-10 17:34:16 +03:00
|
|
|
const supertest = require('supertest');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const ObjectId = require('bson-objectid');
|
|
|
|
const moment = require('moment-timezone');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2020-03-30 18:26:47 +03:00
|
|
|
const models = require('../../../core/server/models');
|
2018-10-10 17:34:16 +03:00
|
|
|
const localUtils = require('./utils');
|
2021-05-03 16:51:25 +03:00
|
|
|
const configUtils = require('../../utils/configUtils');
|
2019-09-20 18:02:45 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Posts API', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
let request;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await localUtils.doAuth(request, 'users:extra', 'posts', 'emails');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-06-18 16:02:40 +03:00
|
|
|
afterEach(function () {
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can retrieve all posts', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
jsonResponse.posts.should.have.length(13);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
|
|
|
|
|
|
|
// Ensure default order
|
|
|
|
jsonResponse.posts[0].slug.should.eql('scheduled-post');
|
|
|
|
jsonResponse.posts[12].slug.should.eql('html-ipsum');
|
|
|
|
|
|
|
|
// Absolute urls by default
|
|
|
|
jsonResponse.posts[0].url.should.match(new RegExp(`${config.get('url')}/p/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`));
|
|
|
|
jsonResponse.posts[2].url.should.eql(`${config.get('url')}/welcome/`);
|
|
|
|
jsonResponse.posts[11].feature_image.should.eql(`${config.get('url')}/content/images/2018/hey.jpg`);
|
|
|
|
|
|
|
|
jsonResponse.posts[0].tags.length.should.eql(0);
|
|
|
|
jsonResponse.posts[2].tags.length.should.eql(1);
|
|
|
|
jsonResponse.posts[2].authors.length.should.eql(1);
|
|
|
|
jsonResponse.posts[2].tags[0].url.should.eql(`${config.get('url')}/tag/getting-started/`);
|
|
|
|
jsonResponse.posts[2].authors[0].url.should.eql(`${config.get('url')}/author/ghost/`);
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can retrieve multiple post formats', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/?formats=plaintext,mobiledoc&limit=3&order=title%20ASC'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
jsonResponse.posts.should.have.length(3);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['plaintext']);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
|
|
|
|
|
|
|
// ensure order works
|
2021-03-10 17:19:11 +03:00
|
|
|
jsonResponse.posts[0].slug.should.eql('portal');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can include single relation', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/?include=tags'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
jsonResponse.posts.should.have.length(13);
|
|
|
|
localUtils.API.checkResponse(
|
|
|
|
jsonResponse.posts[0],
|
|
|
|
'post',
|
|
|
|
null,
|
|
|
|
['authors', 'primary_author', 'email']
|
|
|
|
);
|
|
|
|
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can filter posts', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/?filter=featured:true'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
jsonResponse.posts.should.have.length(2);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Cannot receive pages', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/?filter=page:true'))
|
2019-02-22 06:17:14 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
jsonResponse.posts.should.have.length(0);
|
2019-02-22 06:17:14 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can paginate posts', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/?page=2'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.equal(jsonResponse.meta.pagination.page, 2);
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request a post by id', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
|
|
|
|
|
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
|
|
|
|
|
|
|
testUtils.API.isISO8601(jsonResponse.posts[0].created_at).should.be.true();
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can retrieve a post by slug', async function () {
|
|
|
|
const res = await request.get(localUtils.API.getApiQuery('posts/slug/welcome/'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
jsonResponse.posts[0].slug.should.equal('welcome');
|
|
|
|
|
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-01-18 19:03:03 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can include relations for a single post', async function () {
|
|
|
|
const res = await request
|
2019-11-08 07:40:49 +03:00
|
|
|
.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?include=authors,tags,email'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.posts);
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
jsonResponse.posts[0].authors[0].should.be.an.Object();
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0].authors[0], 'user');
|
2019-02-04 17:16:24 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
jsonResponse.posts[0].tags[0].should.be.an.Object();
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag', ['url']);
|
2019-11-08 07:40:49 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
jsonResponse.posts[0].email.should.be.an.Object();
|
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0].email, 'email');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-01-18 19:03:03 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can add a post', async function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
const post = {
|
|
|
|
title: 'My post',
|
|
|
|
status: 'draft',
|
|
|
|
published_at: '2016-05-30T07:00:00.000Z',
|
|
|
|
mobiledoc: testUtils.DataGenerator.markdownToMobiledoc('my post'),
|
|
|
|
created_at: moment().subtract(2, 'days').toDate(),
|
|
|
|
updated_at: moment().subtract(2, 'days').toDate(),
|
2021-04-21 18:02:02 +03:00
|
|
|
created_by: ObjectId().toHexString(),
|
|
|
|
updated_by: ObjectId().toHexString()
|
2019-02-04 17:16:24 +03:00
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.post(localUtils.API.getApiQuery('posts'))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({posts: [post]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(201);
|
|
|
|
|
|
|
|
res.body.posts.length.should.eql(1);
|
|
|
|
localUtils.API.checkResponse(res.body.posts[0], 'post');
|
|
|
|
res.body.posts[0].url.should.match(new RegExp(`${config.get('url')}/p/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`));
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
should.exist(res.headers.location);
|
|
|
|
res.headers.location.should.equal(`http://127.0.0.1:2369${localUtils.API.getApiQuery('posts/')}${res.body.posts[0].id}/`);
|
|
|
|
|
|
|
|
const model = await models.Post.findOne({
|
|
|
|
id: res.body.posts[0].id,
|
|
|
|
status: 'draft'
|
|
|
|
}, testUtils.context.internal);
|
|
|
|
|
|
|
|
model.get('title').should.eql(post.title);
|
|
|
|
model.get('status').should.eql(post.status);
|
|
|
|
model.get('published_at').toISOString().should.eql('2016-05-30T07:00:00.000Z');
|
|
|
|
model.get('created_at').toISOString().should.not.eql(post.created_at.toISOString());
|
|
|
|
model.get('updated_at').toISOString().should.not.eql(post.updated_at.toISOString());
|
|
|
|
model.get('updated_by').should.not.eql(post.updated_by);
|
|
|
|
model.get('created_by').should.not.eql(post.created_by);
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-01-18 19:03:03 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can update draft', async function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
const post = {
|
|
|
|
title: 'update draft'
|
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request
|
2019-02-22 06:17:14 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[3].id}/`))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
post.updated_at = res.body.posts[0].updated_at;
|
|
|
|
|
|
|
|
const res2 = await request.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[3].id))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({posts: [post]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
res2.headers['x-cache-invalidate'].should.eql('/p/' + res2.body.posts[0].uuid + '/');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can update and force re-render', async function () {
|
2020-06-18 16:02:40 +03:00
|
|
|
const unsplashMock = nock('https://images.unsplash.com/')
|
|
|
|
.get('/favicon_too_large')
|
|
|
|
.query(true)
|
|
|
|
.replyWithFile(200, path.join(__dirname, '../../utils/fixtures/images/ghost-logo.png'), {
|
|
|
|
'Content-Type': 'image/png'
|
|
|
|
});
|
|
|
|
|
|
|
|
const mobiledoc = JSON.parse(testUtils.DataGenerator.Content.posts[3].mobiledoc);
|
|
|
|
mobiledoc.cards.push(['image', {src: 'https://images.unsplash.com/favicon_too_large?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=2000&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ'}]);
|
|
|
|
mobiledoc.sections.push([10, mobiledoc.cards.length - 1]);
|
|
|
|
|
|
|
|
const post = {
|
|
|
|
mobiledoc: JSON.stringify(mobiledoc)
|
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request
|
2020-06-18 16:02:40 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[3].id}/`))
|
|
|
|
.set('Origin', config.get('url'))
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
post.updated_at = res.body.posts[0].updated_at;
|
|
|
|
|
|
|
|
const res2 = await request
|
|
|
|
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[3].id + '/?force_rerender=true&formats=mobiledoc,html'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({posts: [post]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private);
|
|
|
|
|
|
|
|
res2.headers['x-cache-invalidate'].should.eql('/p/' + res2.body.posts[0].uuid + '/');
|
|
|
|
|
|
|
|
unsplashMock.isDone().should.be.true();
|
|
|
|
|
|
|
|
// mobiledoc is updated with image sizes
|
|
|
|
const resMobiledoc = JSON.parse(res2.body.posts[0].mobiledoc);
|
|
|
|
const cardPayload = resMobiledoc.cards[mobiledoc.cards.length - 1][1];
|
|
|
|
cardPayload.width.should.eql(800);
|
|
|
|
cardPayload.height.should.eql(257);
|
|
|
|
|
|
|
|
// html is re-rendered to include srcset
|
|
|
|
res2.body.posts[0].html.should.match(/srcset="https:\/\/images\.unsplash\.com\/favicon_too_large\?ixlib=rb-1\.2\.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=600&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ 600w, https:\/\/images\.unsplash\.com\/favicon_too_large\?ixlib=rb-1\.2\.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=800&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ 800w"/);
|
2020-06-18 16:02:40 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can unpublish a post', async function () {
|
2019-02-04 17:16:24 +03:00
|
|
|
const post = {
|
|
|
|
status: 'draft'
|
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request
|
2019-02-22 06:17:14 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[1].id}/?`))
|
2019-02-04 17:16:24 +03:00
|
|
|
.set('Origin', config.get('url'))
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
post.updated_at = res.body.posts[0].updated_at;
|
|
|
|
|
|
|
|
const res2 = await request
|
|
|
|
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({posts: [post]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
res2.headers['x-cache-invalidate'].should.eql('/*');
|
|
|
|
res2.body.posts[0].status.should.eql('draft');
|
2019-02-04 17:16:24 +03:00
|
|
|
});
|
2019-01-18 19:03:03 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can destroy a post', async function () {
|
|
|
|
const res = await request
|
2019-02-04 17:16:24 +03:00
|
|
|
.del(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(204);
|
|
|
|
|
|
|
|
res.body.should.be.empty();
|
|
|
|
res.headers['x-cache-invalidate'].should.eql('/*');
|
2018-10-10 17:34:16 +03:00
|
|
|
});
|
2019-02-22 06:17:14 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Cannot get post via pages endpoint', async function () {
|
|
|
|
await request.get(localUtils.API.getApiQuery(`pages/${testUtils.DataGenerator.Content.posts[3].id}/`))
|
2019-02-22 06:17:14 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Cannot update post via pages endpoint', async function () {
|
2019-02-22 06:17:14 +03:00
|
|
|
const post = {
|
|
|
|
title: 'fails',
|
|
|
|
updated_at: new Date().toISOString()
|
|
|
|
};
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
await request.put(localUtils.API.getApiQuery('pages/' + testUtils.DataGenerator.Content.posts[3].id))
|
2019-02-22 06:17:14 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({pages: [post]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404);
|
|
|
|
});
|
2021-05-03 16:51:25 +03:00
|
|
|
|
|
|
|
describe('Host Settings: emails limits', function () {
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.set('hostSettings:limits', undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Request fails when emails limit is in place', async function () {
|
|
|
|
configUtils.set('hostSettings:limits', {
|
|
|
|
emails: {
|
|
|
|
disabled: true,
|
|
|
|
error: 'No email shalt be sent'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: need to do a full reboot to reinitialize hostSettings
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await localUtils.doAuth(request, 'users:extra', 'posts', 'emails');
|
|
|
|
|
|
|
|
const draftPostResponse = await request
|
|
|
|
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[3].id}/`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
const draftPost = draftPostResponse.body.posts[0];
|
|
|
|
|
|
|
|
const response = await request
|
|
|
|
.put(localUtils.API.getApiQuery(`posts/${draftPost.id}/?email_recipient_filter=all&send_email_when_published=true`))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send({posts: [{
|
|
|
|
status: 'published',
|
|
|
|
updated_at: draftPost.updated_at
|
|
|
|
}]})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(403);
|
|
|
|
|
|
|
|
response.body.errors[0].type.should.equal('HostLimitError');
|
|
|
|
response.body.errors[0].context.should.equal('No email shalt be sent');
|
|
|
|
});
|
|
|
|
});
|
2018-10-10 17:34:16 +03:00
|
|
|
});
|