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-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2018-10-13 01:48:49 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
describe('Pages Content 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 testUtils.initFixtures('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request pages', async function () {
|
2018-10-15 12:23:34 +03:00
|
|
|
const key = localUtils.getValidKey();
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await 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)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2018-10-13 01:48:49 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2018-10-13 01:48:49 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.pages);
|
|
|
|
should.exist(jsonResponse.meta);
|
2021-03-10 17:19:11 +03:00
|
|
|
jsonResponse.pages.should.have.length(5);
|
2018-10-13 01:48:49 +03:00
|
|
|
|
2021-03-10 17:19:11 +03:00
|
|
|
res.body.pages[0].slug.should.eql('about');
|
2020-11-30 17:25:22 +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
|
|
|
});
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request page', async function () {
|
2018-10-17 12:48:06 +03:00
|
|
|
const key = localUtils.getValidKey();
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await 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)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
res.headers.vary.should.eql('Accept-Encoding');
|
|
|
|
should.exist(res.headers['access-control-allow-origin']);
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
should.exist(jsonResponse.pages);
|
|
|
|
jsonResponse.pages.should.have.length(1);
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
res.body.pages[0].slug.should.eql(testUtils.DataGenerator.Content.posts[5].slug);
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
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
|
|
|
});
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|