@@ -6,36 +6,83 @@ import {CxConstants} from '../main/wrapper/CxConstants';
66
77describe ( "Triage cases" , ( ) => {
88 const cxScanConfig = new BaseTest ( ) ;
9-
10- it ( 'Triage Successful case' , async ( ) => {
11- const auth = new CxWrapper ( cxScanConfig ) ;
12-
9+ const auth = new CxWrapper ( cxScanConfig ) ;
10+ const getScanAndResult = async ( ) : Promise < { scan : any , result : CxResult } > => {
1311 const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed,limit=100" ) ;
14- let result : CxResult ;
15- let scan , output ;
16- while ( ! output && scanList && scanList . payload && scanList . payload . length > 0 ) {
17- scan = scanList . payload . pop ( )
18- console . log ( "Triage Successful case - ScanId " + scan . id )
19- output = await auth . getResultsList ( scan . id )
20- if ( output . status == "Error in the json file." ) {
12+ let scan , output , result ;
13+ while ( ! output && scanList ?. payload ?. length > 0 ) {
14+ scan = scanList . payload . pop ( ) ;
15+ console . log ( "Triage case - ScanId " + scan . id ) ;
16+ output = await auth . getResultsList ( scan . id ) ;
17+ if ( output . status === "Error in the json file." ) {
2118 output = undefined ;
2219 } else {
23- result = output . payload . find ( res => res . type == CxConstants . SAST )
24- if ( ! result || ! result . similarityId ) {
20+ result = output . payload . find ( res => res . type === CxConstants . SAST ) ;
21+ if ( ! result ? .similarityId ) {
2522 output = undefined ;
2623 }
2724 }
2825 }
26+ return { scan, result } ;
27+ } ;
2928
29+ const handleTriageShow = async ( scan : any , result : CxResult ) => {
3030 const cxShow : CxCommandOutput = await auth . triageShow ( scan . projectID , result . similarityId , result . type ) ;
31-
3231 expect ( cxShow . exitCode ) . toEqual ( 0 ) ;
32+ }
3333
34- const cxUpdate : CxCommandOutput = await
35- auth . triageUpdate ( scan . projectID , result . similarityId , result . type , result . state ,
36- "Edited via JavascriptWrapper" ,
37- result . severity . toLowerCase ( ) == "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH ) ;
38-
34+ const handleTriageUpdate = async ( scan : any , result : CxResult , newState : string , newSeverity : string , newStateId = "" ) => {
35+ const cxUpdate : CxCommandOutput = await auth . triageUpdate (
36+ scan . projectID , result . similarityId , result . type , newState ,
37+ "Edited via JavascriptWrapper" ,
38+ newSeverity , newStateId
39+ ) ;
3940 expect ( cxUpdate . exitCode ) . toEqual ( 0 ) ;
41+ } ;
42+
43+ it ( 'Triage Successful case' , async ( ) => {
44+ const { scan, result } = await getScanAndResult ( ) ;
45+ await handleTriageShow ( scan , result ) ;
46+ await handleTriageUpdate ( scan , result , result . state , result . severity . toLowerCase ( ) === "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH ) ;
47+ } ) ;
48+
49+ it ( 'Triage with custom state Successful case' , async ( ) => {
50+ const { scan, result } = await getScanAndResult ( ) ;
51+
52+ const cxCommandOutput : CxCommandOutput = await auth . triageGetStates ( ) ;
53+ console . log ( "Json object from states successful case: " + JSON . stringify ( cxCommandOutput ) ) ;
54+ expect ( cxCommandOutput . payload . length ) . toBeGreaterThan ( 1 ) ;
55+ expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
56+
57+ let customState = cxCommandOutput . payload [ 0 ] . name
58+
59+ if ( result . state == customState ) {
60+ if ( cxCommandOutput . payload . length > 1 ) {
61+ customState = cxCommandOutput . payload [ 1 ] . name
62+ } else {
63+ await handleTriageUpdate ( scan , result , CxConstants . STATE_CONFIRMED , CxConstants . SEVERITY_MEDIUM ) ;
64+ }
65+ }
66+ await handleTriageUpdate ( scan , result , customState , CxConstants . SEVERITY_MEDIUM ) ;
67+
68+ } ) ; it ( 'Triage with custom state id Successful case' , async ( ) => {
69+ const { scan, result } = await getScanAndResult ( ) ;
70+
71+ const cxCommandOutput : CxCommandOutput = await auth . triageGetStates ( ) ;
72+ console . log ( "Json object from states successful case: " + JSON . stringify ( cxCommandOutput ) ) ;
73+ expect ( cxCommandOutput . payload . length ) . toBeGreaterThan ( 1 ) ;
74+ expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
75+ const allStates = cxCommandOutput . payload ;
76+ let customStateId = allStates [ 0 ] . id
77+ const customStateName = allStates [ 0 ] . name
78+
79+ if ( result . state == customStateName ) {
80+ if ( allStates . length > 1 ) {
81+ customStateId = allStates [ 1 ] . id
82+ } else {
83+ await handleTriageUpdate ( scan , result , CxConstants . STATE_CONFIRMED , CxConstants . SEVERITY_MEDIUM ) ;
84+ }
85+ }
86+ await handleTriageUpdate ( scan , result , "" , CxConstants . SEVERITY_MEDIUM , customStateId . toString ( ) ) ;
4087 } ) ;
4188} ) ;
0 commit comments