Skip to content

Commit 8df129e

Browse files
committed
fix: group alt-text by url
1 parent e975067 commit 8df129e

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

src/controllers/suggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ function SuggestionsController(ctx, sqs, env) {
515515
if (opportunity.getType() !== 'broken-backlinks') {
516516
const suggestionsByUrl = validSuggestions.reduce((acc, suggestion) => {
517517
const data = suggestion.getData();
518-
const url = data?.url || data?.pageUrl || data?.url_from;
518+
const url = data?.url || data?.recommendations?.[0]?.pageUrl || data?.url_from;
519519
if (!url) return acc;
520520

521521
if (!acc[url]) {

test/controllers/suggestions.test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ describe('Suggestions Controller', () => {
163163
let opportunityNotEnabled;
164164
let removeStub;
165165
let suggs;
166+
let altTextSuggs;
166167
let context;
167168
let apikeyAuthAttributes;
168169

@@ -257,8 +258,48 @@ describe('Suggestions Controller', () => {
257258

258259
];
259260

261+
altTextSuggs = [
262+
{
263+
id: SUGGESTION_IDS[0],
264+
opportunityId: OPPORTUNITY_ID,
265+
type: 'CONTENT_UPDATE',
266+
rank: 1,
267+
status: 'NEW',
268+
data: {
269+
recommendations: [
270+
{
271+
pageUrl: 'https://example.com/example-page',
272+
id: '1398acaa-99a8-4417-a8ee-a2e71d98028b',
273+
altText: 'A description of the image',
274+
imageUrl: 'https://image.example.com/image1.png',
275+
},
276+
],
277+
},
278+
updatedAt: new Date(),
279+
},
280+
{
281+
id: SUGGESTION_IDS[1],
282+
opportunityId: OPPORTUNITY_ID,
283+
type: 'CONTENT_UPDATE',
284+
rank: 2,
285+
status: 'NEW',
286+
data: {
287+
recommendations: [
288+
{
289+
pageUrl: 'https://example.com/another-page',
290+
id: '2398acaa-99a8-4417-a8ee-a2e71d98028c',
291+
altText: 'Another description of the image',
292+
imageUrl: 'https://image.example.com/image2.png',
293+
},
294+
],
295+
},
296+
updatedAt: new Date(),
297+
},
298+
];
299+
260300
const isHandlerEnabledForSite = sandbox.stub();
261301
isHandlerEnabledForSite.withArgs('broken-backlinks-auto-fix', site).returns(true);
302+
isHandlerEnabledForSite.withArgs('alt-text-auto-fix', site).returns(true);
262303
isHandlerEnabledForSite.withArgs('meta-tags-auto-fix', site).returns(true);
263304
isHandlerEnabledForSite.withArgs('broken-backlinks-auto-fix', siteNotEnabled).returns(false);
264305
mockOpportunity = {
@@ -1358,6 +1399,41 @@ describe('Suggestions Controller', () => {
13581399
expect(bulkPatchResponse.suggestions[1].suggestion).to.have.property('status', 'IN_PROGRESS');
13591400
});
13601401

1402+
it('triggers autofixSuggestion and sets suggestions to in-progress for alt-text', async () => {
1403+
opportunity.getType = sandbox.stub().returns('alt-text');
1404+
mockSuggestion.allByOpportunityId.resolves(
1405+
[mockSuggestionEntity(altTextSuggs[0]),
1406+
mockSuggestionEntity(altTextSuggs[1])],
1407+
);
1408+
mockSuggestion.bulkUpdateStatus.resolves([mockSuggestionEntity({ ...altTextSuggs[0], status: 'IN_PROGRESS' }),
1409+
mockSuggestionEntity({ ...altTextSuggs[1], status: 'IN_PROGRESS' })]);
1410+
const response = await suggestionsController.autofixSuggestions({
1411+
params: {
1412+
siteId: SITE_ID,
1413+
opportunityId: OPPORTUNITY_ID,
1414+
},
1415+
data: { suggestionIds: [SUGGESTION_IDS[0], SUGGESTION_IDS[1]] },
1416+
...context,
1417+
});
1418+
1419+
expect(response.status).to.equal(207);
1420+
const bulkPatchResponse = await response.json();
1421+
expect(bulkPatchResponse).to.have.property('suggestions');
1422+
expect(bulkPatchResponse).to.have.property('metadata');
1423+
expect(bulkPatchResponse.metadata).to.have.property('total', 2);
1424+
expect(bulkPatchResponse.metadata).to.have.property('success', 2);
1425+
expect(bulkPatchResponse.metadata).to.have.property('failed', 0);
1426+
expect(bulkPatchResponse.suggestions).to.have.property('length', 2);
1427+
expect(bulkPatchResponse.suggestions[0]).to.have.property('index', 0);
1428+
expect(bulkPatchResponse.suggestions[1]).to.have.property('index', 1);
1429+
expect(bulkPatchResponse.suggestions[0]).to.have.property('statusCode', 200);
1430+
expect(bulkPatchResponse.suggestions[1]).to.have.property('statusCode', 200);
1431+
expect(bulkPatchResponse.suggestions[0].suggestion).to.exist;
1432+
expect(bulkPatchResponse.suggestions[1].suggestion).to.exist;
1433+
expect(bulkPatchResponse.suggestions[0].suggestion).to.have.property('status', 'IN_PROGRESS');
1434+
expect(bulkPatchResponse.suggestions[1].suggestion).to.have.property('status', 'IN_PROGRESS');
1435+
});
1436+
13611437
it('auto-fix suggestions status returns bad request if no site ID is passed', async () => {
13621438
const response = await suggestionsController.autofixSuggestions({
13631439
params: {

0 commit comments

Comments
 (0)