mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
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
This commit is contained in:
parent
d8a7edd9aa
commit
803a325ade
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
@ -1,6 +1,6 @@
|
||||
module.exports = {
|
||||
get postLookup() {
|
||||
return require('./post-lookup');
|
||||
get entryLookup() {
|
||||
return require('./entry-lookup');
|
||||
},
|
||||
|
||||
get fetchData() {
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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);
|
Loading…
Reference in New Issue
Block a user