Skip to content

Commit

Permalink
refactor: migrated metatags and broken backlinks audit to use the Aud…
Browse files Browse the repository at this point in the history
…itBuilder
  • Loading branch information
martinst06 committed Dec 16, 2024
1 parent 2b0d015 commit 2572108
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/backlinks/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import AhrefsAPIClient from '@adobe/spacecat-shared-ahrefs-client';
import { AbortController, AbortError } from '@adobe/fetch';
import { retrieveSiteBySiteId, syncSuggestions } from '../utils/data-access.js';
import { enhanceBacklinksWithFixes } from '../support/utils.js';
import { AuditBuilder } from '../common/audit-builder.js';
import { noopUrlResolver } from '../common/audit.js';

const TIMEOUT = 3000;

Expand Down Expand Up @@ -60,7 +62,7 @@ export async function filterOutValidBacklinks(backlinks, log) {
return backlinks.filter((_, index) => backlinkStatuses[index]);
}

export default async function auditBrokenBacklinks(message, context) {
export async function auditBrokenBacklinks(message, context) {
const { type, auditContext = {} } = message;
const { dataAccess, log, sqs } = context;
const {
Expand Down Expand Up @@ -219,3 +221,8 @@ export default async function auditBrokenBacklinks(message, context) {
return internalServerError(`Internal server error: ${e.message}`);
}
}

export default new AuditBuilder()
.withUrlResolver(noopUrlResolver)
.withRunner(auditBrokenBacklinks)
.build();
9 changes: 8 additions & 1 deletion src/metatags/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { retrieveSiteBySiteId } from '../utils/data-access.js';
import { getObjectFromKey, getObjectKeysUsingPrefix } from '../utils/s3-utils.js';
import SeoChecks from './seo-checks.js';
import syncOpportunityAndSuggestions from './opportunityHandler.js';
import { AuditBuilder } from '../common/audit-builder.js';
import { noopUrlResolver } from '../common/audit.js';

async function fetchAndProcessPageObject(s3Client, bucketName, key, prefix, log) {
const object = await getObjectFromKey(s3Client, bucketName, key, log);
Expand All @@ -35,7 +37,7 @@ async function fetchAndProcessPageObject(s3Client, bucketName, key, prefix, log)
};
}

export default async function auditMetaTags(message, context) {
export async function auditMetaTags(message, context) {
const { type, auditContext = {} } = message;
const siteId = message.siteId || message.url;
const {
Expand Down Expand Up @@ -120,3 +122,8 @@ export default async function auditMetaTags(message, context) {
return internalServerError(`Internal server error: ${e.message}`);
}
}

export default new AuditBuilder()
.withUrlResolver(noopUrlResolver)
.withRunner(auditMetaTags)
.build();
2 changes: 1 addition & 1 deletion test/audits/backlinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import nock from 'nock';
import auditBrokenBacklinks from '../../src/backlinks/handler.js';
import { auditBrokenBacklinks } from '../../src/backlinks/handler.js';

use(sinonChai);
use(chaiAsPromised);
Expand Down
2 changes: 1 addition & 1 deletion test/audits/metatags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
SEO_RECOMMENDATION, MULTIPLE_H1_ON_PAGE, SHOULD_BE_PRESENT, TAG_LENGTHS, ONE_H1_ON_A_PAGE,
} from '../../src/metatags/constants.js';
import SeoChecks from '../../src/metatags/seo-checks.js';
import auditMetaTags from '../../src/metatags/handler.js';
import { auditMetaTags } from '../../src/metatags/handler.js';
import syncOpportunityAndSuggestions from '../../src/metatags/opportunityHandler.js';
import testData from '../fixtures/meta-tags-data.js';

Expand Down

0 comments on commit 2572108

Please sign in to comment.