@@ -987,65 +987,78 @@ describe('Asset API Tests', () => {
987987 // ==========================================================================
988988
989989 describe ( 'Asset Scan Status' , ( ) => {
990- let scanAssetUid
990+ let assetUid
991991
992992 before ( async function ( ) {
993993 this . timeout ( 30000 )
994- // Reuse the image asset uploaded earlier — avoids a redundant upload
995- if ( testData . assets && testData . assets . image && testData . assets . image . uid ) {
996- scanAssetUid = testData . assets . image . uid
994+ // Reuse an asset created by the Asset Upload block to avoid an extra upload.
995+ // Fall back to creating a fresh one only if that block didn't succeed.
996+ if ( testData . assets . image && testData . assets . image . uid ) {
997+ assetUid = testData . assets . image . uid
997998 return
998999 }
999- // Fallback: create a fresh asset if the upload block didn't run
10001000 try {
10011001 const asset = await stack . asset ( ) . create ( {
10021002 upload : assetPath ,
1003- title : `Scan Status Asset ${ Date . now ( ) } ` ,
1004- description : 'Fallback asset for scan- status tests '
1003+ title : `Scan Status Test Asset ${ Date . now ( ) } ` ,
1004+ description : 'Asset for scan status testing '
10051005 } )
1006- scanAssetUid = asset . uid
1006+ assetUid = asset . uid
10071007 } catch ( err ) {
1008- // Individual tests will self-skip when scanAssetUid is unset
1008+ // Asset creation failed — individual tests will skip themselves.
10091009 }
10101010 } )
10111011
10121012 it ( 'should accept include_asset_scan_status param on single asset fetch' , async function ( ) {
1013- this . timeout ( 15000 )
1014- if ( ! scanAssetUid ) return this . skip ( )
1015-
1016- const asset = await stack . asset ( scanAssetUid ) . fetch ( { include_asset_scan_status : true } )
1013+ if ( ! assetUid ) return this . skip ( )
1014+ const asset = await stack . asset ( assetUid ) . fetch ( { include_asset_scan_status : true } )
10171015
10181016 expect ( asset ) . to . be . an ( 'object' )
1019- expect ( asset . uid ) . to . equal ( scanAssetUid )
1020- // _asset_scan_status is opt-in: present only when asset scanning is enabled for the stack .
1021- // Possible values: 'pending' | 'clean' | 'quarantined' | 'not_scanned'
1017+ expect ( asset . uid ) . to . equal ( assetUid )
1018+ // _asset_scan_status is opt-in. When scanning is enabled: pending | clean | quarantined .
1019+ // When scanning is not enabled for the stack, the API returns 'not_scanned'.
10221020 if ( '_asset_scan_status' in asset ) {
10231021 expect ( asset . _asset_scan_status ) . to . be . a ( 'string' )
10241022 expect ( [ 'pending' , 'clean' , 'quarantined' , 'not_scanned' ] ) . to . include ( asset . _asset_scan_status )
10251023 }
10261024 } )
10271025
10281026 it ( 'should accept include_asset_scan_status param on asset list query' , async function ( ) {
1029- this . timeout ( 15000 )
1030-
10311027 const response = await stack . asset ( ) . query ( { include_asset_scan_status : true } ) . find ( )
10321028
10331029 expect ( response ) . to . be . an ( 'object' )
10341030 expect ( response . items ) . to . be . an ( 'array' )
1031+ // pending | clean | quarantined when scanning is enabled; not_scanned otherwise.
10351032 if ( response . items . length > 0 && '_asset_scan_status' in response . items [ 0 ] ) {
10361033 expect ( response . items [ 0 ] . _asset_scan_status ) . to . be . a ( 'string' )
10371034 expect ( [ 'pending' , 'clean' , 'quarantined' , 'not_scanned' ] ) . to . include ( response . items [ 0 ] . _asset_scan_status )
10381035 }
10391036 } )
10401037
1041- it ( 'should NOT return _asset_scan_status when param is omitted' , async function ( ) {
1042- this . timeout ( 15000 )
1043- if ( ! scanAssetUid ) return this . skip ( )
1044-
1045- const asset = await stack . asset ( scanAssetUid ) . fetch ( )
1038+ it ( 'should not return _asset_scan_status when param is omitted' , async function ( ) {
1039+ if ( ! assetUid ) return this . skip ( )
1040+ const asset = await stack . asset ( assetUid ) . fetch ( )
10461041
10471042 expect ( asset ) . to . be . an ( 'object' )
10481043 expect ( asset ) . to . not . have . property ( '_asset_scan_status' )
10491044 } )
1045+
1046+ it ( 'should accept include_asset_scan_status param on asset upload' , async function ( ) {
1047+ this . timeout ( 30000 )
1048+ const asset = await stack . asset ( ) . create (
1049+ {
1050+ upload : assetPath ,
1051+ title : `Scan Status Upload Test ${ Date . now ( ) } `
1052+ } ,
1053+ { include_asset_scan_status : true }
1054+ )
1055+
1056+ expect ( asset ) . to . be . an ( 'object' )
1057+ expect ( asset . uid ) . to . be . a ( 'string' )
1058+ // pending when scanning is enabled; not_scanned when scanning is not enabled for the stack.
1059+ if ( '_asset_scan_status' in asset ) {
1060+ expect ( [ 'pending' , 'not_scanned' ] ) . to . include ( asset . _asset_scan_status )
1061+ }
1062+ } )
10501063 } )
10511064} )
0 commit comments