From 803a325ade868c832c85249487912c49c2955fd8 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Wed, 17 Oct 2018 13:42:29 +0200 Subject: [PATCH] Renamed post-lookup to entry-lookup refs #9866 - the static pages router uses the entry controller - and the entry controller uses the lookup helper - the lookup helper needs to either fetch static pages or posts - v2 uses pages and posts controller --- core/server/apps/amp/lib/router.js | 2 +- .../services/routing/controllers/entry.js | 2 +- .../{post-lookup.js => entry-lookup.js} | 4 +-- core/server/services/routing/helpers/index.js | 4 +-- core/test/unit/apps/amp/router_spec.js | 16 +++++------ .../routing/controllers/entry_spec.js | 22 +++++++-------- ...st-lookup_spec.js => entry-lookup_spec.js} | 28 +++++++++---------- 7 files changed, 39 insertions(+), 39 deletions(-) rename core/server/services/routing/helpers/{post-lookup.js => entry-lookup.js} (95%) rename core/test/unit/services/routing/helpers/{post-lookup_spec.js => entry-lookup_spec.js} (88%) diff --git a/core/server/apps/amp/lib/router.js b/core/server/apps/amp/lib/router.js index 29b00836a1..91b731ada3 100644 --- a/core/server/apps/amp/lib/router.js +++ b/core/server/apps/amp/lib/router.js @@ -63,7 +63,7 @@ function getPostData(req, res, next) { })); } - helpers.postLookup(urlWithoutSubdirectoryWithoutAmp, {permalinks}, res.locals) + helpers.entryLookup(urlWithoutSubdirectoryWithoutAmp, {permalinks}, res.locals) .then((result) => { if (result && result.post) { req.body.post = result.post; diff --git a/core/server/services/routing/controllers/entry.js b/core/server/services/routing/controllers/entry.js index e09f8f6bd3..658d5e6bd8 100644 --- a/core/server/services/routing/controllers/entry.js +++ b/core/server/services/routing/controllers/entry.js @@ -12,7 +12,7 @@ const debug = require('ghost-ignition').debug('services:routing:controllers:entr module.exports = function entryController(req, res, next) { debug('entryController', res.routerOptions); - return helpers.postLookup(req.path, res.routerOptions, res.locals) + return helpers.entryLookup(req.path, res.routerOptions, res.locals) .then(function then(lookup) { // Format data 1 const post = lookup ? lookup.post : false; diff --git a/core/server/services/routing/helpers/post-lookup.js b/core/server/services/routing/helpers/entry-lookup.js similarity index 95% rename from core/server/services/routing/helpers/post-lookup.js rename to core/server/services/routing/helpers/entry-lookup.js index 4233369d01..df829eb500 100644 --- a/core/server/services/routing/helpers/post-lookup.js +++ b/core/server/services/routing/helpers/entry-lookup.js @@ -4,7 +4,7 @@ const _ = require('lodash'), debug = require('ghost-ignition').debug('services:routing:helpers:post-lookup'), routeMatch = require('path-match')(); -function postLookup(postUrl, routerOptions, locals) { +function entryLookup(postUrl, routerOptions, locals) { debug(postUrl); const api = require('../../../api')[locals.apiVersion]; @@ -59,4 +59,4 @@ function postLookup(postUrl, routerOptions, locals) { }); } -module.exports = postLookup; +module.exports = entryLookup; diff --git a/core/server/services/routing/helpers/index.js b/core/server/services/routing/helpers/index.js index 4f53ff3be4..cd2e51082c 100644 --- a/core/server/services/routing/helpers/index.js +++ b/core/server/services/routing/helpers/index.js @@ -1,6 +1,6 @@ module.exports = { - get postLookup() { - return require('./post-lookup'); + get entryLookup() { + return require('./entry-lookup'); }, get fetchData() { diff --git a/core/test/unit/apps/amp/router_spec.js b/core/test/unit/apps/amp/router_spec.js index 27bcb64d83..d756a5467d 100644 --- a/core/test/unit/apps/amp/router_spec.js +++ b/core/test/unit/apps/amp/router_spec.js @@ -94,7 +94,7 @@ describe('Unit - apps/amp/lib/router', function () { }); describe('fn: getPostData', function () { - let res, req, postLookupStub, post; + let res, req, entryLookupStub, post; beforeEach(function () { post = testUtils.DataGenerator.forKnex.createPost({slug: 'welcome'}); @@ -105,10 +105,10 @@ describe('Unit - apps/amp/lib/router', function () { req = {}; - postLookupStub = sandbox.stub(); + entryLookupStub = sandbox.stub(); - sandbox.stub(helpers, 'postLookup').get(function () { - return postLookupStub; + sandbox.stub(helpers, 'entryLookup').get(function () { + return entryLookupStub; }); sandbox.stub(urlService, 'getPermalinkByUrl'); @@ -123,7 +123,7 @@ describe('Unit - apps/amp/lib/router', function () { urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/'); - helpers.postLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).resolves({ + helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).resolves({ post: post }); @@ -139,7 +139,7 @@ describe('Unit - apps/amp/lib/router', function () { urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/'); - helpers.postLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).resolves({ + helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).resolves({ post: post }); @@ -149,12 +149,12 @@ describe('Unit - apps/amp/lib/router', function () { }); }); - it('should return error if postlookup returns NotFoundError', function (done) { + it('should return error if entrylookup returns NotFoundError', function (done) { res.locals.relativeUrl = req.originalUrl = '/welcome/amp'; urlService.getPermalinkByUrl.withArgs('/welcome/').returns('/:slug/'); - helpers.postLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).rejects(new common.errors.NotFoundError()); + helpers.entryLookup.withArgs('/welcome/', {permalinks: '/:slug/'}).rejects(new common.errors.NotFoundError()); ampController.getPostData(req, res, function (err) { (err instanceof common.errors.NotFoundError).should.be.true(); diff --git a/core/test/unit/services/routing/controllers/entry_spec.js b/core/test/unit/services/routing/controllers/entry_spec.js index 4a29d1a46f..3a7d39ecfb 100644 --- a/core/test/unit/services/routing/controllers/entry_spec.js +++ b/core/test/unit/services/routing/controllers/entry_spec.js @@ -9,7 +9,7 @@ const should = require('should'), EDITOR_URL = '/editor/'; describe('Unit - services/routing/controllers/entry', function () { - let req, res, postLookUpStub, secureStub, renderStub, post, page; + let req, res, entryLookUpStub, secureStub, renderStub, post, page; beforeEach(function () { post = testUtils.DataGenerator.forKnex.createPost(); @@ -18,11 +18,11 @@ describe('Unit - services/routing/controllers/entry', function () { page = testUtils.DataGenerator.forKnex.createPost({page: 1}); secureStub = sandbox.stub(); - postLookUpStub = sandbox.stub(); + entryLookUpStub = sandbox.stub(); renderStub = sandbox.stub(); - sandbox.stub(helpers, 'postLookup').get(function () { - return postLookUpStub; + sandbox.stub(helpers, 'entryLookup').get(function () { + return entryLookUpStub; }); sandbox.stub(helpers, 'secure').get(function () { @@ -59,7 +59,7 @@ describe('Unit - services/routing/controllers/entry', function () { it('resource not found', function (done) { req.path = '/does-not-exist/'; - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves(null); controllers.entry(req, res, function (err) { @@ -82,7 +82,7 @@ describe('Unit - services/routing/controllers/entry', function () { } }); - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ post: post }); @@ -99,7 +99,7 @@ describe('Unit - services/routing/controllers/entry', function () { it('isUnknownOption: true', function (done) { req.path = post.url; - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ isUnknownOption: true, post: post @@ -114,7 +114,7 @@ describe('Unit - services/routing/controllers/entry', function () { it('isEditURL: true', function (done) { req.path = post.url; - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ isEditURL: true, post: post @@ -139,7 +139,7 @@ describe('Unit - services/routing/controllers/entry', function () { } }); - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ post: post }); @@ -163,7 +163,7 @@ describe('Unit - services/routing/controllers/entry', function () { } }); - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ post: post }); @@ -192,7 +192,7 @@ describe('Unit - services/routing/controllers/entry', function () { } }); - postLookUpStub.withArgs(req.path, res.routerOptions) + entryLookUpStub.withArgs(req.path, res.routerOptions) .resolves({ post: post }); diff --git a/core/test/unit/services/routing/helpers/post-lookup_spec.js b/core/test/unit/services/routing/helpers/entry-lookup_spec.js similarity index 88% rename from core/test/unit/services/routing/helpers/post-lookup_spec.js rename to core/test/unit/services/routing/helpers/entry-lookup_spec.js index aff9295987..c249860532 100644 --- a/core/test/unit/services/routing/helpers/post-lookup_spec.js +++ b/core/test/unit/services/routing/helpers/entry-lookup_spec.js @@ -6,7 +6,7 @@ const should = require('should'), helpers = require('../../../../../server/services/routing/helpers'), sandbox = sinon.sandbox.create(); -describe('Unit - services/routing/helpers/post-lookup', function () { +describe('Unit - services/routing/helpers/entry-lookup', function () { let posts, locals; afterEach(function () { @@ -38,7 +38,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup absolute url: /:slug/', function (done) { const testUrl = 'http://127.0.0.1:2369' + posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals).then(function (lookup) { + helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) { api.posts.read.calledOnce.should.be.true(); should.exist(lookup.post); lookup.post.should.have.property('url', posts[0].url); @@ -51,7 +51,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup relative url: /:slug/', function (done) { const testUrl = posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals).then(function (lookup) { + helpers.entryLookup(testUrl, routerOptions, locals).then(function (lookup) { api.posts.read.calledOnce.should.be.true(); should.exist(lookup.post); lookup.post.should.have.property('url', posts[0].url); @@ -64,7 +64,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup absolute url: /:year/:month/:day/:slug/', function (done) { const testUrl = 'http://127.0.0.1:2369/2016/01/01' + posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -76,7 +76,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup relative url: /:year/:month/:day/:slug/', function (done) { const testUrl = '/2016/01/01' + posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -105,7 +105,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup absolute url: /:slug/', function (done) { const testUrl = 'http://127.0.0.1:2369/' + posts[0].slug; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -117,7 +117,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup relative url using :slug', function (done) { const testUrl = posts[0].slug; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -129,7 +129,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup absolute url: /:year/:month/:day/:slug/', function (done) { const testUrl = 'http://127.0.0.1:2369' + posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.true(); should.exist(lookup.post); @@ -144,7 +144,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup relative url: /:year/:month/:day/:slug/', function (done) { const testUrl = posts[0].url; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.true(); should.exist(lookup.post); @@ -174,7 +174,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup absolute url: /:slug/edit/', function (done) { const testUrl = 'http://127.0.0.1:2369' + posts[0].url + 'edit/'; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.true(); lookup.post.should.have.property('url', posts[0].url); @@ -187,7 +187,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('can lookup relative url: /:slug/edit/', function (done) { const testUrl = posts[0].url + 'edit/'; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.true(); lookup.post.should.have.property('url', posts[0].url); @@ -200,7 +200,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup absolute url: /:year/:month/:day/:slug/edit/', function (done) { const testUrl = 'http://127.0.0.1:2369/2016/01/01' + posts[0].url + 'edit/'; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -212,7 +212,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('cannot lookup relative url: /:year/:month/:day/:slug/edit/', function (done) { const testUrl = '/2016/01/01' + posts[0].url + 'edit/'; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup); @@ -224,7 +224,7 @@ describe('Unit - services/routing/helpers/post-lookup', function () { it('unknown url option', function (done) { const testUrl = posts[0].url + 'not-edit/'; - helpers.postLookup(testUrl, routerOptions, locals) + helpers.entryLookup(testUrl, routerOptions, locals) .then(function (lookup) { api.posts.read.calledOnce.should.be.false(); should.not.exist(lookup);