From 2a14ef7f11ce1a60e41dd60acdf8c7267ead47bd Mon Sep 17 00:00:00 2001 From: Josep Lopez Date: Mon, 24 Feb 2025 15:02:38 +0100 Subject: [PATCH] chore: add logging --- src/image-alt-text/opportunityHandler.js | 12 +++++++++++- .../image-alt-text/opportunity-handler.test.js | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/image-alt-text/opportunityHandler.js b/src/image-alt-text/opportunityHandler.js index 09d88260..a31ee6e4 100644 --- a/src/image-alt-text/opportunityHandler.js +++ b/src/image-alt-text/opportunityHandler.js @@ -27,10 +27,19 @@ const getImageSuggestionIdentifier = (suggestion) => `${suggestion.pageUrl}/${su */ export async function syncAltTextSuggestions({ opportunity, newSuggestions, log }) { const existingSuggestions = await opportunity.getSuggestions(); + log.info(`existingSuggestions: ${JSON.stringify(existingSuggestions)}`); // eslint-disable-next-line max-len - const ignoredSuggestions = existingSuggestions.filter((s) => s.status === SuggestionModel.STATUSES.SKIPPED); + const ignoredSuggestions = existingSuggestions.filter((sug) => { + log.info(`sug ${sug}`); + const parsedSuggestion = JSON.parse(JSON.stringify(sug)); + log.info(`parsedSuggestion: ${JSON.stringify(parsedSuggestion)}`); + log.info(`parsedSuggestion.rank: ${parsedSuggestion.rank}`); + return parsedSuggestion.status === SuggestionModel.STATUSES.SKIPPED; + }); + log.info(`Ignored suggestions: ${JSON.stringify(ignoredSuggestions)}`); const ignoredSuggestionIds = ignoredSuggestions.map((s) => s.data.recommendations[0].id); + log.info(`Ignored suggestion ids: ${JSON.stringify(ignoredSuggestionIds)}`); // Remove existing suggestions that were not ignored await Promise.all(existingSuggestions @@ -38,6 +47,7 @@ export async function syncAltTextSuggestions({ opportunity, newSuggestions, log .map((suggestion) => suggestion.remove())); const suggestionsToAdd = newSuggestions.filter((s) => !ignoredSuggestionIds.includes(s.id)); + log.info(`suggestionsToAdd: ${JSON.stringify(suggestionsToAdd)}`); // Add new suggestions to oppty if (isNonEmptyArray(suggestionsToAdd)) { diff --git a/test/audits/image-alt-text/opportunity-handler.test.js b/test/audits/image-alt-text/opportunity-handler.test.js index 55780c90..e4e83f76 100644 --- a/test/audits/image-alt-text/opportunity-handler.test.js +++ b/test/audits/image-alt-text/opportunity-handler.test.js @@ -217,13 +217,13 @@ describe('Image Alt Text Opportunity Handler', () => { { id: 'suggestion-1', status: SuggestionModel.STATUSES.SKIPPED, - data: { recommendations: [{ id: 'suggestion-1' }] }, // Add data.id to match handler's expectation + data: { recommendations: [{ id: 'suggestion-1' }] }, remove: sinon.stub().resolves(), }, { id: 'suggestion-2', status: 'NEW', - data: { recommendations: [{ id: 'suggestion-2' }] }, // Add data.id to match handler's expectation + data: { recommendations: [{ id: 'suggestion-2' }] }, remove: sinon.stub().resolves(), }, ];