@@ -163,6 +163,7 @@ describe('Suggestions Controller', () => {
163
163
let opportunityNotEnabled ;
164
164
let removeStub ;
165
165
let suggs ;
166
+ let altTextSuggs ;
166
167
let context ;
167
168
let apikeyAuthAttributes ;
168
169
@@ -257,8 +258,48 @@ describe('Suggestions Controller', () => {
257
258
258
259
] ;
259
260
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
+
260
300
const isHandlerEnabledForSite = sandbox . stub ( ) ;
261
301
isHandlerEnabledForSite . withArgs ( 'broken-backlinks-auto-fix' , site ) . returns ( true ) ;
302
+ isHandlerEnabledForSite . withArgs ( 'alt-text-auto-fix' , site ) . returns ( true ) ;
262
303
isHandlerEnabledForSite . withArgs ( 'meta-tags-auto-fix' , site ) . returns ( true ) ;
263
304
isHandlerEnabledForSite . withArgs ( 'broken-backlinks-auto-fix' , siteNotEnabled ) . returns ( false ) ;
264
305
mockOpportunity = {
@@ -1358,6 +1399,41 @@ describe('Suggestions Controller', () => {
1358
1399
expect ( bulkPatchResponse . suggestions [ 1 ] . suggestion ) . to . have . property ( 'status' , 'IN_PROGRESS' ) ;
1359
1400
} ) ;
1360
1401
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
+
1361
1437
it ( 'auto-fix suggestions status returns bad request if no site ID is passed' , async ( ) => {
1362
1438
const response = await suggestionsController . autofixSuggestions ( {
1363
1439
params : {
0 commit comments