0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added regression test coverage for editing deprecated settings

refs #10318
refs 118b7033e0

- Adds test coverage for fix introduced in referenedc commit
This commit is contained in:
Nazar Gargol 2020-06-24 22:40:57 +12:00
parent 118b7033e0
commit 8f1905990d
2 changed files with 85 additions and 15 deletions

View file

@ -185,6 +185,44 @@ describe('Settings API (canary)', function () {
}); });
}); });
it('can edit deprecated default_locale setting', function () {
return request.get(localUtils.API.getApiQuery('settings/default_locale/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.then(function (res) {
let jsonResponse = res.body;
const newValue = 'new value';
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings = [{key: 'default_locale', value: 'ua'}];
return jsonResponse;
})
.then((editedSetting) => {
return request.put(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url'))
.send(editedSetting)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then(function (res) {
should.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('default_locale');
jsonResponse.settings[0].value.should.eql('ua');
});
});
});
it('Can read timezone', function (done) { it('Can read timezone', function (done) {
request.get(localUtils.API.getApiQuery('settings/timezone/')) request.get(localUtils.API.getApiQuery('settings/timezone/'))
.set('Origin', config.get('url')) .set('Origin', config.get('url'))
@ -358,34 +396,29 @@ describe('Settings API (canary)', function () {
}); });
}); });
it('can\'t edit non existent setting', function (done) { it('can\'t edit non existent setting', function () {
request.get(localUtils.API.getApiQuery('settings/')) return request.get(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url')) .set('Origin', config.get('url'))
.set('Accept', 'application/json') .set('Accept', 'application/json')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
.end(function (err, res) { .then(function (res) {
if (err) {
return done(err);
}
let jsonResponse = res.body; let jsonResponse = res.body;
const newValue = 'new value'; const newValue = 'new value';
should.exist(jsonResponse); should.exist(jsonResponse);
should.exist(jsonResponse.settings); should.exist(jsonResponse.settings);
jsonResponse.settings = [{key: 'testvalue', value: newValue}]; jsonResponse.settings = [{key: 'testvalue', value: newValue}];
request.put(localUtils.API.getApiQuery('settings/')) return jsonResponse;
})
.then((jsonResponse) => {
return request.put(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url')) .set('Origin', config.get('url'))
.send(jsonResponse) .send(jsonResponse)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private) .expect('Cache-Control', testUtils.cacheRules.private)
.expect(404) .expect(404)
.end(function (err, res) { .then(function (res) {
if (err) {
return done(err);
}
jsonResponse = res.body; jsonResponse = res.body;
should.not.exist(res.headers['x-cache-invalidate']); should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.errors); should.exist(jsonResponse.errors);
@ -399,7 +432,6 @@ describe('Settings API (canary)', function () {
'code', 'code',
'id' 'id'
]); ]);
done();
}); });
}); });
}); });

View file

@ -50,7 +50,7 @@ const defaultSettingsKeys = [
'default_locale' 'default_locale'
]; ];
describe('Settings API (canary)', function () { describe('Settings API (v3)', function () {
let ghostServer; let ghostServer;
let request; let request;
@ -163,6 +163,44 @@ describe('Settings API (canary)', function () {
}); });
}); });
it('can edit deprecated default_locale setting', function () {
return request.get(localUtils.API.getApiQuery('settings/default_locale/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.then(function (res) {
let jsonResponse = res.body;
const newValue = 'new value';
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings = [{key: 'default_locale', value: 'ua'}];
return jsonResponse;
})
.then((editedSetting) => {
return request.put(localUtils.API.getApiQuery('settings/'))
.set('Origin', config.get('url'))
.send(editedSetting)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then(function (res) {
should.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.settings);
jsonResponse.settings.length.should.eql(1);
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'created_at', 'updated_at']);
jsonResponse.settings[0].key.should.eql('default_locale');
jsonResponse.settings[0].value.should.eql('ua');
});
});
});
it('Can read timezone', function (done) { it('Can read timezone', function (done) {
request.get(localUtils.API.getApiQuery('settings/timezone/')) request.get(localUtils.API.getApiQuery('settings/timezone/'))
.set('Origin', config.get('url')) .set('Origin', config.get('url'))