From a4427952e2d281f1439ad5951c9ac371cafd1f3a Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Wed, 14 Sep 2016 13:30:37 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20=F0=9F=9A=A8=20Update=20Am?= =?UTF-8?q?perize=20dep=20and=20fix=20test=20(#7374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue Updates Amperize dep to v0.3.1 and fixes test for `amp_content`. --- .../apps/amp/lib/helpers/amp_content.js | 2 +- .../server/apps/amp/tests/amp_content_spec.js | 35 ++++++++++++++++--- package.json | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/server/apps/amp/lib/helpers/amp_content.js b/core/server/apps/amp/lib/helpers/amp_content.js index ebd3bad667..1724f6c143 100644 --- a/core/server/apps/amp/lib/helpers/amp_content.js +++ b/core/server/apps/amp/lib/helpers/amp_content.js @@ -126,7 +126,7 @@ function getAmperizeHTML(html, post) { amperize.parse(html, function (err, res) { if (err) { if (err.src) { - errors.logError(err.message, 'AMP HTML couldn\'t get parsed:' + err.src); + errors.logError(err.message, 'AMP HTML couldn\'t get parsed: ' + err.src); } else { errors.logError(err); } diff --git a/core/server/apps/amp/tests/amp_content_spec.js b/core/server/apps/amp/tests/amp_content_spec.js index e9fae91ac9..9801a1c1ff 100644 --- a/core/server/apps/amp/tests/amp_content_spec.js +++ b/core/server/apps/amp/tests/amp_content_spec.js @@ -5,6 +5,8 @@ var should = require('should'), // Stuff we are testing ampContentHelper = rewire('../lib/helpers/amp_content'); +// TODO: Amperize really needs to get stubbed, so we can test returning errors +// properly and make this test faster! describe('{{amp_content}} helper', function () { afterEach(function () { ampContentHelper.__set__('amperizeCache', {}); @@ -109,7 +111,7 @@ describe('{{amp_content}} helper', function () { describe('Transforms and sanitizes HTML', function () { beforeEach(function () { - configUtils.set({url: 'https://my-awesome-blog.com/'}); + configUtils.set({url: 'https://blog.ghost.org/'}); }); afterEach(function () { @@ -119,11 +121,11 @@ describe('{{amp_content}} helper', function () { it('can transform img tags to amp-img', function (done) { var testData = { - html: 'The Ghost Logo', + html: 'The Ghost Logo', updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)', id: 1 }, - expectedResult = '', + expectedResult = '', ampResult = ampContentHelper.call(testData); ampResult.then(function (rendered) { @@ -183,7 +185,7 @@ describe('{{amp_content}} helper', function () { updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)', id: 1 }, - expectedResult = '

Hello

' + ' ' + ' ' + @@ -215,7 +217,7 @@ describe('{{amp_content}} helper', function () { }).catch(done); }); - it('can handle incomplete HTML tags', function (done) { + it('can handle incomplete HTML tags by returning not Amperized HTML', function (done) { var testData = { html: '', updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)', @@ -238,6 +240,29 @@ describe('{{amp_content}} helper', function () { }).catch(done); }); + it('can handle not existing img src by returning not Amperized HTML', function (done) { + var testData = { + html: 'The Ghost Logo', + updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)', + id: 1 + }, + ampResult = ampContentHelper.call(testData), + sanitizedHTML, + ampedHTML; + + ampResult.then(function (rendered) { + sanitizedHTML = ampContentHelper.__get__('cleanHTML'); + ampedHTML = ampContentHelper.__get__('ampHTML'); + should.exist(rendered); + rendered.string.should.equal(''); + should.exist(ampedHTML); + ampedHTML.should.be.equal('The Ghost Logo'); + should.exist(sanitizedHTML); + sanitizedHTML.should.be.equal(''); + done(); + }).catch(done); + }); + it('sanitizes remaining and not valid tags', function (done) { var testData = { html: '' + diff --git a/package.json b/package.json index ea583cb755..f529fb492f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "node": "~0.10.0 || ~0.12.0 || ^4.2.0" }, "dependencies": { - "amperize": "https://github.com/AileenCGN/amperize/tarball/error-handling-on-timeout", + "amperize": "0.3.1", "archiver": "1.0.1", "bcryptjs": "2.3.0", "bluebird": "3.4.1",
Name:Bill Gates
Telephone: