From 603e0909c9b954874d0a8df263f0e9c4eaa9775f Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Wed, 22 Feb 2023 16:35:45 +0100 Subject: [PATCH] Fixed webmentions unit test coverage no issue Try catch was not covered --- .../test/MentionSendingService.test.js | 6 ----- ghost/webmentions/test/MentionsAPI.test.js | 26 ++++++++++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ghost/webmentions/test/MentionSendingService.test.js b/ghost/webmentions/test/MentionSendingService.test.js index e3454063e6..dd24527722 100644 --- a/ghost/webmentions/test/MentionSendingService.test.js +++ b/ghost/webmentions/test/MentionSendingService.test.js @@ -6,7 +6,6 @@ const externalRequest = require('../../core/core/server/lib/request-external.js' const sinon = require('sinon'); const logging = require('@tryghost/logging'); const {createModel} = require('./utils/index.js'); -const dnsPromises = require('dns').promises; // mock up job service let jobService = { @@ -22,11 +21,6 @@ describe('MentionSendingService', function () { nock.disableNetConnect(); sinon.stub(logging, 'info'); errorLogStub = sinon.stub(logging, 'error'); - - // externalRequest does dns lookup; stub to make sure we don't fail with fake domain names - sinon.stub(dnsPromises, 'lookup').callsFake(function () { - return Promise.resolve({address: '123.123.123.123', family: 4}); - }); }); afterEach(function () { diff --git a/ghost/webmentions/test/MentionsAPI.test.js b/ghost/webmentions/test/MentionsAPI.test.js index 7204133690..8e44eb241a 100644 --- a/ghost/webmentions/test/MentionsAPI.test.js +++ b/ghost/webmentions/test/MentionsAPI.test.js @@ -4,6 +4,7 @@ const Mention = require('../lib/Mention'); const MentionsAPI = require('../lib/MentionsAPI'); const InMemoryMentionRepository = require('../lib/InMemoryMentionRepository'); const sinon = require('sinon'); +const cheerio = require('cheerio'); const mockRoutingService = { async pageExists() { @@ -41,7 +42,7 @@ const mockWebmentionRequest = { function addMinutes(date, minutes) { date.setMinutes(date.getMinutes() + minutes); - + return date; } @@ -270,6 +271,29 @@ describe('MentionsAPI', function () { } }); + it('Handles verify errors', async function () { + const repository = new InMemoryMentionRepository(); + sinon.stub(cheerio, 'load').throws(new Error('Test error')); + + const api = new MentionsAPI({ + repository, + routingService: { + async pageExists() { + return true; + } + }, + resourceService: mockResourceService, + webmentionMetadata: mockWebmentionMetadata, + webmentionRequest: mockWebmentionRequest + }); + + await api.processWebmention({ + source: new URL('https://source.com'), + target: new URL('https://target.com'), + payload: {} + }); + }); + it('Will only store resource if if the resource type is post', async function () { const repository = new InMemoryMentionRepository(); const api = new MentionsAPI({