@@ -17,8 +17,6 @@ suite("runGGShieldCommand", () => {
17
17
18
18
test ( "Global env variables are set correctly" , async ( ) => {
19
19
process . env . TEST_GLOBAL_VAR = "GlobalValue" ;
20
-
21
- const spawnSyncSpy = simple . mock ( childProcess , "spawnSync" ) ;
22
20
runGGShield . runGGShieldCommand (
23
21
{
24
22
ggshieldPath : "path/to/ggshield" ,
@@ -29,14 +27,49 @@ suite("runGGShieldCommand", () => {
29
27
) ;
30
28
31
29
// Assert that spawnSync was called
32
- assert ( spawnSyncSpy . called , "spawnSync should be called once" ) ;
30
+ assert ( spawnSyncMock . called , "spawnSync should be called once" ) ;
33
31
34
32
// Check the arguments passed to spawnSync
35
- const spawnSyncArgs = spawnSyncSpy . lastCall . args ;
33
+ const spawnSyncArgs = spawnSyncMock . lastCall . args ;
36
34
const options = spawnSyncArgs [ 2 ] ;
37
35
assert . strictEqual ( options . env . TEST_GLOBAL_VAR , "GlobalValue" ) ;
38
36
39
- simple . restore ( ) ;
40
37
delete process . env . TEST_GLOBAL_VAR ;
41
38
} ) ;
39
+
40
+ const testCasesAllowSelfSigned = [
41
+ {
42
+ allowSelfSigned : true ,
43
+ description :
44
+ "GGshield is called with flag --allow-self-signed when allowSelfSigned is true" ,
45
+ } ,
46
+ {
47
+ allowSelfSigned : false ,
48
+ description :
49
+ "GGshield is not called with flag --allow-self-signed when allowSelfSigned is false" ,
50
+ } ,
51
+ ] ;
52
+
53
+ testCasesAllowSelfSigned . forEach ( ( { allowSelfSigned, description } ) => {
54
+ test ( description , async ( ) => {
55
+ process . env . TEST_GLOBAL_VAR = "GlobalValue" ;
56
+
57
+ runGGShield . runGGShieldCommand (
58
+ {
59
+ ggshieldPath : "path/to/ggshield" ,
60
+ apiUrl : "" ,
61
+ apiKey : "" ,
62
+ allowSelfSigned : allowSelfSigned ,
63
+ } as GGShieldConfiguration ,
64
+ [ ]
65
+ ) ;
66
+
67
+ assert ( spawnSyncMock . called , "spawnSync should be called once" ) ;
68
+
69
+ const spawnSyncArgs = spawnSyncMock . lastCall . args ;
70
+ const args = spawnSyncArgs [ 1 ] ;
71
+
72
+ assert . strictEqual ( args . includes ( "--allow-self-signed" ) , allowSelfSigned ) ;
73
+ } ) ;
74
+ } ) ;
42
75
} ) ;
0 commit comments