@@ -1431,6 +1431,54 @@ describe('utils', () => {
14311431 } ) ;
14321432 } ) ;
14331433
1434+ describe ( 'queueDeliveryConfigWriter — Cloud Manager verification (SITES-47815)' , ( ) => {
1435+ const makeSite = ( ) => ( {
1436+ getId : ( ) => 'site-1' ,
1437+ getBaseURL : ( ) => 'https://example.com' ,
1438+ getAuthoringType : ( ) => 'cs' ,
1439+ getDeliveryType : ( ) => 'aem_cs' ,
1440+ getDeliveryConfig : ( ) => ( { programId : 'p1' , environmentId : 'e1' } ) ,
1441+ } ) ;
1442+
1443+ const makeContext = ( ) => ( {
1444+ env : { AUDIT_JOBS_QUEUE_URL : 'https://sqs.example.com/queue' } ,
1445+ log : { error : sinon . stub ( ) , info : sinon . stub ( ) , warn : sinon . stub ( ) } ,
1446+ sqs : { sendMessage : sinon . stub ( ) . resolves ( ) } ,
1447+ } ) ;
1448+
1449+ // Load utils with a controllable CloudManager client so we can exercise the
1450+ // verified / not-verified / degraded branches of queueDeliveryConfigWriter.
1451+ const loadWith = ( cmResult ) => esmock ( '../../src/support/utils.js' , {
1452+ '../../src/support/cloud-manager.js' : {
1453+ createCloudManagerClient : ( ) => ( { verifyProgram : async ( ) => cmResult } ) ,
1454+ } ,
1455+ } ) ;
1456+
1457+ it ( 'stamps programVerified=true when Cloud Manager verifies the program' , async ( ) => {
1458+ const { queueDeliveryConfigWriter : q } = await loadWith ( { verified : true } ) ;
1459+ const context = makeContext ( ) ;
1460+ await q ( { site : makeSite ( ) , baseURL : 'https://example.com' , slackContext : { } } , context ) ;
1461+ expect ( context . sqs . sendMessage . firstCall . args [ 1 ] . programVerified ) . to . equal ( true ) ;
1462+ expect ( context . log . warn ) . to . not . have . been . called ;
1463+ } ) ;
1464+
1465+ it ( 'warns and stamps programVerified=false when CM reports not-verified (not degraded)' , async ( ) => {
1466+ const { queueDeliveryConfigWriter : q } = await loadWith ( { verified : false , degraded : false } ) ;
1467+ const context = makeContext ( ) ;
1468+ await q ( { site : makeSite ( ) , baseURL : 'https://example.com' , slackContext : { } } , context ) ;
1469+ expect ( context . sqs . sendMessage . firstCall . args [ 1 ] . programVerified ) . to . equal ( false ) ;
1470+ expect ( context . log . warn ) . to . have . been . calledOnce ;
1471+ } ) ;
1472+
1473+ it ( 'does not warn when the connector is unavailable (degraded)' , async ( ) => {
1474+ const { queueDeliveryConfigWriter : q } = await loadWith ( { verified : false , degraded : true } ) ;
1475+ const context = makeContext ( ) ;
1476+ await q ( { site : makeSite ( ) , baseURL : 'https://example.com' , slackContext : { } } , context ) ;
1477+ expect ( context . sqs . sendMessage . firstCall . args [ 1 ] . programVerified ) . to . equal ( false ) ;
1478+ expect ( context . log . warn ) . to . not . have . been . called ;
1479+ } ) ;
1480+ } ) ;
1481+
14341482 describe ( 'sendAutofixMessage' , ( ) => {
14351483 let mockSqs ;
14361484
0 commit comments