Skip to content

Commit 68d4932

Browse files
committed
fix(test): apply suggestions
1 parent 6497074 commit 68d4932

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

src/lib/ggshield-configuration-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export function getConfiguration(
2424
ggshieldPath
2525
? ggshieldPath
2626
: getBinaryAbsolutePath(os.platform(), os.arch(), context),
27-
apiUrl ? apiUrl : apiUrlDefault,
28-
apiKey ? apiKey : "",
29-
allowSelfSigned ? allowSelfSigned : false
27+
apiUrl || apiUrlDefault,
28+
apiKey || "",
29+
allowSelfSigned || false
3030
);
3131
}
3232

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
import * as simple from "simple-mock";
22
import assert = require("assert");
33
import { ExtensionContext, workspace } from "vscode";
4-
import * as GGShieldConfiguration from "../../../lib/ggshield-configuration";
54
import { getConfiguration } from "../../../lib/ggshield-configuration-utils";
65

76
suite("getConfiguration", () => {
87
let getConfigurationMock: simple.Stub<Function>;
9-
let constructorMock: simple.Stub<Function>;
10-
let context: Partial<ExtensionContext>;
118

129
setup(() => {
1310
// Mock workspace.getConfiguration
1411
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;
2212
});
2313

2414
teardown(() => {
@@ -42,25 +32,18 @@ suite("getConfiguration", () => {
4232
}
4333
},
4434
});
45-
constructorMock.returnWith({});
46-
47-
getConfiguration(context as ExtensionContext);
35+
const configuration = getConfiguration({} as ExtensionContext);
4836

4937
// Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called
5038
assert(
5139
getConfigurationMock.called,
5240
"getConfiguration should be called once"
5341
);
54-
assert(
55-
constructorMock.called,
56-
"GGShieldConfiguration constructor should be called once"
57-
);
5842

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);
6548
});
6649
});

src/test/suite/lib/run-ggshield.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ suite("runGGShieldCommand", () => {
6161
apiKey: "",
6262
allowSelfSigned: allowSelfSigned,
6363
} as GGShieldConfiguration,
64-
[]
64+
["test"]
6565
);
6666

6767
assert(spawnSyncMock.called, "spawnSync should be called once");
6868

6969
const spawnSyncArgs = spawnSyncMock.lastCall.args;
7070
const args = spawnSyncArgs[1];
7171

72-
assert.strictEqual(args.includes("--allow-self-signed"), allowSelfSigned);
72+
assert.strictEqual(args[0] === "--allow-self-signed", allowSelfSigned);
7373
});
7474
});
7575
});

0 commit comments

Comments
 (0)