2018-10-13 01:48:49 +03:00
|
|
|
const url = require('url');
|
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
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('Pages 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 () {
|
2018-10-15 12:23:34 +03:00
|
|
|
return testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request pages', function () {
|
2018-10-15 12:23:34 +03:00
|
|
|
const key = localUtils.getValidKey();
|
|
|
|
return request.get(localUtils.API.getApiQuery(`pages/?key=${key}`))
|
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((res) => {
|
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']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.pages);
|
|
|
|
should.exist(jsonResponse.meta);
|
|
|
|
jsonResponse.pages.should.have.length(1);
|
|
|
|
|
|
|
|
res.body.pages[0].slug.should.eql(testUtils.DataGenerator.Content.posts[5].slug);
|
|
|
|
|
|
|
|
const urlParts = url.parse(res.body.pages[0].url);
|
|
|
|
should.exist(urlParts.protocol);
|
|
|
|
should.exist(urlParts.host);
|
|
|
|
});
|
|
|
|
});
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
it('Can request page', function () {
|
2018-10-17 12:48:06 +03:00
|
|
|
const key = localUtils.getValidKey();
|
2018-10-19 11:40:47 +03:00
|
|
|
return request.get(localUtils.API.getApiQuery(`pages/${testUtils.DataGenerator.Content.posts[5].id}/?key=${key}`))
|
2018-10-17 12:48:06 +03:00
|
|
|
.set('Origin', testUtils.API.getURL())
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.then((res) => {
|
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.pages);
|
|
|
|
jsonResponse.pages.should.have.length(1);
|
|
|
|
|
2018-10-19 11:40:47 +03:00
|
|
|
res.body.pages[0].slug.should.eql(testUtils.DataGenerator.Content.posts[5].slug);
|
2018-10-17 12:48:06 +03:00
|
|
|
|
|
|
|
const urlParts = url.parse(res.body.pages[0].url);
|
|
|
|
should.exist(urlParts.protocol);
|
|
|
|
should.exist(urlParts.host);
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|