From b855f2d8f0b26bd13a62f2feb197db7da02fb47a Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Fri, 5 Oct 2018 14:49:58 +0200 Subject: [PATCH] Removed `testUtils.API.getApiPath` refs #9866 - the global utility should for now not generate API urls - we only have one test which generates the API url - for now it will live in this test file - if we have multiple cases, we can reconsider this --- core/test/unit/services/url/utils_spec.js | 41 ++++++++++++++++------- core/test/utils/api.js | 17 ---------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/core/test/unit/services/url/utils_spec.js b/core/test/unit/services/url/utils_spec.js index 022dae01b8..c0963a5a33 100644 --- a/core/test/unit/services/url/utils_spec.js +++ b/core/test/unit/services/url/utils_spec.js @@ -439,6 +439,23 @@ describe('Url', function () { }); ['deprecated', 'active'].forEach((apiVersion) => { + function getApiPath(options) { + const baseAPIPath = '/ghost/api/'; + + switch (options.version) { + case 'deprecated': + return `${baseAPIPath}v0.1/`; + case 'active': + if (options.versionType === 'admin') { + return `${baseAPIPath}v2/admin/`; + } else { + return `${baseAPIPath}v2/content/`; + } + default: + return `${baseAPIPath}v0.1/`; + } + } + describe(`for api version: ${apiVersion}`, function () { it('api: should return admin url is set', function () { configUtils.set({ @@ -450,7 +467,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}, true) - .should.eql(`https://something.de${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`https://something.de${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: url has subdir', function () { @@ -460,13 +477,13 @@ describe('Url', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}, true) - .should.eql(`http://my-ghost-blog.com/blog${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`http://my-ghost-blog.com/blog${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: relative path is correct', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}) - .should.eql(testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})); + .should.eql(getApiPath({version: apiVersion, versionType: 'content'})); }); it('api: relative path with subdir is correct', function () { @@ -476,7 +493,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}) - .should.eql(`/blog${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`/blog${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: should return http if config.url is http', function () { @@ -486,7 +503,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}, true) - .should.eql(`http://my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`http://my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: should return https if config.url is https', function () { @@ -496,7 +513,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {version: apiVersion, versionType: 'content'}, true) - .should.eql(`https://my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`https://my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with cors, blog url is http: should return no protocol', function () { @@ -506,7 +523,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'content'}, true) - .should.eql(`//my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`//my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with cors, admin url is http: cors should return no protocol', function () { @@ -519,7 +536,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'content'}, true) - .should.eql(`//admin.ghost.example${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`//admin.ghost.example${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with cors, admin url is https: should return with protocol', function () { @@ -532,7 +549,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'content'}, true) - .should.eql(`https://admin.ghost.example${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`https://admin.ghost.example${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with cors, blog url is https: should return with protocol', function () { @@ -542,7 +559,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'content'}, true) - .should.eql(`https://my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`https://my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with stable version, blog url is https: should return stable content api path', function () { @@ -552,7 +569,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'content'}, true) - .should.eql(`https://my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'content'})}`); + .should.eql(`https://my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'content'})}`); }); it('api: with stable version and admin true, blog url is https: should return stable admin api path', function () { @@ -562,7 +579,7 @@ describe('Url', function () { urlService.utils .urlFor('api', {cors: true, version: apiVersion, versionType: 'admin'}, true) - .should.eql(`https://my-ghost-blog.com${testUtils.API.getApiPath({version: apiVersion, versionType: 'admin'})}`); + .should.eql(`https://my-ghost-blog.com${getApiPath({version: apiVersion, versionType: 'admin'})}`); }); }); }); diff --git a/core/test/utils/api.js b/core/test/utils/api.js index b4de08de04..7e60065643 100644 --- a/core/test/utils/api.js +++ b/core/test/utils/api.js @@ -56,22 +56,6 @@ var _ = require('lodash'), webhook: _.keys(schema.webhooks) }; -function getApiPath(options) { - const baseAPIPath = '/ghost/api/'; - switch (options.version) { - case 'deprecated': - return `${baseAPIPath}v0.1/`; - case 'active': - if (options.versionType === 'admin') { - return `${baseAPIPath}v2/admin/`; - } else { - return `${baseAPIPath}v2/content/`; - } - default: - return `${baseAPIPath}v0.1/`; - } -} - function getURL() { return protocol + host; } @@ -119,7 +103,6 @@ function checkResponse(jsonResponse, objectType, additionalProperties, missingPr } module.exports = { - getApiPath: getApiPath, getSigninURL: getSigninURL, getAdminURL: getAdminURL, getURL: getURL,