Skip to content

Commit

Permalink
fix: include richResult verdict
Browse files Browse the repository at this point in the history
  • Loading branch information
dzehnder committed Aug 21, 2024
1 parent 561e433 commit 711b292
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 67 deletions.
12 changes: 8 additions & 4 deletions src/structured-data/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { AuditBuilder } from '../common/audit-builder.js';
*
* @throws {Error} - Throws an error if the audit process fails.
*/
export async function processUrlInspect(baseURL, context, pages) {
export async function processStructuredData(baseURL, context, pages) {
const { log } = context;

let google;
Expand Down Expand Up @@ -74,11 +74,15 @@ export async function processUrlInspect(baseURL, context, pages) {
} else {
log.info(`No rich results issues found for URL: ${page}`);
}

return {
inspectionUrl: page,
indexStatusResult: filteredIndexStatusResult,
richResults: filteredRichResults,
richResults: inspectionResult?.richResultsResult
? {
verdict: inspectionResult.richResultsResult.verdict,
detectedIssues: filteredRichResults,
}
: {},
};
} catch (error) {
log.error(`Failed to inspect URL: ${page}. Error: ${error.message}`);
Expand All @@ -105,7 +109,7 @@ export async function structuredDataHandler(baseURL, context, site) {
throw new Error(`No product detail pages found for site: ${baseURL}`);
}

const auditResult = await processUrlInspect(baseURL, context, productDetailPages);
const auditResult = await processStructuredData(baseURL, context, productDetailPages);

const endTime = process.hrtime(startTime);
const elapsedSeconds = endTime[0] + endTime[1] / 1e9;
Expand Down
132 changes: 69 additions & 63 deletions test/audits/structured-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,73 +138,79 @@ describe('URLInspect Audit', () => {
verdict: 'PASS',
lastCrawlTime: '2024-08-13T22:35:22Z',
},
richResults: [
{
richResultType: 'Product snippets',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "image"',
severity: 'ERROR',
},
],
},
],
},
{
richResultType: 'Merchant listings',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "shippingDetails"',
severity: 'ERROR',
},
],
},
],
},
],
richResults: {
verdict: 'PASS',
detectedIssues: [
{
richResultType: 'Product snippets',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "image"',
severity: 'ERROR',
},
],
},
],
},
{
richResultType: 'Merchant listings',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "shippingDetails"',
severity: 'ERROR',
},
],
},
],
},
],
},
},
{
inspectionUrl: 'https://example.com/product/2',
indexStatusResult: {
verdict: 'PASS',
lastCrawlTime: '2024-08-13T22:35:22Z',
},
richResults: [
{
richResultType: 'Product snippets',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "image"',
severity: 'ERROR',
},
],
},
],
},
{
richResultType: 'Merchant listings',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "shippingDetails"',
severity: 'ERROR',
},
],
},
],
},
],
richResults: {
verdict: 'PASS',
detectedIssues: [
{
richResultType: 'Product snippets',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "image"',
severity: 'ERROR',
},
],
},
],
},
{
richResultType: 'Merchant listings',
items: [
{
name: 'Example Product Name',
issues: [
{
issueMessage: 'Missing field "shippingDetails"',
severity: 'ERROR',
},
],
},
],
},
],
},
},
],
);
Expand All @@ -217,7 +223,7 @@ describe('URLInspect Audit', () => {

const auditData = await structuredDataHandler('https://www.example.com', context, siteStub);

expect(auditData.auditResult[0].richResults).to.deep.equal([]);
expect(auditData.auditResult[0].richResults).to.deep.equal({});
});

it('returns no rich results when there are no errors in rich results', async () => {
Expand All @@ -230,8 +236,8 @@ describe('URLInspect Audit', () => {

const auditData = await structuredDataHandler('https://www.example.com', context, siteStub);

expect(auditData.auditResult[0].richResults).to.deep.equal([]);
expect(auditData.auditResult[1].richResults).to.deep.equal([]);
expect(auditData.auditResult[0].richResults.detectedIssues).to.deep.equal([]);
expect(auditData.auditResult[1].richResults.verdict).to.equal('PASS');
});

it('throws error if there are no configured PDPs', async () => {
Expand Down

0 comments on commit 711b292

Please sign in to comment.