Skip to content

Commit

Permalink
Merge branch 'main' into sitemapoppty
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiAlexandruParaschiv authored Nov 13, 2024
2 parents ffa4196 + 5e51433 commit 6d685ac
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 26 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [1.32.12](https://github.com/adobe/spacecat-audit-worker/compare/v1.32.11...v1.32.12) (2024-11-13)


### Bug Fixes

* broken backlinks no longer because of migration to jobs-dispatcher ([#464](https://github.com/adobe/spacecat-audit-worker/issues/464)) ([cc38be2](https://github.com/adobe/spacecat-audit-worker/commit/cc38be247b1cea86977f3268e7c7bfe5ec6ceee5))

## [1.32.11](https://github.com/adobe/spacecat-audit-worker/compare/v1.32.10...v1.32.11) (2024-11-13)


### Bug Fixes

* **deps:** update dependency @adobe/spacecat-shared-data-access to v1.52.0 ([#463](https://github.com/adobe/spacecat-audit-worker/issues/463)) ([e8eb5a3](https://github.com/adobe/spacecat-audit-worker/commit/e8eb5a393b3e18799076c984d9c8b43608524e1f))

## [1.32.10](https://github.com/adobe/spacecat-audit-worker/compare/v1.32.9...v1.32.10) (2024-11-13)


### Bug Fixes

* broken internal links result schema update ([#460](https://github.com/adobe/spacecat-audit-worker/issues/460)) ([58d8171](https://github.com/adobe/spacecat-audit-worker/commit/58d81717fcbeedf4aa20d358a6fe7ec3a3b8f919))

## [1.32.9](https://github.com/adobe/spacecat-audit-worker/compare/v1.32.8...v1.32.9) (2024-11-12)


Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/spacecat-audit-worker",
"version": "1.32.9",
"version": "1.32.12",
"description": "SpaceCat Audit Worker",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -57,7 +57,7 @@
"@adobe/helix-universal": "5.0.6",
"@adobe/helix-universal-logger": "3.0.21",
"@adobe/spacecat-shared-ahrefs-client": "1.5.11",
"@adobe/spacecat-shared-data-access": "1.51.0",
"@adobe/spacecat-shared-data-access": "1.52.0",
"@adobe/spacecat-shared-google-client": "1.2.21",
"@adobe/spacecat-shared-http-utils": "1.6.18",
"@adobe/spacecat-shared-rum-api-client": "2.9.10",
Expand Down
4 changes: 2 additions & 2 deletions src/backlinks/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export async function filterOutValidBacklinks(backlinks, log) {
}

export default async function auditBrokenBacklinks(message, context) {
const { type, url: siteId, auditContext = {} } = message;
const { type, auditContext = {} } = message;
const { dataAccess, log, sqs } = context;
const {
AUDIT_RESULTS_QUEUE_URL: queueUrl,
} = context.env;

const siteId = message.url || message.siteId;
try {
log.info(`Received ${type} audit request for siteId: ${siteId}`);
const site = await retrieveSiteBySiteId(dataAccess, siteId, log);
Expand Down
15 changes: 10 additions & 5 deletions src/internal-links/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ function transform404LinksData(responseData, hostUrl, auditUrl, log) {
const sameDomainSources = allSources.filter(
(source) => source && hasSameHost(source, hostUrl),
);
if (sameDomainSources.length) {

for (const source of sameDomainSources) {
result.push({
url,
views,
sources: sameDomainSources,
url_to: url,
url_from: source,
traffic_domain: views,
});
}
} catch {
Expand Down Expand Up @@ -87,9 +88,13 @@ export async function internalLinksAuditRunner(auditUrl, context, site) {
granularity: 'hourly',
};

log.info('broken-internal-links: Options for RUM call: ', JSON.stringify(options));

const all404Links = await rumAPIClient.query('404', options);
const auditResult = {
internalLinks: transform404LinksData(all404Links, finalUrl, auditUrl, log),
brokenInternalLinks: transform404LinksData(all404Links, finalUrl, auditUrl, log),
fullAuditRef: auditUrl,
finalUrl,
auditContext: {
interval: INTERVAL,
},
Expand Down
40 changes: 40 additions & 0 deletions test/audits/backlinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,46 @@ describe('Backlinks Tests', function () {
expect(context.log.info).to.have.been.calledWith('Successfully audited site1 for broken-backlinks type audit');
});

it('should successfully perform an audit to detect broken backlinks, save and send the proper audit result for message containing siteId', async () => {
mockDataAccess.getSiteByID = sinon.stub().withArgs('site1').resolves(site);
mockDataAccess.getTopPagesForSite.resolves([]);
mockDataAccess.getConfiguration = sinon.stub().resolves(configuration);
message.siteId = message.url;
delete message.url;

nock(site.getBaseURL())
.get(/.*/)
.reply(200);

nock('https://ahrefs.com')
.get(/.*/)
.reply(200, auditResult);

const expectedMessage = {
type: message.type,
url: site.getBaseURL(),
auditContext: {
finalUrl: 'bar.foo.com',
},
auditResult: {
finalUrl: 'bar.foo.com',
brokenBacklinks: auditResult.backlinks,
fullAuditRef: 'https://ahrefs.com/site-explorer/broken-backlinks?select=title%2Curl_from%2Curl_to%2Ctraffic_domain&limit=50&mode=prefix&order_by=domain_rating_source%3Adesc%2Ctraffic_domain%3Adesc&target=bar.foo.com&output=json&where=%7B%22and%22%3A%5B%7B%22field%22%3A%22domain_rating_source%22%2C%22is%22%3A%5B%22gte%22%2C29.5%5D%7D%2C%7B%22field%22%3A%22traffic_domain%22%2C%22is%22%3A%5B%22gte%22%2C500%5D%7D%2C%7B%22field%22%3A%22links_external%22%2C%22is%22%3A%5B%22lte%22%2C300%5D%7D%5D%7D',
},
};

const response = await auditBrokenBacklinks(message, context);

expect(response.status).to.equal(204);
expect(mockDataAccess.addAudit).to.have.been.calledOnce;
expect(context.sqs.sendMessage).to.have.been.calledOnce;
expect(context.sqs.sendMessage).to.have.been
.calledWith(context.env.AUDIT_RESULTS_QUEUE_URL, expectedMessage);
expect(context.log.info).to.have.been.calledWith('Successfully audited site1 for broken-backlinks type audit');
message.url = message.siteId;
delete message.siteId;
});

it('should successfully perform an audit to detect broken backlinks and suggest fixes based on keywords from top pages if auto-suggest'
+ ' enabled', async () => {
mockDataAccess.getSiteByID = sinon.stub().withArgs('site1').resolves(site);
Expand Down
20 changes: 9 additions & 11 deletions test/audits/internal-links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ import { MockContextBuilder } from '../shared.js';

const AUDIT_RESULT_DATA = [
{
url: 'https://www.example.com/article/dogs/breeds/choosing-an-irish-setter',
views: 100,
sources: [
'https://www.example.com/article/dogs/just-for-fun/dogs-good-for-men-13-manly-masculine-dog-breeds',
],
url_to: 'https://www.example.com/article/dogs/breeds/choosing-an-irish-setter',
url_from: 'https://www.example.com/article/dogs/just-for-fun/dogs-good-for-men-13-manly-masculine-dog-breeds',
traffic_domain: 100,
},
{
url: 'https://www.example.com/article/dogs/breeds/choosing-a-miniature-poodle',
views: 100,
sources: [
'https://www.example.com/article/dogs/pet-care/when-is-a-dog-considered-senior',
],
url_to: 'https://www.example.com/article/dogs/breeds/choosing-a-miniature-poodle',
url_from: 'https://www.example.com/article/dogs/pet-care/when-is-a-dog-considered-senior',
traffic_domain: 100,
},
];

Expand Down Expand Up @@ -88,7 +84,9 @@ describe('Broken internal links audit', () => {
});
expect(result).to.deep.equal({
auditResult: {
internalLinks: AUDIT_RESULT_DATA,
brokenInternalLinks: AUDIT_RESULT_DATA,
fullAuditRef: auditUrl,
finalUrl: auditUrl,
auditContext: {
interval: 30,
},
Expand Down

0 comments on commit 6d685ac

Please sign in to comment.