From 131a4b59ae5ca699a7798c22012e04d709845ca9 Mon Sep 17 00:00:00 2001 From: Trae Yelovich Date: Thu, 14 Nov 2024 11:11:24 -0500 Subject: [PATCH] fix formatting of error msg and update test Signed-off-by: Trae Yelovich --- .../__unit__/utils/AuthUtils.unit.test.ts | 17 ++++++++++++++--- packages/zowe-explorer/src/utils/AuthUtils.ts | 9 ++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/utils/AuthUtils.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/utils/AuthUtils.unit.test.ts index d285bc03d7..ecbdb4bb45 100644 --- a/packages/zowe-explorer/__tests__/__unit__/utils/AuthUtils.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/utils/AuthUtils.unit.test.ts @@ -9,7 +9,7 @@ * */ -import { Gui, imperative } from "@zowe/zowe-explorer-api"; +import { ErrorCorrelator, Gui, imperative, ZoweExplorerApiType } from "@zowe/zowe-explorer-api"; import { AuthUtils } from "../../../src/utils/AuthUtils"; import { Constants } from "../../../src/configuration/Constants"; import { MockedProperty } from "../../__mocks__/mockUtils"; @@ -21,12 +21,23 @@ describe("AuthUtils", () => { errorCode: 401 as unknown as string, msg: "All configured authentication methods failed", }); - const profile = { type: "zosmf" } as any; + const profile = { name: "aProfile", type: "zosmf" } as any; + const correlateErrorMock = jest.spyOn(ErrorCorrelator.getInstance(), "correlateError"); + const correlatedError = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, errorDetails, { + templateArgs: { + profileName: profile.name, + }, + }); const promptForAuthenticationMock = jest .spyOn(AuthUtils, "promptForAuthentication") .mockImplementation(async () => Promise.resolve(true)); AuthUtils.promptForAuthError(errorDetails, profile); - expect(promptForAuthenticationMock).toHaveBeenCalledWith(errorDetails, profile); + expect(correlateErrorMock).toHaveBeenCalledWith(ZoweExplorerApiType.All, errorDetails, { + templateArgs: { + profileName: profile.name, + }, + }); + expect(promptForAuthenticationMock).toHaveBeenCalledWith(errorDetails, profile, correlatedError); }); }); describe("promptForSsoLogin", () => { diff --git a/packages/zowe-explorer/src/utils/AuthUtils.ts b/packages/zowe-explorer/src/utils/AuthUtils.ts index 23689ebd6a..523f574697 100644 --- a/packages/zowe-explorer/src/utils/AuthUtils.ts +++ b/packages/zowe-explorer/src/utils/AuthUtils.ts @@ -62,7 +62,14 @@ export class AuthUtils { (Number(err.errorCode) === imperative.RestConstants.HTTP_STATUS_401 || err.message.includes("All configured authentication methods failed")) ) { - void AuthUtils.promptForAuthentication(err, profile).catch((error) => error instanceof Error && ZoweLogger.error(error.message)); + const correlation = ErrorCorrelator.getInstance().correlateError(ZoweExplorerApiType.All, err, { + templateArgs: { + profileName: profile.name + } + }); + void AuthUtils.promptForAuthentication(err, profile, correlation).catch( + (error) => error instanceof Error && ZoweLogger.error(error.message) + ); } }