@@ -9,35 +9,45 @@ const cxWrapperFactory = new CxWrapperFactory();
99describe ( "Triage cases" , ( ) => {
1010 const cxScanConfig = new BaseTest ( ) ;
1111
12- it ( 'Triage Successful case' , async ( ) => {
13- const auth = await cxWrapperFactory . createWrapper ( cxScanConfig ) ;
14-
12+ const getScanAndResult = async ( auth : any ) : Promise < { scan : any , result : CxResult } > => {
1513 const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed,limit=100" ) ;
16- let result : CxResult ;
17- let scan , output ;
18- while ( ! output && scanList && scanList . payload && scanList . payload . length > 0 ) {
19- scan = scanList . payload . pop ( )
20- console . log ( "Triage Successful case - ScanId " + scan . id )
21- output = await auth . getResultsList ( scan . id )
22- if ( output . status == "Error in the json file." ) {
14+ let scan , output , result ;
15+
16+ while ( ! output && scanList ?. payload ?. length > 0 ) {
17+ scan = scanList . payload . pop ( ) ;
18+ output = await auth . getResultsList ( scan . id ) ;
19+ if ( output ?. status === "Error in the json file." ) {
2320 output = undefined ;
2421 } else {
25- result = output . payload . find ( res => res . type == CxConstants . SAST )
26- if ( ! result || ! result . similarityId ) {
22+ result = output ? .payload ? .find ( ( res : CxResult ) => res . type === CxConstants . SAST ) ;
23+ if ( ! result ? .similarityId ) {
2724 output = undefined ;
2825 }
2926 }
3027 }
3128
32- const cxShow : CxCommandOutput = await auth . triageShow ( scan . projectID , result . similarityId , result . type ) ;
29+ if ( ! scan ) {
30+ const scanShow = await auth . scanShow ( "d4354650-4ee1-4e10-9b1d-0feaf6c187a7" ) ;
31+ scan = scanShow ?. payload ?. pop ( ) ;
32+ output = await auth . getResultsList ( scan . id ) ;
33+ result = output ?. payload ?. find ( ( res : CxResult ) => res . type === CxConstants . SAST ) ;
34+ }
3335
34- expect ( cxShow . exitCode ) . toEqual ( 0 ) ;
36+ return { scan, result } ;
37+ } ;
38+
39+ it ( 'Triage Successful case' , async ( ) => {
40+ const auth = await cxWrapperFactory . createWrapper ( cxScanConfig ) ;
41+ const { scan, result } = await getScanAndResult ( auth ) ;
3542
36- const cxUpdate : CxCommandOutput = await
37- auth . triageUpdate ( scan . projectID , result . similarityId , result . type , result . state ,
38- "Edited via JavascriptWrapper" ,
39- result . severity . toLowerCase ( ) == "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH ) ;
43+ const cxShow : CxCommandOutput = await auth . triageShow ( scan . projectID , result . similarityId , result . type ) ;
44+ expect ( cxShow . exitCode ) . toEqual ( 0 ) ;
4045
46+ const cxUpdate : CxCommandOutput = await auth . triageUpdate (
47+ scan . projectID , result . similarityId , result . type , result . state ,
48+ "Edited via JavascriptWrapper" ,
49+ result . severity . toLowerCase ( ) === "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH
50+ ) ;
4151 expect ( cxUpdate . exitCode ) . toEqual ( 0 ) ;
4252 } ) ;
4353} ) ;
0 commit comments