Skip to content

Commit 51d041c

Browse files
committed
fixup! fix(tests): Update tests for ggshieldAuthStatus
1 parent da467b8 commit 51d041c

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/lib/ggshield-api.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,18 @@ export async function ggshieldAuthStatus(
234234
configuration: GGShieldConfiguration,
235235
context: ExtensionContext
236236
): Promise<void> {
237-
let isAuthenticated;
237+
let isAuthenticated: boolean;
238238
const proc = runGGShieldCommand(configuration, ["api-status", "--json"]);
239239
if (proc.status === 0 && JSON.parse(proc.stdout).status_code === 200) {
240-
console.log(proc.stdout, JSON.parse(proc.stdout).status_code === 200);
241240
isAuthenticated = true;
242241
}
243242
else{
244243
if (proc.stderr && proc.stderr.includes("Config key")){
245244
window.showErrorMessage(`Gitguardian: ${proc.stderr}`);
246-
247245
}
248246
console.log(proc.stderr);
249247
isAuthenticated = false;
250248
}
251-
252249
commands.executeCommand('setContext', 'isAuthenticated', isAuthenticated);
253250
await context.globalState.update('isAuthenticated', isAuthenticated);
254251
}

src/test/suite/extension.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as assert from "assert";
22
import { extensions, commands,} from "vscode";
33

4-
suite("Extension Functionality Tests", () => {
4+
suite("activate", () => {
55

6-
test("Extension activates successfully", async () => {
6+
test("Should activate extension successfully", async () => {
77
const ext = extensions.getExtension("gitguardian-secret-security.gitguardian");
88
await ext?.activate();
99
assert.ok(ext?.isActive, "Extension should be active");
1010
});
1111

12-
test("Commands are registered", async () => {
12+
test("Should register all gitguardian commands", async () => {
1313
const commandIds = [
1414
"gitguardian.quota",
1515
"gitguardian.ignore",

src/test/suite/ggshield-api.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ suite('ggshieldAuthStatus', function () {
99
let isAuthenticated: boolean;
1010
let mockGlobalState: Memento & { setKeysForSync(keys: readonly string[]): void; };
1111
let mockContext: Partial<ExtensionContext>;
12+
let runGGShieldMock: simple.Stub<Function>;
1213

1314
setup(function () {
1415
isAuthenticated = false;
@@ -28,15 +29,16 @@ suite('ggshieldAuthStatus', function () {
2829
mockContext = {
2930
globalState: mockGlobalState,
3031
};
32+
runGGShieldMock = simple.mock(runGGShield, "runGGShieldCommand");
3133
});
3234
teardown(function () {
3335
simple.restore();
3436
});
3537

3638
test('Valid authentication should update isAuthenticated to true', async function () {
37-
simple.mock(runGGShield, "runGGShieldCommand").returnWith({
39+
runGGShieldMock.returnWith({
3840
status: 0,
39-
stdout: '{"detail": "Valid API key.", "status_code": 200, "app_version": "v2.111.0", "secrets_engine_version": "2.124.1"}',
41+
stdout: '{"detail": "Valid API key.", "status_code": 200}',
4042
stderr: ''
4143
});
4244

@@ -45,9 +47,9 @@ suite('ggshieldAuthStatus', function () {
4547
});
4648

4749
test('Invalid authentication should keep isAuthenticated to false', async function () {
48-
simple.mock(runGGShield, "runGGShieldCommand").returnWith({
50+
runGGShieldMock.returnWith({
4951
status: 0,
50-
stdout: '{"detail": "Invalid API key.", "status_code": 401, "app_version": "v2.111.0", "secrets_engine_version": "2.124.1"}',
52+
stdout: '{"detail": "Invalid API key.", "status_code": 401}',
5153
stderr: ''
5254
});
5355

src/test/suite/results-parser.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ const results = `{
4242
"secrets_engine_version":"2.96.0"
4343
}`;
4444

45-
suite("Result Parser Suite", () => {
46-
window.showInformationMessage("Start all tests.");
47-
48-
test("test result parser", () => {
45+
suite("parseGGShieldResults", () => {
46+
test("Should parse ggshield scan output", () => {
4947
const diagnostics = parseGGShieldResults(JSON.parse(results));
5048
assert.strictEqual(diagnostics.length, 1);
5149
const diagnostic = diagnostics[0];
@@ -58,7 +56,7 @@ suite("Result Parser Suite", () => {
5856
assert.strictEqual(diagnostic.severity, DiagnosticSeverity.Warning);
5957
});
6058

61-
test("test result parser with invalid json", () => {
59+
test("Should return an empty array on an invalid ggshield output", () => {
6260
const diagnostics = parseGGShieldResults(JSON.parse("{}"));
6361

6462
assert.strictEqual(diagnostics.length, 0);

0 commit comments

Comments
 (0)