@@ -981,4 +981,84 @@ describe('Asset API Tests', () => {
981981 }
982982 } )
983983 } )
984+
985+ // ==========================================================================
986+ // ASSET SCAN STATUS
987+ // ==========================================================================
988+
989+ describe ( 'Asset Scan Status' , ( ) => {
990+ let assetUid
991+
992+ before ( async function ( ) {
993+ this . timeout ( 30000 )
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
998+ return
999+ }
1000+ try {
1001+ const asset = await stack . asset ( ) . create ( {
1002+ upload : assetPath ,
1003+ title : `Scan Status Test Asset ${ Date . now ( ) } ` ,
1004+ description : 'Asset for scan status testing'
1005+ } )
1006+ assetUid = asset . uid
1007+ } catch ( err ) {
1008+ // Asset creation failed — individual tests will skip themselves.
1009+ }
1010+ } )
1011+
1012+ it ( 'should accept include_asset_scan_status param on single asset fetch' , async function ( ) {
1013+ if ( ! assetUid ) return this . skip ( )
1014+ const asset = await stack . asset ( assetUid ) . fetch ( { include_asset_scan_status : true } )
1015+
1016+ expect ( asset ) . to . be . an ( 'object' )
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'.
1020+ if ( '_asset_scan_status' in asset ) {
1021+ expect ( asset . _asset_scan_status ) . to . be . a ( 'string' )
1022+ expect ( [ 'pending' , 'clean' , 'quarantined' , 'not_scanned' ] ) . to . include ( asset . _asset_scan_status )
1023+ }
1024+ } )
1025+
1026+ it ( 'should accept include_asset_scan_status param on asset list query' , async function ( ) {
1027+ const response = await stack . asset ( ) . query ( { include_asset_scan_status : true } ) . find ( )
1028+
1029+ expect ( response ) . to . be . an ( 'object' )
1030+ expect ( response . items ) . to . be . an ( 'array' )
1031+ // pending | clean | quarantined when scanning is enabled; not_scanned otherwise.
1032+ if ( response . items . length > 0 && '_asset_scan_status' in response . items [ 0 ] ) {
1033+ expect ( response . items [ 0 ] . _asset_scan_status ) . to . be . a ( 'string' )
1034+ expect ( [ 'pending' , 'clean' , 'quarantined' , 'not_scanned' ] ) . to . include ( response . items [ 0 ] . _asset_scan_status )
1035+ }
1036+ } )
1037+
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 ( )
1041+
1042+ expect ( asset ) . to . be . an ( 'object' )
1043+ expect ( asset ) . to . not . have . property ( '_asset_scan_status' )
1044+ } )
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+ } )
1063+ } )
9841064} )
0 commit comments