11import { CxWrapper } from '../main/wrapper/CxWrapper' ;
22import { CxCommandOutput } from "../main/wrapper/CxCommandOutput" ;
3- import { BaseTest } from "./BaseTest" ;
43import CxChat from "../main/chat/CxChat" ;
4+ import { anything , instance , mock , when } from 'ts-mockito' ;
5+ import { BaseTest } from "./BaseTest" ;
6+
7+ function createOutput ( exitCode :number , payload :CxChat ) :CxCommandOutput {
8+ const output = new CxCommandOutput ( ) ;
9+ output . exitCode = exitCode ;
10+ output . status = "" ;
11+ output . payload = [ payload ] ;
12+ return output ;
13+ }
14+
15+ describe ( "Gpt Chat Cases" , ( ) => {
16+ // tests preparation
17+ const cxScanConfig = new BaseTest ( ) ;
18+ const mockedWrapper : CxWrapper = mock ( CxWrapper ) ;
19+ const originalWrapper : CxWrapper = new CxWrapper ( cxScanConfig ) ;
20+ const outputSuccessful = createOutput ( 0 , new CxChat ( "CONVERSATION" , [ "RESPONSE" ] ) ) ;
521
6- describe ( "Chat" , ( ) => {
7- it ( 'Try call' , async ( ) => {
8- const config = new BaseTest ( ) ;
9- config . pathToExecutable = "path\\to\\cli\\dev\\build"
10- const wrapper = new CxWrapper ( config ) ;
11- let cxCommandOutput : CxCommandOutput = await wrapper . chat (
12- "apikey" ,
13- "path\\to\\result\\file" ,
14- 3 ,
15- "MEDIUM" ,
16- "Security Opt Not Set" ,
17- "Explain the result" ,
18- null ,
19- "gpt-3.5-turbo"
22+ when ( mockedWrapper . chat ( "APIKEY" , "FILE" , anything ( ) , anything ( ) , anything ( ) , anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve (
23+ outputSuccessful
24+ ) ;
25+ const wrapper : CxWrapper = instance ( mockedWrapper ) ;
26+
27+ it ( 'Gpt Chat Successful case' , async ( ) => {
28+ const cxCommandOutput = await wrapper . chat (
29+ "APIKEY" ,
30+ "FILE" ,
31+ 0 ,
32+ "SEVERITY" ,
33+ "VULNERABILITY" ,
34+ "INPUT" ,
35+ "CONVERSATION" ,
36+ "MODEL"
2037 ) ;
2138 expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
22- const output : CxChat = cxCommandOutput . payload . pop ( ) ;
23- cxCommandOutput = await wrapper . chat (
24- "apikey" ,
25- "path\\to\\result\\file" ,
26- 3 ,
27- "MEDIUM" ,
28- "Security Opt Not Set" ,
29- "Can you provide a snippet with the fix?" ,
30- output . conversationId ,
31- "gpt-3.5-turbo"
39+ } ) ;
40+
41+ it ( 'Gpt Chat Failed case' , async ( ) => {
42+ const cxCommandOutput = await originalWrapper . chat (
43+ "APIKEY" ,
44+ "" ,
45+ 0 ,
46+ "SEVERITY" ,
47+ "VULNERABILITY" ,
48+ "INPUT" ,
49+ "CONVERSATION" ,
50+ "MODEL"
3251 ) ;
33- expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
52+ expect ( cxCommandOutput . exitCode ) . toBe ( 1 ) ;
53+ expect ( cxCommandOutput . status ) . toBe ( "open : no such file or directory\n" ) ;
3454 } ) ;
3555} ) ;
0 commit comments