2018-10-12 20:44:02 +03:00
|
|
|
const should = require('should');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const os = require('os');
|
|
|
|
const fs = require('fs-extra');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../core/shared/config');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils');
|
2018-10-12 20:44:02 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
let request;
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
describe('Settings API', function () {
|
2018-10-12 20:44:02 +03:00
|
|
|
let ghostServer;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then(function (_ghostServer) {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
return ghostServer.stop();
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('Can request all settings', function (done) {
|
2018-10-12 20:44:02 +03:00
|
|
|
request.get(localUtils.API.getApiQuery('settings/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
2018-10-12 20:44:02 +03:00
|
|
|
should.exist(jsonResponse);
|
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(jsonResponse, 'settings');
|
2018-10-12 20:44:02 +03:00
|
|
|
|
|
|
|
JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).isActive.should.eql(true);
|
|
|
|
JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(true);
|
|
|
|
should.not.exist(_.find(jsonResponse.settings, {key: 'permalinks'}));
|
2019-09-23 13:59:00 +03:00
|
|
|
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_head'}));
|
|
|
|
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_foot'}));
|
2018-10-12 20:44:02 +03:00
|
|
|
|
|
|
|
testUtils.API.isISO8601(jsonResponse.settings[0].created_at).should.be.true();
|
|
|
|
jsonResponse.settings[0].created_at.should.be.an.instanceof(String);
|
|
|
|
|
|
|
|
should.not.exist(_.find(jsonResponse.settings, function (setting) {
|
|
|
|
return setting.type === 'core';
|
|
|
|
}));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('Can read a setting', function (done) {
|
2019-09-23 13:59:00 +03:00
|
|
|
request.get(localUtils.API.getApiQuery('settings/codeinjection_head/'))
|
2018-10-12 20:44:02 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
2019-03-05 00:59:13 +03:00
|
|
|
const jsonResponse = res.body;
|
2018-10-12 20:44:02 +03:00
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
2019-03-05 00:59:13 +03:00
|
|
|
jsonResponse.settings.length.should.eql(1);
|
|
|
|
|
2020-06-24 13:58:15 +03:00
|
|
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
2019-09-23 13:59:00 +03:00
|
|
|
jsonResponse.settings[0].key.should.eql('codeinjection_head');
|
2018-10-12 20:44:02 +03:00
|
|
|
testUtils.API.isISO8601(jsonResponse.settings[0].created_at).should.be.true();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
it('Can edit a setting', function () {
|
|
|
|
return request.get(localUtils.API.getApiQuery('settings/'))
|
2018-10-12 20:44:02 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function (res) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const jsonResponse = res.body;
|
|
|
|
const changedValue = [];
|
|
|
|
|
|
|
|
const settingToChange = {
|
|
|
|
settings: [
|
|
|
|
{
|
|
|
|
key: 'title',
|
|
|
|
value: changedValue
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'codeinjection_head',
|
|
|
|
value: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'navigation',
|
|
|
|
value: {label: 'label1'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'slack',
|
|
|
|
value: JSON.stringify({username: 'username'})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'is_private',
|
|
|
|
value: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'meta_title',
|
|
|
|
value: 'SEO title'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'meta_description',
|
|
|
|
value: 'SEO description'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'og_image',
|
|
|
|
value: '/content/images/2019/07/facebook.png'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'og_title',
|
|
|
|
value: 'facebook title'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'og_description',
|
|
|
|
value: 'facebook description'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'twitter_image',
|
|
|
|
value: '/content/images/2019/07/twitter.png'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'twitter_title',
|
|
|
|
value: 'twitter title'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'twitter_description',
|
|
|
|
value: 'twitter description'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'labs',
|
|
|
|
value: '{"subscribers":false,"members":true}'
|
2020-06-22 14:21:00 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'lang',
|
|
|
|
value: 'ua'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'timezone',
|
|
|
|
value: 'Pacific/Auckland'
|
2020-04-29 18:44:27 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2018-10-12 20:44:02 +03:00
|
|
|
|
|
|
|
should.exist(jsonResponse);
|
|
|
|
should.exist(jsonResponse.settings);
|
|
|
|
|
2020-10-19 07:45:26 +03:00
|
|
|
return request.put(localUtils.API.getApiQuery('settings/'))
|
2018-10-12 20:44:02 +03:00
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.send(settingToChange)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
2020-10-19 07:45:26 +03:00
|
|
|
.then(function ({body, headers}) {
|
|
|
|
const putBody = body;
|
|
|
|
headers['x-cache-invalidate'].should.eql('/*');
|
2018-10-12 20:44:02 +03:00
|
|
|
should.exist(putBody);
|
2019-03-05 00:59:13 +03:00
|
|
|
|
|
|
|
putBody.settings[0].key.should.eql('title');
|
2018-10-12 20:44:02 +03:00
|
|
|
putBody.settings[0].value.should.eql(JSON.stringify(changedValue));
|
2019-03-05 00:59:13 +03:00
|
|
|
|
|
|
|
putBody.settings[1].key.should.eql('codeinjection_head');
|
2019-03-04 19:00:07 +03:00
|
|
|
should.equal(putBody.settings[1].value, null);
|
2019-03-05 00:59:13 +03:00
|
|
|
|
|
|
|
putBody.settings[2].key.should.eql('navigation');
|
2019-03-04 19:00:07 +03:00
|
|
|
should.equal(putBody.settings[2].value, JSON.stringify({label: 'label1'}));
|
2019-03-05 00:59:13 +03:00
|
|
|
|
|
|
|
putBody.settings[3].key.should.eql('slack');
|
2019-03-04 19:00:07 +03:00
|
|
|
should.equal(putBody.settings[3].value, JSON.stringify({username: 'username'}));
|
2019-03-05 00:59:13 +03:00
|
|
|
|
2019-03-06 14:56:26 +03:00
|
|
|
putBody.settings[4].key.should.eql('is_private');
|
|
|
|
should.equal(putBody.settings[4].value, false);
|
|
|
|
|
2019-07-18 17:24:34 +03:00
|
|
|
putBody.settings[5].key.should.eql('meta_title');
|
|
|
|
should.equal(putBody.settings[5].value, 'SEO title');
|
|
|
|
|
|
|
|
putBody.settings[6].key.should.eql('meta_description');
|
|
|
|
should.equal(putBody.settings[6].value, 'SEO description');
|
|
|
|
|
|
|
|
putBody.settings[6].key.should.eql('meta_description');
|
|
|
|
should.equal(putBody.settings[6].value, 'SEO description');
|
|
|
|
|
|
|
|
putBody.settings[7].key.should.eql('og_image');
|
|
|
|
should.equal(putBody.settings[7].value, '/content/images/2019/07/facebook.png');
|
|
|
|
|
|
|
|
putBody.settings[8].key.should.eql('og_title');
|
|
|
|
should.equal(putBody.settings[8].value, 'facebook title');
|
|
|
|
|
|
|
|
putBody.settings[9].key.should.eql('og_description');
|
|
|
|
should.equal(putBody.settings[9].value, 'facebook description');
|
|
|
|
|
|
|
|
putBody.settings[10].key.should.eql('twitter_image');
|
|
|
|
should.equal(putBody.settings[10].value, '/content/images/2019/07/twitter.png');
|
|
|
|
|
|
|
|
putBody.settings[11].key.should.eql('twitter_title');
|
|
|
|
should.equal(putBody.settings[11].value, 'twitter title');
|
|
|
|
|
|
|
|
putBody.settings[12].key.should.eql('twitter_description');
|
|
|
|
should.equal(putBody.settings[12].value, 'twitter description');
|
|
|
|
|
2019-09-26 16:40:24 +03:00
|
|
|
putBody.settings[13].key.should.eql('labs');
|
2019-10-09 11:26:54 +03:00
|
|
|
should.equal(putBody.settings[13].value, '{"subscribers":false,"members":true}');
|
2019-09-26 16:40:24 +03:00
|
|
|
|
2020-06-22 14:21:00 +03:00
|
|
|
putBody.settings[14].key.should.eql('lang');
|
|
|
|
should.equal(putBody.settings[14].value, 'ua');
|
|
|
|
|
|
|
|
putBody.settings[15].key.should.eql('timezone');
|
|
|
|
should.equal(putBody.settings[15].value, 'Pacific/Auckland');
|
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
localUtils.API.checkResponse(putBody, 'settings');
|
2018-10-12 20:44:02 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('Can download routes.yaml', function () {
|
2018-10-12 20:44:02 +03:00
|
|
|
return request.get(localUtils.API.getApiQuery('settings/routes/yaml/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/yaml')
|
|
|
|
.expect(200)
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((res) => {
|
2018-10-12 20:44:02 +03:00
|
|
|
res.headers['content-disposition'].should.eql('Attachment; filename="routes.yaml"');
|
|
|
|
res.headers['content-type'].should.eql('application/yaml; charset=utf-8');
|
|
|
|
res.headers['content-length'].should.eql('138');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('Can upload routes.yaml', function () {
|
2018-10-12 20:44:02 +03:00
|
|
|
const newRoutesYamlPath = `${os.tmpdir()}/routes.yaml`;
|
|
|
|
|
|
|
|
return fs.writeFile(newRoutesYamlPath, 'routes:\ncollections:\ntaxonomies:\n')
|
2019-07-05 14:40:43 +03:00
|
|
|
.then(() => {
|
2018-10-12 20:44:02 +03:00
|
|
|
return request
|
|
|
|
.post(localUtils.API.getApiQuery('settings/routes/yaml/'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.attach('routes', newRoutesYamlPath)
|
|
|
|
.expect('Content-Type', /application\/json/)
|
|
|
|
.expect(200);
|
|
|
|
})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((res) => {
|
2018-10-12 20:44:02 +03:00
|
|
|
res.headers['x-cache-invalidate'].should.eql('/*');
|
|
|
|
})
|
2019-07-05 14:40:43 +03:00
|
|
|
.finally(() => {
|
2018-10-12 20:44:02 +03:00
|
|
|
return ghostServer.stop();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|