Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix web extension telemetry test cases #771

Merged
merged 8 commits into from
Nov 21, 2023
6 changes: 4 additions & 2 deletions src/web/client/telemetry/webExtensionTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export class WebExtensionTelemetry {
duration: number,
methodName: string,
eventName?: string,
entityFileExtensionType?: string
entityFileExtensionType?: string,
status?: string
) {
this.sendAPITelemetry(
URL,
Expand All @@ -135,7 +136,8 @@ export class WebExtensionTelemetry {
true,
duration,
undefined,
!isNullOrUndefined(eventName) ? eventName : telemetryEventNames.WEB_EXTENSION_API_REQUEST_SUCCESS);
!isNullOrUndefined(eventName) ? eventName : telemetryEventNames.WEB_EXTENSION_API_REQUEST_SUCCESS,
status);
}

public sendAPIFailureTelemetry(
Expand Down
39 changes: 23 additions & 16 deletions src/web/client/test/integration/errorHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_PATH_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_PATH_PARAMETERS_MISSING,
checkMandatoryPathParameters.name,
`entity:, entityId:512e50bd-a9d1-44c0-ba3f-5dc7f46e7216`,

);
});

Expand All @@ -386,8 +388,9 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_PATH_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_PATH_PARAMETERS_MISSING,
checkMandatoryPathParameters.name,
`entity:entity, entityId:`
);
});

Expand Down Expand Up @@ -425,7 +428,7 @@ describe("errorHandler", () => {
expect(result).true;
});

