From 0248853cf34c34c8c44ed727da53874a0d097a11 Mon Sep 17 00:00:00 2001 From: paraschi Date: Tue, 13 Aug 2024 19:05:15 +0300 Subject: [PATCH] feat: pr review update test --- src/canonical/handler.js | 1 - test/audits/canonical.test.js | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/canonical/handler.js b/src/canonical/handler.js index 18b8f922..815641d6 100644 --- a/src/canonical/handler.js +++ b/src/canonical/handler.js @@ -513,7 +513,6 @@ export async function canonicalAuditRunner(baseURL, context, site) { }, {}); log.info(`Successfully completed Canonical Audit for site: ${baseURL}`); - log.info(`Audit results: ${JSON.stringify(aggregatedResults)}`); return { fullAuditRef: baseURL, diff --git a/test/audits/canonical.test.js b/test/audits/canonical.test.js index affaeaeb..63b5483a 100644 --- a/test/audits/canonical.test.js +++ b/test/audits/canonical.test.js @@ -523,13 +523,35 @@ describe('Canonical URL Tests', () => { it('should run canonical audit successfully', async () => { const baseURL = 'http://example.com'; const html = ``; - nock('http://example.com/page1').get('').reply(200, html); - const context = { log, dataAccess: { getTopPagesForSite: sinon.stub().resolves([{ getURL: () => 'http://example.com/page1' }]) } }; + + nock('http://example.com').get('/page1').reply(200, html); + nock(baseURL).get('/').reply(200, html); + const getTopPagesForSiteStub = sinon.stub().resolves([{ getURL: () => 'http://example.com/page1' }]); + + const context = { + log, + dataAccess: { + getTopPagesForSite: getTopPagesForSiteStub, + }, + }; const site = { getId: () => 'testSiteId' }; const result = await canonicalAuditRunner(baseURL, context, site); expect(result).to.be.an('object'); + expect(result.auditResult).to.have.all.keys( + 'canonical-self-referenced', + 'canonical-tag-exists', + 'canonical-tag-in-head', + 'canonical-tag-nonempty', + 'canonical-url-absolute', + 'canonical-url-lowercased', + 'canonical-url-same-domain', + 'canonical-url-same-protocol', + 'canonical-url-no-redirect', + 'canonical-url-status-ok', + ); + expect(getTopPagesForSiteStub).to.have.been.calledOnceWith('testSiteId', 'ahrefs', 'global'); expect(log.info).to.have.been.called; });