Fixed webmentions unit test coverage
no issue Try catch was not covered
This commit is contained in:
parent
dda1293ec0
commit
603e0909c9
@ -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 () {
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user