@@ -217,7 +217,7 @@ test('flags', async () => {
217217 expect ( typeof TheCommand . flags . action ) . toBe ( 'object' )
218218 expect ( TheCommand . flags . action . char ) . toBe ( 'a' )
219219 expect ( typeof TheCommand . flags . action . description ) . toBe ( 'string' )
220- expect ( JSON . stringify ( TheCommand . flags . action . exclusive ) ) . toStrictEqual ( JSON . stringify ( [ 'extension' , { name : 'publish' , when : ( ) => { } } ] ) )
220+ expect ( JSON . stringify ( TheCommand . flags . action . exclusive ) ) . toStrictEqual ( JSON . stringify ( [ 'extension' , { name : 'publish' , when : ( ) => { } } ] ) )
221221
222222 expect ( typeof TheCommand . flags [ 'web-assets' ] ) . toBe ( 'object' )
223223 expect ( typeof TheCommand . flags [ 'web-assets' ] . description ) . toBe ( 'string' )
@@ -1324,11 +1324,11 @@ describe('run', () => {
13241324 expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
13251325 expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
13261326 expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1327- expect ( auditLogger . sendAuditLogs . mock . calls . length ) . toBeLessThanOrEqual ( 2 )
1327+ expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledTimes ( 1 )
13281328 expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledWith ( mockToken , expect . objectContaining ( { orgId : mockOrg , projectId : mockProject , workspaceId : mockWorkspaceId , workspaceName : mockWorkspaceName } ) , mockEnv )
13291329 } )
13301330
1331- test ( 'Do not send audit logs for successful app deploy' , async ( ) => {
1331+ test ( 'Do not send audit logs for successful app deploy, if no logevent is present ' , async ( ) => {
13321332 const mockToken = 'mocktoken'
13331333 const mockEnv = 'stage'
13341334 const mockOrg = 'mockorg'
@@ -1362,6 +1362,43 @@ describe('run', () => {
13621362 expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
13631363 expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
13641364 expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1365+ expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledTimes ( 0 )
1366+ } )
1367+
1368+ test ( 'Do not send audit logs for successful app deploy, if case of no token' , async ( ) => {
1369+ const mockToken = null
1370+ const mockEnv = 'stage'
1371+ const mockOrg = 'mockorg'
1372+ const mockProject = 'mockproject'
1373+ const mockWorkspaceId = 'mockworkspaceid'
1374+ const mockWorkspaceName = 'mockworkspacename'
1375+
1376+ helpers . getCliInfo . mockResolvedValueOnce ( {
1377+ accessToken : mockToken ,
1378+ env : mockEnv
1379+ } )
1380+
1381+ command . getFullConfig = jest . fn ( ) . mockReturnValue ( {
1382+ aio : {
1383+ project : {
1384+ id : mockProject ,
1385+ org : {
1386+ id : mockOrg
1387+ } ,
1388+ workspace : {
1389+ id : mockWorkspaceId ,
1390+ name : mockWorkspaceName
1391+ }
1392+ }
1393+ }
1394+ } )
1395+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
1396+
1397+ await command . run ( )
1398+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
1399+ expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
1400+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1401+ expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledTimes ( 0 )
13651402 } )
13661403
13671404 test ( 'Send audit logs for successful app deploy + web assets' , async ( ) => {
@@ -1403,4 +1440,51 @@ describe('run', () => {
14031440 expect ( auditLogger . getFilesCountWithExtension ) . toHaveBeenCalledTimes ( 2 )
14041441 expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledWith ( mockToken , expect . objectContaining ( { orgId : mockOrg , projectId : mockProject , workspaceId : mockWorkspaceId , workspaceName : mockWorkspaceName } ) , mockEnv )
14051442 } )
1443+
1444+ test ( 'Should deploy successfully even if Audit log service is unavailable' , async ( ) => {
1445+ const mockToken = 'mocktoken'
1446+ const mockEnv = 'stage'
1447+ const mockOrg = 'mockorg'
1448+ const mockProject = 'mockproject'
1449+ const mockWorkspaceId = 'mockworkspaceid'
1450+ const mockWorkspaceName = 'mockworkspacename'
1451+ helpers . getCliInfo . mockResolvedValueOnce ( {
1452+ accessToken : mockToken ,
1453+ env : mockEnv
1454+ } )
1455+ command . getFullConfig = jest . fn ( ) . mockReturnValue ( {
1456+ aio : {
1457+ project : {
1458+ id : mockProject ,
1459+ org : {
1460+ id : mockOrg
1461+ } ,
1462+ workspace : {
1463+ id : mockWorkspaceId ,
1464+ name : mockWorkspaceName
1465+ }
1466+ }
1467+ }
1468+ } )
1469+
1470+ auditLogger . sendAuditLogs . mockRejectedValue ( {
1471+ message : 'Internal Server Error' ,
1472+ status : 500
1473+ } )
1474+
1475+ command . getAppExtConfigs . mockResolvedValueOnce ( createAppConfig ( command . appConfig ) )
1476+
1477+ await command . run ( )
1478+ expect ( command . log ) . toHaveBeenCalledWith (
1479+ expect . stringContaining ( 'skipping publish phase...' )
1480+ )
1481+
1482+ expect ( command . log ) . toHaveBeenCalledWith (
1483+ expect . stringContaining ( 'Successful deployment 🏄' )
1484+ )
1485+ expect ( auditLogger . sendAuditLogs ) . toHaveBeenCalledTimes ( 1 )
1486+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
1487+ expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
1488+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1489+ } )
14061490} )
0 commit comments