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
This commit is contained in:
kirrg001 2018-10-05 14:49:58 +02:00 committed by Katharina Irrgang
parent b74879c64e
commit b855f2d8f0
2 changed files with 29 additions and 29 deletions

View File

@ -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'})}`);
});
});
});

View File

@ -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,