Refactored method urlFor to use versionType instead of admin: true

no issue

- Updated urlFor to work with versionType instead of admin:true
- Updated tests to use the correct method call
This commit is contained in:
Rish 2018-10-03 19:14:40 +05:30 committed by Rishabh Garg
parent a49bbfb9d6
commit dd151f3713
6 changed files with 28 additions and 29 deletions

View File

@ -44,7 +44,7 @@ function initialiseServices() {
scheduling.init({
schedulerUrl: config.get('scheduling').schedulerUrl,
active: config.get('scheduling').active,
apiUrl: urlService.utils.urlFor('api', {version: 'deprecated'}, true),
apiUrl: urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true),
internalPath: config.get('paths').internalSchedulingPath,
contentPath: config.getContentPath('scheduling')
})

View File

@ -327,8 +327,7 @@ function urlFor(context, data, absolute) {
}
if (data && data.version) {
let versionType = data.admin ? 'admin' : 'content';
apiPath = getApiPath({version: data.version, type: versionType});
apiPath = getApiPath({version: data.version, type: data.versionType});
}
if (absolute) {

View File

@ -39,7 +39,7 @@ module.exports = function setupParentApp(options = {}) {
// API
// @TODO: finish refactoring the API app
// @TODO: decide what to do with these paths - config defaults? config overrides?
parentApp.use(urlUtils.getApiPath({version: 'deprecated', type: 'content'}), require('./api/v0.1/app')());
parentApp.use(urlUtils.getApiPath({version: 'deprecated'}), require('./api/v0.1/app')());
parentApp.use(urlUtils.getApiPath({version: 'active', type: 'content'}), require('./api/v2/content/app')());
parentApp.use(urlUtils.getApiPath({version: 'active', type: 'admin'}), require('./api/v2/admin/app')());

View File

@ -26,7 +26,7 @@ function servePublicFile(file, type, maxAge) {
if (type === 'text/xsl' || type === 'text/plain' || type === 'application/javascript') {
buf = buf.toString().replace(blogRegex, urlService.utils.urlFor('home', true).replace(/\/$/, ''));
buf = buf.toString().replace(apiRegex, urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true));
buf = buf.toString().replace(apiRegex, urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true));
}
content = {
headers: {

View File

@ -27,7 +27,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: '',
clientSecret: '',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
ghostSdk.url.api().should.equal('//testblog.com/ghost/api/v0.1/');
@ -41,7 +41,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: '',
clientSecret: '',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
ghostSdk.url.api().should.equal('https://testblog.com/ghost/api/v0.1/');
@ -58,7 +58,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: '',
clientSecret: '',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
ghostSdk.url.api().should.equal('https://admin.testblog.com/ghost/api/v0.1/');
@ -68,7 +68,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: '',
clientSecret: '',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
ghostSdk.url.api('a/', '/b', '/c/').should.equal('//testblog.com/ghost/api/v0.1/a/b/c/');
@ -78,7 +78,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
ghostSdk.url.api().should.equal('//testblog.com/ghost/api/v0.1/?client_id=ghost-frontend&client_secret=notasecret');
@ -88,7 +88,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
var rendered = ghostSdk.url.api({a: 'string', b: 5, c: 'en coded'});
@ -126,7 +126,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
@ -146,7 +146,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true)
});
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
@ -165,7 +165,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true)
});
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
@ -185,7 +185,7 @@ describe('Ghost Ajax Helper', function () {
ghostSdk.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true)
url: urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true)
});
var rendered = ghostSdk.url.api('posts', {limit: 3}),

View File

@ -446,7 +446,7 @@ describe('Url', function () {
}
});
urlService.utils.urlFor('api', {version: 'deprecated'}, true).should.eql('https://something.de/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true).should.eql('https://something.de/ghost/api/v0.1/');
});
it('api: url has subdir', function () {
@ -454,11 +454,11 @@ describe('Url', function () {
url: 'http://my-ghost-blog.com/blog'
});
urlService.utils.urlFor('api', {version: 'deprecated'}, true).should.eql('http://my-ghost-blog.com/blog/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true).should.eql('http://my-ghost-blog.com/blog/ghost/api/v0.1/');
});
it('api: relative path is correct', function () {
urlService.utils.urlFor('api', {version: 'deprecated'}).should.eql('/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}).should.eql('/ghost/api/v0.1/');
});
it('api: relative path with subdir is correct', function () {
@ -466,7 +466,7 @@ describe('Url', function () {
url: 'http://my-ghost-blog.com/blog'
});
urlService.utils.urlFor('api', {version: 'deprecated'}).should.eql('/blog/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}).should.eql('/blog/ghost/api/v0.1/');
});
it('api: should return http if config.url is http', function () {
@ -474,7 +474,7 @@ describe('Url', function () {
url: 'http://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {version: 'deprecated'}, true).should.eql('http://my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true).should.eql('http://my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: should return https if config.url is https', function () {
@ -482,7 +482,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {version: 'deprecated'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {version: 'deprecated', versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: with cors, blog url is http: should return no protocol', function () {
@ -490,7 +490,7 @@ describe('Url', function () {
url: 'http://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true).should.eql('//my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true).should.eql('//my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: with cors, admin url is http: cors should return no protocol', function () {
@ -501,7 +501,7 @@ describe('Url', function () {
}
});
urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true).should.eql('//admin.ghost.example/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true).should.eql('//admin.ghost.example/ghost/api/v0.1/');
});
it('api: with cors, admin url is https: should return with protocol', function () {
@ -512,7 +512,7 @@ describe('Url', function () {
}
});
urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true).should.eql('https://admin.ghost.example/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true).should.eql('https://admin.ghost.example/ghost/api/v0.1/');
});
it('api: with cors, blog url is https: should return with protocol', function () {
@ -520,7 +520,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: 'deprecated'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: 'deprecated', versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: with stable version, blog url is https: should return stable content api path', function () {
@ -528,7 +528,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: "deprecated"}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: "deprecated", versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: with stable version and admin true, blog url is https: should return stable admin api path', function () {
@ -536,7 +536,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: "deprecated", admin: true}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
urlService.utils.urlFor('api', {cors: true, version: "deprecated", versionType: 'admin'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v0.1/');
});
it('api: with active version, blog url is https: should return active content api path', function () {
@ -544,7 +544,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: "active"}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/content/');
urlService.utils.urlFor('api', {cors: true, version: "active", versionType: 'content'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/content/');
});
it('api: with active version and admin true, blog url is https: should return active admin api path', function () {
@ -552,7 +552,7 @@ describe('Url', function () {
url: 'https://my-ghost-blog.com'
});
urlService.utils.urlFor('api', {cors: true, version: "active", admin: true}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/admin/');
urlService.utils.urlFor('api', {cors: true, version: "active", versionType: 'admin'}, true).should.eql('https://my-ghost-blog.com/ghost/api/v2/admin/');
});
});