Skip to content

Commit

Permalink
chore: add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKid committed Feb 24, 2025
1 parent 5543f44 commit 789d40f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/image-alt-text/opportunityHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ export async function syncAltTextSuggestions({ opportunity, newSuggestions, log
const existingSuggestions = await opportunity.getSuggestions();

// eslint-disable-next-line max-len
const ignoredSuggestions = existingSuggestions.filter((s) => s.getStatus() === SuggestionModel.STATUSES.SKIPPED);
const ignoredSuggestions = existingSuggestions.filter((s) => {
log.info(`suggestion data: ${JSON.stringify(s.getData())}`);
log.info(`suggestion status: ${s.getStatus()}`);
return s.getStatus() === SuggestionModel.STATUSES.SKIPPED;
});
log.info(`ignored suggestions: ${JSON.stringify(ignoredSuggestions)}`);
const ignoredSuggestionIds = ignoredSuggestions.map((s) => s.getData().recommendations[0].id);
log.info(`ignored suggestion ids: ${JSON.stringify(ignoredSuggestionIds)}`);

// Remove existing suggestions that were not ignored
await Promise.all(existingSuggestions
Expand Down
19 changes: 19 additions & 0 deletions test/audits/image-alt-text/opportunity-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Image Alt Text Opportunity Handler', () => {
id: 'suggestion-1',
getStatus: () => 'NEW',
status: 'NEW',
getData: () => ({ recommendations: [{ id: 'suggestion-1' }] }),
remove: sinon.stub().resolves(),
}]),
addSuggestions: sinon
Expand Down Expand Up @@ -161,6 +162,15 @@ describe('Image Alt Text Opportunity Handler', () => {
it('should handle errors when adding suggestions', async () => {
dataAccessStub.Opportunity.allBySiteIdAndStatus.resolves([altTextOppty]);

// Update mock suggestion to include getData
altTextOppty.getSuggestions.returns([{
id: 'suggestion-1',
getStatus: () => 'NEW',
status: 'NEW',
getData: () => ({ recommendations: [{ id: 'suggestion-1' }] }),
remove: sinon.stub().resolves(),
}]);

// Mock error response from addSuggestions
altTextOppty.addSuggestions.returns({
errorItems: [
Expand All @@ -185,6 +195,15 @@ describe('Image Alt Text Opportunity Handler', () => {
it('should throw error when all suggestions fail to create', async () => {
dataAccessStub.Opportunity.allBySiteIdAndStatus.resolves([altTextOppty]);

// Update mock suggestion to include getData
altTextOppty.getSuggestions.returns([{
id: 'suggestion-1',
getStatus: () => 'NEW',
status: 'NEW',
getData: () => ({ recommendations: [{ id: 'suggestion-1' }] }),
remove: sinon.stub().resolves(),
}]);

// Mock error response from addSuggestions with no successful creations
altTextOppty.addSuggestions.returns({
errorItems: [
Expand Down

0 comments on commit 789d40f

Please sign in to comment.