From 39e403d176de7a923a62cb91159ef97e84187c08 Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 5 Oct 2020 17:52:40 +1300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20meta=20attributes=20calc?= =?UTF-8?q?ulation=20on=20post=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/12247 - Internal preview controller was lacking "mapping" call to post object which handled not only missing meta attribute information but lots of other mappings (e.g. users, tags, etc.) - Have added a regression test to catch issues like this in the future --- core/server/api/canary/utils/serializers/output/preview.js | 4 +++- core/server/api/v2/utils/serializers/output/preview.js | 4 +++- test/regression/site/frontend_spec.js | 2 ++ test/utils/fixtures/data-generator.js | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/server/api/canary/utils/serializers/output/preview.js b/core/server/api/canary/utils/serializers/output/preview.js index 5339284b63..50f495934a 100644 --- a/core/server/api/canary/utils/serializers/output/preview.js +++ b/core/server/api/canary/utils/serializers/output/preview.js @@ -1,7 +1,9 @@ +const mapper = require('./utils/mapper'); + module.exports = { all(model, apiConfig, frame) { frame.response = { - preview: [model.toJSON(frame.options)] + preview: [mapper.mapPost(model, frame)] }; } }; diff --git a/core/server/api/v2/utils/serializers/output/preview.js b/core/server/api/v2/utils/serializers/output/preview.js index 5339284b63..50f495934a 100644 --- a/core/server/api/v2/utils/serializers/output/preview.js +++ b/core/server/api/v2/utils/serializers/output/preview.js @@ -1,7 +1,9 @@ +const mapper = require('./utils/mapper'); + module.exports = { all(model, apiConfig, frame) { frame.response = { - preview: [model.toJSON(frame.options)] + preview: [mapper.mapPost(model, frame)] }; } }; diff --git a/test/regression/site/frontend_spec.js b/test/regression/site/frontend_spec.js index f5fdaa4b13..d4eb4d4340 100644 --- a/test/regression/site/frontend_spec.js +++ b/test/regression/site/frontend_spec.js @@ -253,6 +253,8 @@ describe('Frontend Routing', function () { should.exist(res.headers.date); $('title').text().should.equal('Not finished yet'); + $('meta[name="description"]').attr('content').should.equal('meta description for draft post'); + // @TODO: use theme from fixtures and don't rely on content/themes/casper // $('.content .post').length.should.equal(1); // $('.poweredby').text().should.equal('Proudly published with Ghost'); diff --git a/test/utils/fixtures/data-generator.js b/test/utils/fixtures/data-generator.js index 9ee9565073..52dc5d4ddb 100644 --- a/test/utils/fixtures/data-generator.js +++ b/test/utils/fixtures/data-generator.js @@ -809,6 +809,11 @@ DataGenerator.forKnex = (function () { id: ObjectId.generate(), post_id: DataGenerator.Content.posts[2].id, meta_description: 'test stuff' + }, + { + id: ObjectId.generate(), + post_id: DataGenerator.Content.posts[3].id, + meta_description: 'meta description for draft post' } ];