From 8f1905990d825f9e40d3e57180658d9b019e4150 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Wed, 24 Jun 2020 22:40:57 +1200 Subject: [PATCH] Added regression test coverage for editing deprecated settings refs #10318 refs https://github.com/TryGhost/Ghost/commit/118b7033e0fb35aec60823c746248675248eddae - Adds test coverage for fix introduced in referenedc commit --- .../api/canary/admin/settings_spec.js | 60 ++++++++++++++----- test/regression/api/v3/admin/settings_spec.js | 40 ++++++++++++- 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/test/regression/api/canary/admin/settings_spec.js b/test/regression/api/canary/admin/settings_spec.js index 84e8bc631d..41cba84cc5 100644 --- a/test/regression/api/canary/admin/settings_spec.js +++ b/test/regression/api/canary/admin/settings_spec.js @@ -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) { request.get(localUtils.API.getApiQuery('settings/timezone/')) .set('Origin', config.get('url')) @@ -358,34 +396,29 @@ describe('Settings API (canary)', function () { }); }); - it('can\'t edit non existent setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can\'t edit non existent setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); 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')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(404) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { jsonResponse = res.body; should.not.exist(res.headers['x-cache-invalidate']); should.exist(jsonResponse.errors); @@ -399,7 +432,6 @@ describe('Settings API (canary)', function () { 'code', 'id' ]); - done(); }); }); }); diff --git a/test/regression/api/v3/admin/settings_spec.js b/test/regression/api/v3/admin/settings_spec.js index 73687261e9..102aca9ad2 100644 --- a/test/regression/api/v3/admin/settings_spec.js +++ b/test/regression/api/v3/admin/settings_spec.js @@ -50,7 +50,7 @@ const defaultSettingsKeys = [ 'default_locale' ]; -describe('Settings API (canary)', function () { +describe('Settings API (v3)', function () { let ghostServer; 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) { request.get(localUtils.API.getApiQuery('settings/timezone/')) .set('Origin', config.get('url'))