Skip to content

Commit 065a8a8

Browse files
committed
Refactor telemetryAIEvent parameters and add tests for telemetry functionality
1 parent 46f11dd commit 065a8a8

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export enum CxConstants {
116116
SUB_CMD_TELEMETRY_AI = "ai",
117117
AI_PROVIDER = "--ai-provider",
118118
TIMESTAMP = "--timestamp",
119-
CLICK_TYPE = "--click-type",
119+
TYPE = "--type",
120+
SUB_TYPE = "--sub-type",
120121
PROBLEM_SEVERITY = "--problem-severity"
121122
}

src/main/wrapper/CxWrapper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,15 @@ export class CxWrapper {
448448
return new ExecutionService().executeCommands(this.config.pathToExecutable, commands, CxConstants.MASK_TYPE);
449449
}
450450

451-
telemetryAIEvent(aiProvider: string, agent: string, timestamp: Date, clickType: string, engine: string, problemSeverity: string): Promise<CxCommandOutput> {
451+
telemetryAIEvent(aiProvider: string, agent: string, timestamp: Date, eventType: string, subType: string, engine: string, problemSeverity: string): Promise<CxCommandOutput> {
452452
const commands: string[] = [
453453
CxConstants.TELEMETRY,
454454
CxConstants.SUB_CMD_TELEMETRY_AI,
455455
CxConstants.AI_PROVIDER, aiProvider,
456456
CxConstants.AGENT, agent,
457-
CxConstants.TIMESTAMP, timestamp.toISOString(),
458-
CxConstants.CLICK_TYPE, clickType,
457+
CxConstants.TIMESTAMP, timestamp?.toISOString(),
458+
CxConstants.TYPE, eventType,
459+
CxConstants.SUB_TYPE, subType,
459460
CxConstants.ENGINE, engine,
460461
CxConstants.PROBLEM_SEVERITY, problemSeverity
461462
];

src/tests/TelemetryTest.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { CxWrapper } from '../main/wrapper/CxWrapper';
2+
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
3+
import { BaseTest } from "./BaseTest";
4+
5+
describe("Telemetry cases", () => {
6+
const cxScanConfig = new BaseTest();
7+
8+
it('TelemetryAIEvent Successful case with minimal parameters', async () => {
9+
const wrapper = new CxWrapper(cxScanConfig);
10+
const timestamp = new Date();
11+
const cxCommandOutput: CxCommandOutput = await wrapper.telemetryAIEvent(
12+
"Cursor",
13+
"Cursos",
14+
timestamp,
15+
"click",
16+
"ast-results.viewPackageDetails",
17+
"secrets",
18+
"high"
19+
);
20+
console.log("Json object from telemetryAIEvent successful case: " + JSON.stringify(cxCommandOutput));
21+
expect(cxCommandOutput.exitCode).toBe(0);
22+
});
23+
24+
it('TelemetryAIEvent Successful case with past timestamp', async () => {
25+
const wrapper = new CxWrapper(cxScanConfig);
26+
const pastTimestamp = new Date(Date.now() - 3600000); // 1 hour ago
27+
const cxCommandOutput: CxCommandOutput = await wrapper.telemetryAIEvent(
28+
"openai",
29+
"vscode",
30+
pastTimestamp,
31+
"click",
32+
"ast-results.viewPackageDetails",
33+
"oss",
34+
"high"
35+
);
36+
console.log("Json object from telemetryAIEvent with past timestamp: " + JSON.stringify(cxCommandOutput));
37+
expect(cxCommandOutput.exitCode).toBe(0);
38+
});
39+
40+
it('TelemetryAIEvent Successful case with edge case parameters', async () => {
41+
const wrapper = new CxWrapper(cxScanConfig);
42+
const timestamp = new Date();
43+
const cxCommandOutput: CxCommandOutput = await wrapper.telemetryAIEvent(
44+
"",
45+
"",
46+
timestamp,
47+
"",
48+
"",
49+
"",
50+
""
51+
);
52+
console.log("Json object from telemetryAIEvent with empty parameters: " + JSON.stringify(cxCommandOutput));
53+
expect(typeof cxCommandOutput.exitCode).toBe(0);
54+
});
55+
56+
it('TelemetryAIEvent Successful case without timestamp', async () => {
57+
const wrapper = new CxWrapper(cxScanConfig);
58+
const cxCommandOutput: CxCommandOutput = await wrapper.telemetryAIEvent(
59+
"Copilot",
60+
"VS Code",
61+
undefined,
62+
"click",
63+
"ast-results.viewPackageDetails",
64+
"oss",
65+
"medium"
66+
);
67+
console.log("Json object from telemetryAIEvent without timestamp: " + JSON.stringify(cxCommandOutput));
68+
expect(typeof cxCommandOutput.exitCode).toBe(0);
69+
});
70+
});

0 commit comments

Comments
 (0)