it("checkMandatoryQueryParameters_whenORGURLIsBlank_shouldReturnFalse", () => {
it("checkMandatoryQueryParameters_whenOrgUrlIsBlank_shouldReturnFalse", () => {
//Act
const _mockShowErrorMessage = spy(vscode.window, "showErrorMessage");
const _mockSendErrorTelemetry = spy(
Expand Down Expand Up @@ -459,12 +462,13 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING,
checkMandatoryQueryParameters.name,
`orgURL:, dataSource:SQL, schemaName:1.0.0.0 ,websiteId:ed9a6c19-5ab6-4f67-8c35-2423cff958c4`
);
});

it("checkMandatoryQueryParameters_whenDATASOURCEIsBlank_shouldReturnFalse", () => {
it("checkMandatoryQueryParameters_whenDataSourceIsBlank_shouldReturnFalse", () => {
//Act
const _mockShowErrorMessage = spy(vscode.window, "showErrorMessage");
const _mockSendErrorTelemetry = spy(
Expand Down Expand Up @@ -497,12 +501,13 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING,
checkMandatoryQueryParameters.name,
`orgURL:ORG_URL, dataSource:, schemaName:1.0.0.0 ,websiteId:ed9a6c19-5ab6-4f67-8c35-2423cff958c4`
);
});

it("checkMandatoryQueryParameters_whenSCHEMAVERSIONIsBlank_shouldReturnFalse", () => {
it("checkMandatoryQueryParameters_whenSchemaVersionIsBlank_shouldReturnFalse", () => {
//Act
const _mockShowErrorMessage = spy(vscode.window, "showErrorMessage");
const _mockSendErrorTelemetry = spy(
Expand Down Expand Up @@ -535,12 +540,13 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING,
checkMandatoryQueryParameters.name,
`orgURL:ORG_URL, dataSource:SQL, schemaName: ,websiteId:ed9a6c19-5ab6-4f67-8c35-2423cff958c4`
);
});

it("checkMandatoryQueryParameters_whenWEBSITEIDIsBlank_shouldReturnFalse", () => {
it("checkMandatoryQueryParameters_whenWebsiteIdIsBlank_shouldReturnFalse", () => {
//Act
const _mockShowErrorMessage = spy(vscode.window, "showErrorMessage");
const _mockSendErrorTelemetry = spy(
Expand Down Expand Up @@ -570,8 +576,9 @@ describe("errorHandler", () => {
);
assert.calledOnceWithExactly(
_mockSendErrorTelemetry,
'triggeredMethod',
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING
telemetryEventNames.WEB_EXTENSION_MANDATORY_QUERY_PARAMETERS_MISSING,
checkMandatoryQueryParameters.name,
`orgURL:ORG_URL, dataSource:SQL, schemaName:1.0.0.0 ,websiteId:`
);
});

Expand Down
56 changes: 42 additions & 14 deletions src/web/client/test/integration/webExtensionTelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ describe("webExtensionTelemetry", () => {
],
[queryParameters.REFERRER, "yes"],
[queryParameters.SITE_VISIBILITY, "false"],
[queryParameters.REGION, "NAM"],
[queryParameters.GEO, "US"],
[queryParameters.ENV_ID, "c4dc3686-1e6b-e428-b886-16cd0b9f4918"]
]);

const sendTelemetryEvent = stub(telemetry, "sendTelemetryEvent");
Expand All @@ -112,6 +115,9 @@ describe("webExtensionTelemetry", () => {
),
referrer: queryParamsMap.get(queryParameters.REFERRER),
siteVisibility: queryParamsMap.get(queryParameters.SITE_VISIBILITY),
region: queryParamsMap.get(queryParameters.REGION),
geo: queryParamsMap.get(queryParameters.GEO),
envId: queryParamsMap.get(queryParameters.ENV_ID),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

Expand Down Expand Up @@ -145,6 +151,9 @@ describe("webExtensionTelemetry", () => {
),
referrer: queryParamsMap.get(queryParameters.REFERRER),
siteVisibility: queryParamsMap.get(queryParameters.SITE_VISIBILITY),
region: queryParamsMap.get(queryParameters.REGION),
geo: queryParamsMap.get(queryParameters.GEO),
envId: queryParamsMap.get(queryParameters.ENV_ID),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

Expand Down Expand Up @@ -177,7 +186,7 @@ describe("webExtensionTelemetry", () => {
};

//Act
webExtensionTelemetry.sendErrorTelemetry(eventName, errorMessage);
webExtensionTelemetry.sendErrorTelemetry(eventName, methodName, errorMessage);

//Assert
const error: Error = new Error(errorMessage);
Expand All @@ -204,7 +213,7 @@ describe("webExtensionTelemetry", () => {
methodName: methodName
};
//Act
webExtensionTelemetry.sendErrorTelemetry(eventName,methodName);
webExtensionTelemetry.sendErrorTelemetry(eventName, methodName);
//Assert

assert.calledOnce(sendTelemetryException);
Expand Down Expand Up @@ -246,7 +255,7 @@ describe("webExtensionTelemetry", () => {
assert.calledOnceWithExactly(sendTelemetryEvent, eventName, properties);
});

it("sendAPITelemetry_whenErrorMessageIsPassed_shouldCallsendTelemetryException", () => {
it("sendAPITelemetry_whenErrorMessageIsPassed_shouldCallSendTelemetryException", () => {
//Act
const URL = "powerPages.com";
const entity = "webPages";
Expand All @@ -267,8 +276,10 @@ describe("webExtensionTelemetry", () => {
entity: entity,
httpMethod: httpMethod,
entityFileExtensionType: entityFileExtensionType,
eventName: "update",
methodName: "sendAPITelemetry_whenErrorMessageIsPassed_shouldCallSendTelemetryException",
isSuccessful: "true",
status: "200",
eventName: eventName
};

//Action
Expand All @@ -277,12 +288,13 @@ describe("webExtensionTelemetry", () => {
URL,
entity,
httpMethod,
"sendAPITelemetry_whenErrorMessageIsPassed_shouldCallsendTelemetryException",
"sendAPITelemetry_whenErrorMessageIsPassed_shouldCallSendTelemetryException",
entityFileExtensionType, // TODO: Pass these as function properties parameters
isSuccessful,
duration,
errorMessage,
eventName
eventName,
"200"
);

const measurements = {
Expand All @@ -300,7 +312,7 @@ describe("webExtensionTelemetry", () => {
expect(sendTelemetryExceptionCalls.args[2]).deep.eq(measurements);
});

it("sendAPITelemetry_whenErrorMessageNotPassed_shouldCallsendTelemetryException", () => {
it("sendAPITelemetry_whenErrorMessageNotPassed_shouldCallSendTelemetryException", () => {
//Act
const URL = "powerPages.com";
const entity = "webPages";
Expand All @@ -319,6 +331,8 @@ describe("webExtensionTelemetry", () => {
httpMethod: httpMethod,
entityFileExtensionType: entityFileExtensionType,
isSuccessful: "true",
status: "200",
methodName: "sendAPITelemetry_whenErrorMessageNotPassed_shouldCallSendTelemetryException"
};

//Action
Expand All @@ -327,12 +341,13 @@ describe("webExtensionTelemetry", () => {
URL,
entity,
httpMethod,
"sendAPITelemetry_whenErrorMessageNotPassed_shouldCallsendTelemetryException",
"sendAPITelemetry_whenErrorMessageNotPassed_shouldCallSendTelemetryException",
entityFileExtensionType, // TODO: Pass these as function properties parameters
isSuccessful,
duration,
errorMessage,
eventName
eventName,
"200"
);

const measurements = {
Expand Down Expand Up @@ -366,6 +381,8 @@ describe("webExtensionTelemetry", () => {
httpMethod: httpMethod,
entityFileExtensionType: entityFileExtensionType,
isSuccessful: "",
status: "200",
methodName: "sendAPITelemetry_whenIsSuccessfulAndDurationIsUndefined_shouldSetDurationInMillisAs0orIsSuccessfulAsBlankString"
};

//Action
Expand All @@ -379,7 +396,8 @@ describe("webExtensionTelemetry", () => {
isSuccessful,
duration,
errorMessage,
eventName
eventName,
"200"
);

const measurements = {
Expand Down Expand Up @@ -413,6 +431,8 @@ describe("webExtensionTelemetry", () => {
httpMethod: httpMethod,
entityFileExtensionType: entityFileExtensionType,
isSuccessful: "false",
status: "200",
methodName: "sendAPITelemetry_whenIsSuccessfulIsFalse_shouldSetIsSuccessfulAsFalse"
};

//Action
Expand All @@ -425,7 +445,8 @@ describe("webExtensionTelemetry", () => {
isSuccessful,
duration,
errorMessage,
eventName
eventName,
"200"
);

const measurements = {
Expand Down Expand Up @@ -454,19 +475,23 @@ describe("webExtensionTelemetry", () => {
httpMethod: httpMethod,
entityFileExtensionType: entityFileExtensionType,
isSuccessful: "true",
methodName: "sendAPISuccessTelemetry_whenCall_shouldCallSendAPITelemetryWithoutErrorMessage",
status: "200"
};

const measurements = {
durationInMillis: duration,
};

//Action
webExtensionTelemetry.sendAPISuccessTelemetry(
URL,
entity,
httpMethod,
duration,
entityFileExtensionType
"sendAPISuccessTelemetry_whenCall_shouldCallSendAPITelemetryWithoutErrorMessage",
"WebExtensionApiRequestSuccess",
entityFileExtensionType,
"200"
);

//Assert
Expand Down Expand Up @@ -497,6 +522,8 @@ describe("webExtensionTelemetry", () => {
entityFileExtensionType: entityFileExtensionType,
eventName: telemetryEventNames.WEB_EXTENSION_API_REQUEST_FAILURE,
isSuccessful: "false",
status: "200",
methodName: "sendAPIFailureTelemetry_withErrorMessage_shouldCallSendTelemetryException"
};

const measurements = {
Expand All @@ -511,7 +538,8 @@ describe("webExtensionTelemetry", () => {
duration,
"sendAPIFailureTelemetry_withErrorMessage_shouldCallSendTelemetryException",
errorMessage,
entityFileExtensionType
entityFileExtensionType,
"200"
);

//Assert
Expand Down
2 changes: 1 addition & 1 deletion src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function getSanitizedFileName(fileName: string): string {

// Get the file's extension
export function getFileExtension(fileName: string): string | undefined {
return fileName.split('.').pop();
return fileName.toString().split('.').pop();
}

export function getFileExtensionForPreload() {
Expand Down
Loading