2018-10-13 01:48:49 +03:00
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const url = require('url');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const configUtils = require('../../utils/configUtils');
|
2020-03-30 18:26:47 +03:00
|
|
|
const config = require('../../../core/server/config');
|
2018-10-13 01:48:49 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
let request;
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
describe('Posts Content API', function () {
|
2018-10-13 01:48:49 +03:00
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function () {
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
2019-02-13 22:38:25 +03:00
|
|
|
return testUtils.initFixtures('owner:post', 'users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2018-10-15 12:23:34 +03:00
|
|
|
const validKey = localUtils.getValidKey();
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request posts', function (done) {
|
2018-10-15 12:23:34 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-10-15 12:23:34 +03:00
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
2018-10-13 01:48:49 +03:00
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
2018-10-13 01:48:49 +03:00
|
|
|
should.exist(jsonResponse.posts);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
2018-10-13 01:48:49 +03:00
|
|
|
jsonResponse.posts.should.have.length(11);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2018-10-13 01:48:49 +03:00
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
|
|
|
|
2019-01-15 15:21:04 +03:00
|
|
|
// Default order 'published_at desc' check
|
2018-10-13 01:48:49 +03:00
|
|
|
jsonResponse.posts[0].slug.should.eql('welcome');
|
|
|
|
jsonResponse.posts[6].slug.should.eql('themes');
|
|
|
|
|
|
|
|
// check meta response for this test
|
|
|
|
jsonResponse.meta.pagination.page.should.eql(1);
|
|
|
|
jsonResponse.meta.pagination.limit.should.eql(15);
|
|
|
|
jsonResponse.meta.pagination.pages.should.eql(1);
|
|
|
|
jsonResponse.meta.pagination.total.should.eql(11);
|
|
|
|
jsonResponse.meta.pagination.hasOwnProperty('next').should.be.true();
|
|
|
|
jsonResponse.meta.pagination.hasOwnProperty('prev').should.be.true();
|
|
|
|
should.not.exist(jsonResponse.meta.pagination.next);
|
|
|
|
should.not.exist(jsonResponse.meta.pagination.prev);
|
|
|
|
|
|
|
|
// kitchen sink
|
|
|
|
res.body.posts[9].slug.should.eql(testUtils.DataGenerator.Content.posts[1].slug);
|
|
|
|
|
|
|
|
let urlParts = url.parse(res.body.posts[9].feature_image);
|
|
|
|
should.exist(urlParts.protocol);
|
|
|
|
should.exist(urlParts.host);
|
|
|
|
|
|
|
|
urlParts = url.parse(res.body.posts[9].url);
|
|
|
|
should.exist(urlParts.protocol);
|
|
|
|
should.exist(urlParts.host);
|
|
|
|
|
|
|
|
const $ = cheerio.load(res.body.posts[9].html);
|
|
|
|
urlParts = url.parse($('img').attr('src'));
|
|
|
|
should.exist(urlParts.protocol);
|
|
|
|
should.exist(urlParts.host);
|
|
|
|
|
2018-11-05 20:07:45 +03:00
|
|
|
res.body.posts[7].slug.should.eql('not-so-short-bit-complex');
|
2019-10-08 15:58:08 +03:00
|
|
|
res.body.posts[7].html.should.match(/<a href="http:\/\/127.0.0.1:2369\/about#nowhere" title="Relative URL/);
|
2018-11-05 20:07:45 +03:00
|
|
|
res.body.posts[9].slug.should.eql('ghostly-kitchen-sink');
|
|
|
|
res.body.posts[9].html.should.match(/<img src="http:\/\/127.0.0.1:2369\/content\/images\/lol.jpg"/);
|
|
|
|
|
2018-10-13 01:48:49 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can filter posts by tag', function (done) {
|
2018-10-15 12:23:34 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=tag:kitchen-sink,featured:true&include=tags`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
const ids = _.map(jsonResponse.posts, 'id');
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.exist(jsonResponse.posts);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2018-10-13 01:48:49 +03:00
|
|
|
|
|
|
|
// should content filtered data and order
|
|
|
|
jsonResponse.posts.should.have.length(4);
|
|
|
|
ids.should.eql([
|
|
|
|
testUtils.DataGenerator.Content.posts[4].id,
|
|
|
|
testUtils.DataGenerator.Content.posts[2].id,
|
|
|
|
testUtils.DataGenerator.Content.posts[1].id,
|
2019-07-05 14:40:43 +03:00
|
|
|
testUtils.DataGenerator.Content.posts[0].id
|
2018-10-13 01:48:49 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Each post must either be featured or have the tag 'kitchen-sink'
|
|
|
|
_.each(jsonResponse.posts, (post) => {
|
|
|
|
if (post.featured) {
|
|
|
|
post.featured.should.equal(true);
|
|
|
|
} else {
|
|
|
|
const tags = _.map(post.tags, 'slug');
|
|
|
|
tags.should.containEql('kitchen-sink');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// The meta object should contain the right detail
|
|
|
|
jsonResponse.meta.should.have.property('pagination');
|
|
|
|
jsonResponse.meta.pagination.should.be.an.Object().with.properties(['page', 'limit', 'pages', 'total', 'next', 'prev']);
|
|
|
|
jsonResponse.meta.pagination.page.should.eql(1);
|
|
|
|
jsonResponse.meta.pagination.limit.should.eql(15);
|
|
|
|
jsonResponse.meta.pagination.pages.should.eql(1);
|
|
|
|
jsonResponse.meta.pagination.total.should.eql(4);
|
|
|
|
should.equal(jsonResponse.meta.pagination.next, null);
|
|
|
|
should.equal(jsonResponse.meta.pagination.prev, null);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can filter posts by authors', function (done) {
|
🐛 Fixed all known filter limitations (#10159)
refs #10105, closes #10108, closes https://github.com/TryGhost/Ghost/issues/9950, refs https://github.com/TryGhost/Ghost/issues/9923, refs https://github.com/TryGhost/Ghost/issues/9916, refs https://github.com/TryGhost/Ghost/issues/9574, refs https://github.com/TryGhost/Ghost/issues/6345, refs https://github.com/TryGhost/Ghost/issues/6309, refs https://github.com/TryGhost/Ghost/issues/6158, refs https://github.com/TryGhost/GQL/issues/16
- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.
NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
2018-12-11 13:53:40 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=authors:[joe-bloggs,pat,ghost,slimer-mcectoplasm]&include=authors`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
const ids = _.map(jsonResponse.posts, 'id');
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
should.exist(jsonResponse.posts);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2018-10-13 01:48:49 +03:00
|
|
|
|
|
|
|
// 2. The data part of the response should be correct
|
|
|
|
// We should have 2 matching items
|
|
|
|
jsonResponse.posts.should.be.an.Array().with.lengthOf(11);
|
|
|
|
|
🐛 Fixed all known filter limitations (#10159)
refs #10105, closes #10108, closes https://github.com/TryGhost/Ghost/issues/9950, refs https://github.com/TryGhost/Ghost/issues/9923, refs https://github.com/TryGhost/Ghost/issues/9916, refs https://github.com/TryGhost/Ghost/issues/9574, refs https://github.com/TryGhost/Ghost/issues/6345, refs https://github.com/TryGhost/Ghost/issues/6309, refs https://github.com/TryGhost/Ghost/issues/6158, refs https://github.com/TryGhost/GQL/issues/16
- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.
NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
2018-12-11 13:53:40 +03:00
|
|
|
// The API orders by number of matched authors.
|
|
|
|
jsonResponse.posts[0].slug.should.eql('not-so-short-bit-complex');
|
|
|
|
|
2018-10-13 01:48:49 +03:00
|
|
|
// Each post must either have the author 'joe-bloggs' or 'ghost', 'pat' is non existing author
|
🐛 Fixed all known filter limitations (#10159)
refs #10105, closes #10108, closes https://github.com/TryGhost/Ghost/issues/9950, refs https://github.com/TryGhost/Ghost/issues/9923, refs https://github.com/TryGhost/Ghost/issues/9916, refs https://github.com/TryGhost/Ghost/issues/9574, refs https://github.com/TryGhost/Ghost/issues/6345, refs https://github.com/TryGhost/Ghost/issues/6309, refs https://github.com/TryGhost/Ghost/issues/6158, refs https://github.com/TryGhost/GQL/issues/16
- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.
NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
2018-12-11 13:53:40 +03:00
|
|
|
const primaryAuthors = _.map(jsonResponse.posts, function (post) {
|
2018-10-13 01:48:49 +03:00
|
|
|
return post.primary_author.slug;
|
|
|
|
});
|
|
|
|
|
🐛 Fixed all known filter limitations (#10159)
refs #10105, closes #10108, closes https://github.com/TryGhost/Ghost/issues/9950, refs https://github.com/TryGhost/Ghost/issues/9923, refs https://github.com/TryGhost/Ghost/issues/9916, refs https://github.com/TryGhost/Ghost/issues/9574, refs https://github.com/TryGhost/Ghost/issues/6345, refs https://github.com/TryGhost/Ghost/issues/6309, refs https://github.com/TryGhost/Ghost/issues/6158, refs https://github.com/TryGhost/GQL/issues/16
- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.
NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
2018-12-11 13:53:40 +03:00
|
|
|
primaryAuthors.should.matchAny(/joe-bloggs|ghost'/);
|
2019-07-05 14:40:43 +03:00
|
|
|
_.filter(primaryAuthors, (value) => {
|
|
|
|
return value === 'ghost';
|
|
|
|
}).length.should.eql(7);
|
|
|
|
|
|
|
|
_.filter(primaryAuthors, (value) => {
|
|
|
|
return value === 'joe-bloggs';
|
|
|
|
}).length.should.eql(4);
|
🐛 Fixed all known filter limitations (#10159)
refs #10105, closes #10108, closes https://github.com/TryGhost/Ghost/issues/9950, refs https://github.com/TryGhost/Ghost/issues/9923, refs https://github.com/TryGhost/Ghost/issues/9916, refs https://github.com/TryGhost/Ghost/issues/9574, refs https://github.com/TryGhost/Ghost/issues/6345, refs https://github.com/TryGhost/Ghost/issues/6309, refs https://github.com/TryGhost/Ghost/issues/6158, refs https://github.com/TryGhost/GQL/issues/16
- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.
NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
2018-12-11 13:53:40 +03:00
|
|
|
|
2018-10-13 01:48:49 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request fields of posts', function (done) {
|
2018-10-15 20:44:00 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&fields=url`))
|
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url']);
|
2018-10-15 20:44:00 +03:00
|
|
|
res.body.posts[0].url.should.eql('http://127.0.0.1:2369/welcome/');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can include relations', function (done) {
|
2018-10-15 12:23:34 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&include=tags,authors`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.exist(res.body.posts);
|
|
|
|
|
|
|
|
// kitchen sink
|
|
|
|
res.body.posts[9].slug.should.eql(testUtils.DataGenerator.Content.posts[1].slug);
|
|
|
|
|
|
|
|
should.exist(res.body.posts[9].tags);
|
|
|
|
should.exist(res.body.posts[9].tags[0].url);
|
|
|
|
should.exist(url.parse(res.body.posts[9].tags[0].url).protocol);
|
|
|
|
should.exist(url.parse(res.body.posts[9].tags[0].url).host);
|
|
|
|
|
|
|
|
should.exist(res.body.posts[9].primary_tag);
|
|
|
|
should.exist(res.body.posts[9].primary_tag.url);
|
|
|
|
should.exist(url.parse(res.body.posts[9].primary_tag.url).protocol);
|
|
|
|
should.exist(url.parse(res.body.posts[9].primary_tag.url).host);
|
|
|
|
|
|
|
|
should.exist(res.body.posts[9].authors);
|
|
|
|
should.exist(res.body.posts[9].authors[0].url);
|
|
|
|
should.exist(url.parse(res.body.posts[9].authors[0].url).protocol);
|
|
|
|
should.exist(url.parse(res.body.posts[9].authors[0].url).host);
|
|
|
|
|
|
|
|
should.exist(res.body.posts[9].primary_author);
|
|
|
|
should.exist(res.body.posts[9].primary_author.url);
|
|
|
|
should.exist(url.parse(res.body.posts[9].primary_author.url).protocol);
|
|
|
|
should.exist(url.parse(res.body.posts[9].primary_author.url).host);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request posts from different origin', function (done) {
|
2018-10-15 12:23:34 +03:00
|
|
|
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', 'https://example.com')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-10-15 12:23:34 +03:00
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
2018-10-13 01:48:49 +03:00
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
2018-10-13 01:48:49 +03:00
|
|
|
should.exist(jsonResponse.posts);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse, 'posts');
|
2018-10-13 01:48:49 +03:00
|
|
|
jsonResponse.posts.should.have.length(11);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
|
|
|
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
|
2018-10-13 01:48:49 +03:00
|
|
|
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can filter by published date', function (done) {
|
2018-10-13 01:48:49 +03:00
|
|
|
function createFilter(publishedAt, op) {
|
|
|
|
// This line deliberately uses double quotes because GQL cannot handle either double quotes
|
|
|
|
// or escaped singles, see TryGhost/GQL#34
|
2019-08-19 14:41:09 +03:00
|
|
|
return encodeURIComponent('published_at:' + op + '\'' + publishedAt + '\'');
|
2018-10-13 01:48:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
request
|
2018-10-15 12:23:34 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&limit=1`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then(function (res) {
|
|
|
|
should.exist(res.body.posts[0]);
|
2020-04-29 18:44:27 +03:00
|
|
|
const post = res.body.posts[0];
|
|
|
|
const publishedAt = moment(post.published_at).format('YYYY-MM-DD HH:mm:ss');
|
2018-10-13 01:48:49 +03:00
|
|
|
|
|
|
|
post.title.should.eql('Welcome to Ghost');
|
|
|
|
|
|
|
|
return request
|
2018-10-15 12:23:34 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&limit=1&filter=${createFilter(publishedAt, `<`)}`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
})
|
|
|
|
.then(function (res) {
|
|
|
|
should.exist(res.body.posts[0]);
|
2020-04-29 18:44:27 +03:00
|
|
|
const post = res.body.posts[0];
|
|
|
|
const publishedAt = moment(post.published_at).format('YYYY-MM-DD HH:mm:ss');
|
2018-10-13 01:48:49 +03:00
|
|
|
|
|
|
|
post.title.should.eql('Writing posts with Ghost ✍️');
|
|
|
|
|
|
|
|
return request
|
2018-10-15 12:23:34 +03:00
|
|
|
.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&limit=1&filter=${createFilter(publishedAt, `>`)}`))
|
2018-10-13 01:48:49 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200);
|
|
|
|
})
|
|
|
|
.then(function (res) {
|
|
|
|
should.exist(res.body.posts[0]);
|
2020-04-29 18:44:27 +03:00
|
|
|
const post = res.body.posts[0];
|
2018-10-13 01:48:49 +03:00
|
|
|
|
|
|
|
post.title.should.eql('Welcome to Ghost');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done);
|
|
|
|
});
|
2018-10-19 11:40:47 +03:00
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request a single post', function () {
|
2018-10-19 11:40:47 +03:00
|
|
|
return request
|
|
|
|
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/?key=${validKey}`))
|
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.posts);
|
|
|
|
should.not.exist(jsonResponse.meta);
|
|
|
|
jsonResponse.posts.should.have.length(1);
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
|
2018-10-19 11:40:47 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|