Skip to content

Commit afe6baa

Browse files
Amit Joshiclaude
andcommitted
Fix tests for updated HTTP error handling
Update test mocks to include required Response properties (status, url, clone, text) that createHttpResponseError needs. Also update test assertions to expect sendAPIFailureTelemetry instead of sendErrorTelemetry for HTTP errors, matching the new error handling flow. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0fff91b commit afe6baa

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/web/client/test/integration/remoteFetchProvider.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,18 @@ describe("remoteFetchProvider", () => {
550550
const portalFs = new PortalsFS();
551551
await WebExtensionContext.authenticateAndUpdateDataverseProperties();
552552

553+
const mockResponseBody = JSON.stringify({
554+
"@odata.count": 0,
555+
"@Microsoft.Dynamics.CRM.totalrecordcount": 0,
556+
"value": [],
557+
});
553558
const _mockFetch = stub(fetch, "default").resolves({
554559
ok: false,
555-
statusText: "statusText",
560+
status: 500,
561+
statusText: "Internal Server Error",
562+
url: "https://test.crm.dynamics.com/api/data/v9.2/webpages",
563+
clone: function() { return this; },
564+
text: () => Promise.resolve(mockResponseBody),
556565
json: () => {
557566
return new Promise((resolve) => {
558567
return resolve({
@@ -565,13 +574,18 @@ describe("remoteFetchProvider", () => {
565574
// eslint-disable-next-line @typescript-eslint/no-explicit-any
566575
} as any);
567576

577+
const sendAPIFailureTelemetry = stub(
578+
WebExtensionContext.telemetry,
579+
"sendAPIFailureTelemetry"
580+
);
581+
568582
//Action
569583
await fetchDataFromDataverseAndUpdateVFS(portalFs);
570584

571585
//Assert
572586
const sendErrorTelemetryCalls = sendErrorTelemetry.getCalls();
573587

574-
assert.callCount(sendErrorTelemetry, 5);
588+
assert.callCount(sendErrorTelemetry, 4);
575589
assert.calledWithMatch(sendErrorTelemetryCalls[0], webExtensionTelemetryEventNames.WEB_EXTENSION_POPULATE_WEBSITE_ID_TO_LANGUAGE_SYSTEM_ERROR,
576590
"populateWebsiteIdToLanguageMap",
577591
"Only absolute URLs are supported");
@@ -584,10 +598,8 @@ describe("remoteFetchProvider", () => {
584598
assert.calledWithMatch(sendErrorTelemetryCalls[3], webExtensionTelemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SYSTEM_ERROR,
585599
"populateSharedWorkspace",
586600
"Web extension populate shared workspace system error");
587-
assert.calledWithMatch(sendErrorTelemetryCalls[4],
588-
webExtensionTelemetryEventNames.WEB_EXTENSION_FETCH_DATAVERSE_AND_CREATE_FILES_SYSTEM_ERROR,
589-
"fetchFromDataverseAndCreateFiles",
590-
`{"ok":false,"statusText":"statusText"}`);
601+
// HTTP errors now go through sendAPIFailureTelemetry with status code
602+
assert.calledOnce(sendAPIFailureTelemetry);
591603
assert.calledOnce(_mockFetch);
592604
});
593605

src/web/client/test/integration/remoteSaveProvider.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,14 @@ describe("remoteSaveProvider", () => {
227227
it("saveData_shouldErrorOnDataverseSaveCall_whenFetchReturnsNotOKAndStatusCodeIs304AndIsWebFileV2IsFalse", async () => {
228228
//Act
229229
const fileUri: vscode.Uri = { fsPath: "testuri" } as vscode.Uri;
230+
const mockResponseBody = JSON.stringify({ error: "Unauthorized" });
230231
const _mockFetch = stub(fetch, "default").resolves({
231232
ok: false,
232233
statusText: "Unauthorized",
233234
status: 403,
235+
url: "https://orgedfe4d6c.crm10.dynamics.com",
236+
clone: function() { return this; },
237+
text: () => Promise.resolve(mockResponseBody),
234238
json: () => {
235239
return new Promise((resolve) => {
236240
return resolve({ value: "value" });
@@ -264,9 +268,9 @@ describe("remoteSaveProvider", () => {
264268
"pdf"
265269
);
266270

267-
const sendErrorTelemetry = stub(
271+
const sendAPIFailureTelemetry = stub(
268272
WebExtensionContext.telemetry,
269-
"sendErrorTelemetry"
273+
"sendAPIFailureTelemetry"
270274
);
271275

272276
const showErrorDialog = stub(errorHandler, "showErrorDialog");
@@ -297,12 +301,13 @@ describe("remoteSaveProvider", () => {
297301
assert.calledOnce(getColumnContent);
298302
assert.calledOnce(isWebFileV2);
299303
assert.calledOnce(vscodeParse);
300-
assert.calledOnce(sendErrorTelemetry);
304+
// HTTP errors now go through sendAPIFailureTelemetry with status code
305+
assert.calledOnce(sendAPIFailureTelemetry);
301306
assert.calledOnce(showErrorDialog);
302307
const showErrorDialogCalls = showErrorDialog.getCalls()[0];
303308
expect(
304309
showErrorDialogCalls.args[0],
305-
"Theres a problem on the back end"
310+
"There's a problem on the back end"
306311
);
307312
expect(showErrorDialogCalls.args[1], "Try again");
308313
}

0 commit comments

Comments
 (0)