1
1
import * as simple from "simple-mock" ;
2
2
import assert = require( "assert" ) ;
3
3
import { ExtensionContext , workspace } from "vscode" ;
4
- import * as GGShieldConfiguration from "../../../lib/ggshield-configuration" ;
5
4
import { getConfiguration } from "../../../lib/ggshield-configuration-utils" ;
6
5
7
6
suite ( "getConfiguration" , ( ) => {
8
7
let getConfigurationMock : simple . Stub < Function > ;
9
- let constructorMock : simple . Stub < Function > ;
10
- let context : Partial < ExtensionContext > ;
11
8
12
9
setup ( ( ) => {
13
10
// Mock workspace.getConfiguration
14
11
getConfigurationMock = simple . mock ( workspace , "getConfiguration" ) ;
15
-
16
- // Mock the GGShieldConfiguration constructor globally
17
- constructorMock = simple . mock (
18
- GGShieldConfiguration ,
19
- "GGShieldConfiguration"
20
- ) ;
21
- context = { } as ExtensionContext ;
22
12
} ) ;
23
13
24
14
teardown ( ( ) => {
@@ -42,25 +32,18 @@ suite("getConfiguration", () => {
42
32
}
43
33
} ,
44
34
} ) ;
45
- constructorMock . returnWith ( { } ) ;
46
-
47
- getConfiguration ( context as ExtensionContext ) ;
35
+ const configuration = getConfiguration ( { } as ExtensionContext ) ;
48
36
49
37
// Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called
50
38
assert (
51
39
getConfigurationMock . called ,
52
40
"getConfiguration should be called once"
53
41
) ;
54
- assert (
55
- constructorMock . called ,
56
- "GGShieldConfiguration constructor should be called once"
57
- ) ;
58
42
59
- // Check the arguments passed to GGShieldConfiguration constructor
60
- const ggshieldConfigurationArgs = constructorMock . lastCall . args ;
61
- assert . strictEqual ( ggshieldConfigurationArgs [ 0 ] , "path/to/ggshield" ) ;
62
- assert . strictEqual ( ggshieldConfigurationArgs [ 1 ] , "https://custom-url.com" ) ;
63
- assert . strictEqual ( ggshieldConfigurationArgs [ 2 ] , "test-api-key" ) ;
64
- assert . strictEqual ( ggshieldConfigurationArgs [ 3 ] , true ) ;
43
+ // Assert that the configuration has the expected values
44
+ assert . strictEqual ( configuration . ggshieldPath , "path/to/ggshield" ) ;
45
+ assert . strictEqual ( configuration . apiUrl , "https://custom-url.com" ) ;
46
+ assert . strictEqual ( configuration . apiKey , "test-api-key" ) ;
47
+ assert . strictEqual ( configuration . allowSelfSigned , true ) ;
65
48
} ) ;
66
49
} ) ;
0 commit comments