diff --git a/src/structured-data/handler.js b/src/structured-data/handler.js index 4b1de01b..a11c7347 100644 --- a/src/structured-data/handler.js +++ b/src/structured-data/handler.js @@ -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; @@ -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}`); @@ -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; diff --git a/test/audits/structured-data.test.js b/test/audits/structured-data.test.js index e7d456c8..9710050c 100644 --- a/test/audits/structured-data.test.js +++ b/test/audits/structured-data.test.js @@ -138,36 +138,39 @@ 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', @@ -175,36 +178,39 @@ 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', + }, + ], + }, + ], + }, + ], + }, }, ], ); @@ -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 () => { @@ -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 () => {