Skip to content

Commit

Permalink
feat: adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiAlexandruParaschiv committed Aug 7, 2024
1 parent 513d846 commit 0240b7b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/audits/canonical.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('Canonical URL Tests', () => {

afterEach(() => {
sinon.restore();
nock.cleanAll();
});

describe('getTopPagesForSiteId', () => {
Expand Down Expand Up @@ -67,6 +66,19 @@ describe('Canonical URL Tests', () => {
expect(result).to.deep.equal([]);
expect(log.error).to.have.been.calledWith('Error retrieving top pages for site testSiteId: Test error');
});

it('should log and return an empty array if no top pages are found', async () => {
const dataAccess = {
getTopPagesForSite: sinon.stub().resolves([]),
};
const siteId = 'testSiteId';
const context = { log };

const result = await getTopPagesForSiteId(dataAccess, siteId, context, log);

expect(result).to.deep.equal([]);
expect(log.info).to.have.been.calledWith('No top pages found');
});
});

describe('validateCanonicalTag', () => {
Expand All @@ -86,6 +98,18 @@ describe('Canonical URL Tests', () => {
expect(log.info).to.have.been.called;
});

it('should return an error when URL is undefined or null', async () => {
const result = await validateCanonicalTag(null, log);

expect(result.canonicalUrl).to.be.null;
expect(result.checks).to.deep.include({
check: 'url-defined',
success: false,
explanation: 'The URL is undefined or null, which prevents the canonical tag validation process.',
});
expect(log.error).to.have.been.calledWith('URL is undefined or null');
});

it('should handle fetch error', async () => {
const url = 'http://example.com';
nock('http://example.com').get('/').replyWithError('Test error');
Expand Down

0 comments on commit 0240b7b

Please sign in to comment.