Skip to content

Commit f7599da

Browse files
- Update tests.
1 parent 4b3f903 commit f7599da

24 files changed

Lines changed: 129 additions & 190 deletions

lib/msal-browser/src/error/BrowserAuthError.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { AuthError } from "@azure/msal-common/browser";
77
import * as BrowserAuthErrorCodes from "./BrowserAuthErrorCodes.js";
88
export { BrowserAuthErrorCodes }; // Allow importing as "BrowserAuthErrorCodes"
99

10+
export function getDefaultErrorMessage(code: string): string {
11+
return `See https://aka.ms/msaljs/browser/errors#${code} for details`;
12+
}
13+
1014
/**
1115
* Browser library error class thrown by the MSAL.js library for SPAs
1216
*/
1317
export class BrowserAuthError extends AuthError {
1418
constructor(errorCode: string, subError?: string) {
15-
super(
16-
errorCode,
17-
`See https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/errors.md#${errorCode} for details`,
18-
subError
19-
);
19+
super(errorCode, getDefaultErrorMessage(errorCode), subError);
2020

2121
Object.setPrototypeOf(this, BrowserAuthError.prototype);
2222
this.name = "BrowserAuthError";

lib/msal-browser/src/error/BrowserConfigurationAuthError.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { AuthError } from "@azure/msal-common/browser";
77
import * as BrowserConfigurationAuthErrorCodes from "./BrowserConfigurationAuthErrorCodes.js";
8+
import { getDefaultErrorMessage } from "./BrowserAuthError.js";
89
export { BrowserConfigurationAuthErrorCodes };
910
/**
1011
* Browser library error class thrown by the MSAL.js library for SPAs
@@ -21,5 +22,8 @@ export class BrowserConfigurationAuthError extends AuthError {
2122
export function createBrowserConfigurationAuthError(
2223
errorCode: string
2324
): BrowserConfigurationAuthError {
24-
return new BrowserConfigurationAuthError(errorCode);
25+
return new BrowserConfigurationAuthError(
26+
errorCode,
27+
getDefaultErrorMessage(errorCode)
28+
);
2529
}

lib/msal-browser/src/error/NativeAuthError.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {
1313
createBrowserAuthError,
1414
BrowserAuthErrorCodes,
15+
getDefaultErrorMessage,
1516
} from "./BrowserAuthError.js";
1617

1718
import * as NativeAuthErrorCodes from "./NativeAuthErrorCodes.js";
@@ -32,7 +33,7 @@ export class NativeAuthError extends AuthError {
3233
ext: OSError | undefined;
3334

3435
constructor(errorCode: string, description?: string, ext?: OSError) {
35-
super(errorCode, description);
36+
super(errorCode, description || getDefaultErrorMessage(errorCode));
3637

3738
Object.setPrototypeOf(this, NativeAuthError.prototype);
3839
this.name = "NativeAuthError";
@@ -85,7 +86,8 @@ export function createNativeAuthError(
8586
switch (ext.status) {
8687
case NativeStatusCodes.ACCOUNT_UNAVAILABLE:
8788
return createInteractionRequiredAuthError(
88-
InteractionRequiredAuthErrorCodes.nativeAccountUnavailable
89+
InteractionRequiredAuthErrorCodes.nativeAccountUnavailable,
90+
getDefaultErrorMessage(code)
8991
);
9092
case NativeStatusCodes.USER_INTERACTION_REQUIRED:
9193
return new InteractionRequiredAuthError(code, description);

lib/msal-browser/test/app/IPublicClientApplication.spec.ts

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

66
import { stubbedPublicClientApplication } from "../../src/app/IPublicClientApplication";
7-
import { BrowserConfigurationAuthErrorMessages } from "../../src/error/BrowserConfigurationAuthError";
87
import { BrowserAuthError } from "../../src/error/BrowserAuthError";
98
import { BrowserConfigurationAuthErrorCodes } from "../../src/error/BrowserConfigurationAuthError.js";
9+
import { getDefaultErrorMessage } from "../../src/error/BrowserAuthError.js";
1010

1111
describe("IPublicClientApplication.ts Class Unit Tests", () => {
1212
describe("stubbedPublicClientApplication tests", () => {
@@ -18,10 +18,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
1818
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
1919
);
2020
expect(e.errorMessage).toEqual(
21-
BrowserConfigurationAuthErrorMessages[
22-
BrowserConfigurationAuthErrorCodes
23-
.stubbedPublicClientApplicationCalled
24-
]
21+
getDefaultErrorMessage(
22+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
23+
)
2524
);
2625
done();
2726
});
@@ -35,10 +34,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
3534
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
3635
);
3736
expect(e.errorMessage).toEqual(
38-
BrowserConfigurationAuthErrorMessages[
39-
BrowserConfigurationAuthErrorCodes
40-
.stubbedPublicClientApplicationCalled
41-
]
37+
getDefaultErrorMessage(
38+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
39+
)
4240
);
4341
done();
4442
});
@@ -52,10 +50,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
5250
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
5351
);
5452
expect(e.errorMessage).toEqual(
55-
BrowserConfigurationAuthErrorMessages[
56-
BrowserConfigurationAuthErrorCodes
57-
.stubbedPublicClientApplicationCalled
58-
]
53+
getDefaultErrorMessage(
54+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
55+
)
5956
);
6057
done();
6158
});
@@ -68,10 +65,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
6865
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
6966
);
7067
expect(e.errorMessage).toEqual(
71-
BrowserConfigurationAuthErrorMessages[
72-
BrowserConfigurationAuthErrorCodes
73-
.stubbedPublicClientApplicationCalled
74-
]
68+
getDefaultErrorMessage(
69+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
70+
)
7571
);
7672
done();
7773
});
@@ -83,10 +79,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
8379
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
8480
);
8581
expect(e.errorMessage).toEqual(
86-
BrowserConfigurationAuthErrorMessages[
87-
BrowserConfigurationAuthErrorCodes
88-
.stubbedPublicClientApplicationCalled
89-
]
82+
getDefaultErrorMessage(
83+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
84+
)
9085
);
9186
done();
9287
});
@@ -98,10 +93,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
9893
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
9994
);
10095
expect(e.errorMessage).toEqual(
101-
BrowserConfigurationAuthErrorMessages[
102-
BrowserConfigurationAuthErrorCodes
103-
.stubbedPublicClientApplicationCalled
104-
]
96+
getDefaultErrorMessage(
97+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
98+
)
10599
);
106100
done();
107101
});
@@ -113,10 +107,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
113107
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
114108
);
115109
expect(e.errorMessage).toEqual(
116-
BrowserConfigurationAuthErrorMessages[
117-
BrowserConfigurationAuthErrorCodes
118-
.stubbedPublicClientApplicationCalled
119-
]
110+
getDefaultErrorMessage(
111+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
112+
)
120113
);
121114
done();
122115
});
@@ -128,10 +121,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
128121
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
129122
);
130123
expect(e.errorMessage).toEqual(
131-
BrowserConfigurationAuthErrorMessages[
132-
BrowserConfigurationAuthErrorCodes
133-
.stubbedPublicClientApplicationCalled
134-
]
124+
getDefaultErrorMessage(
125+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
126+
)
135127
);
136128
done();
137129
});
@@ -143,10 +135,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
143135
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
144136
);
145137
expect(e.errorMessage).toEqual(
146-
BrowserConfigurationAuthErrorMessages[
147-
BrowserConfigurationAuthErrorCodes
148-
.stubbedPublicClientApplicationCalled
149-
]
138+
getDefaultErrorMessage(
139+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
140+
)
150141
);
151142
done();
152143
});
@@ -161,10 +152,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
161152
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
162153
);
163154
expect(browserAuthError.errorMessage).toEqual(
164-
BrowserConfigurationAuthErrorMessages[
165-
BrowserConfigurationAuthErrorCodes
166-
.stubbedPublicClientApplicationCalled
167-
]
155+
getDefaultErrorMessage(
156+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
157+
)
168158
);
169159
}
170160
});
@@ -178,10 +168,9 @@ describe("IPublicClientApplication.ts Class Unit Tests", () => {
178168
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
179169
);
180170
expect(browserAuthError.errorMessage).toEqual(
181-
BrowserConfigurationAuthErrorMessages[
182-
BrowserConfigurationAuthErrorCodes
183-
.stubbedPublicClientApplicationCalled
184-
]
171+
getDefaultErrorMessage(
172+
BrowserConfigurationAuthErrorCodes.stubbedPublicClientApplicationCalled
173+
)
185174
);
186175
}
187176
});

lib/msal-browser/test/app/PCANonBrowser.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import { NavigationClient } from "../../src/navigation/NavigationClient.js";
1818
import { SilentRequest } from "../../src/request/SilentRequest.js";
1919
import { AuthenticationResult } from "../../src/response/AuthenticationResult.js";
2020
import { TestTimeUtils } from "msal-test-utils";
21-
import {
22-
BrowserAuthErrorCodes,
23-
BrowserAuthErrorMessages,
24-
} from "../../src/error/BrowserAuthError.js";
21+
import { BrowserAuthErrorCodes } from "../../src/error/BrowserAuthError.js";
2522

2623
/**
2724
* Tests for PublicClientApplication.ts when run in a non-browser environment

lib/msal-browser/test/app/PublicClientApplication.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import { FetchClient } from "../../src/network/FetchClient.js";
8181
import {
8282
BrowserAuthError,
8383
BrowserAuthErrorCodes,
84-
BrowserAuthErrorMessages,
8584
createBrowserAuthError,
8685
} from "../../src/error/BrowserAuthError.js";
8786
import * as BrowserUtils from "../../src/utils/BrowserUtils.js";
@@ -120,6 +119,7 @@ import { INTERACTION_TYPE } from "../../src/utils/BrowserConstants.js";
120119
import { BaseOperatingContext } from "../../src/operatingcontext/BaseOperatingContext.js";
121120
import { PlatformAuthDOMHandler } from "../../src/broker/nativeBroker/PlatformAuthDOMHandler.js";
122121
import { config } from "process";
122+
import { getDefaultErrorMessage } from "../../src/error/BrowserAuthError.js";
123123

124124
const cacheConfig = {
125125
temporaryCacheLocation: BrowserCacheLocation.SessionStorage,
@@ -2005,9 +2005,9 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
20052005
BrowserAuthErrorCodes.blockNestedPopups
20062006
);
20072007
expect(e.errorMessage).toEqual(
2008-
BrowserAuthErrorMessages[
2008+
getDefaultErrorMessage(
20092009
BrowserAuthErrorCodes.blockNestedPopups
2010-
]
2010+
)
20112011
);
20122012
done();
20132013
})
@@ -3127,9 +3127,9 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
31273127
BrowserAuthErrorCodes.blockNestedPopups
31283128
);
31293129
expect(e.errorMessage).toEqual(
3130-
BrowserAuthErrorMessages[
3130+
getDefaultErrorMessage(
31313131
BrowserAuthErrorCodes.blockNestedPopups
3132-
]
3132+
)
31333133
);
31343134
done();
31353135
})
@@ -3878,10 +3878,9 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
38783878
BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform
38793879
);
38803880
expect(e.errorMessage).toEqual(
3881-
BrowserAuthErrorMessages[
3882-
BrowserAuthErrorCodes
3883-
.unableToAcquireTokenFromNativePlatform
3884-
]
3881+
getDefaultErrorMessage(
3882+
BrowserAuthErrorCodes.unableToAcquireTokenFromNativePlatform
3883+
)
38853884
);
38863885
});
38873886
expect(nativeAcquireTokenSpy).toHaveBeenCalledTimes(0);

lib/msal-browser/test/broker/PlatformAuthExtensionHandler.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import {
77
Logger,
88
AuthError,
9-
AuthErrorMessages,
109
AuthErrorCodes,
1110
IPerformanceClient,
1211
} from "@azure/msal-common";
@@ -19,7 +18,7 @@ import { CryptoOps } from "../../src/crypto/CryptoOps.js";
1918
import { mock } from "node:test";
2019
import { PlatformBrokerRequest } from "../../src/broker/nativeBroker/PlatformBrokerRequest.js";
2120
import { TEST_CONFIG, TEST_URIS } from "../utils/StringConstants.js";
22-
import { BrowserAuthErrorMessages } from "../../src/error/BrowserAuthError.js";
21+
import { getDefaultErrorMessage } from "../../src/error/BrowserAuthError.js";
2322

2423
let performanceClient: IPerformanceClient;
2524

@@ -189,9 +188,9 @@ describe("PlatformAuthExtensionHandler Tests", () => {
189188
BrowserAuthErrorCodes.nativeExtensionNotInstalled
190189
);
191190
expect(e.errorMessage).toBe(
192-
BrowserAuthErrorMessages[
191+
getDefaultErrorMessage(
193192
BrowserAuthErrorCodes.nativeExtensionNotInstalled
194-
]
193+
)
195194
);
196195
done();
197196
});
@@ -215,9 +214,9 @@ describe("PlatformAuthExtensionHandler Tests", () => {
215214
BrowserAuthErrorCodes.nativeHandshakeTimeout
216215
);
217216
expect(e.errorMessage).toBe(
218-
BrowserAuthErrorMessages[
217+
getDefaultErrorMessage(
219218
BrowserAuthErrorCodes.nativeHandshakeTimeout
220-
]
219+
)
221220
);
222221
done();
223222
})
@@ -504,7 +503,7 @@ describe("PlatformAuthExtensionHandler Tests", () => {
504503
AuthErrorCodes.unexpectedError
505504
);
506505
expect(e.errorMessage).toContain(
507-
AuthErrorMessages[AuthErrorCodes.unexpectedError]
506+
"Event does not contain result"
508507
);
509508
done();
510509
});

lib/msal-browser/test/error/BrowserAuthError.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
BrowserAuthError,
33
createBrowserAuthError,
4-
BrowserAuthErrorMessages,
54
BrowserAuthErrorCodes,
65
} from "../../src/error/BrowserAuthError";
76
import { AuthError } from "@azure/msal-common";
7+
import { getDefaultErrorMessage } from "../../src/error/BrowserAuthError.js";
88

99
describe("BrowserAuthError Unit Tests", () => {
1010
for (const key in BrowserAuthErrorCodes) {
@@ -13,7 +13,7 @@ describe("BrowserAuthError Unit Tests", () => {
1313
it(`BrowserAuthError object can be created for code ${code}`, () => {
1414
const err: BrowserAuthError = createBrowserAuthError(code);
1515

16-
const message = BrowserAuthErrorMessages[code];
16+
const message = getDefaultErrorMessage(code);
1717
expect(message).toBeTruthy();
1818

1919
expect(err instanceof BrowserAuthError).toBe(true);

lib/msal-browser/test/error/BrowserConfigurationAuthError.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { AuthError } from "@azure/msal-common";
22
import {
33
BrowserConfigurationAuthError,
44
BrowserConfigurationAuthErrorCodes,
5-
BrowserConfigurationAuthErrorMessages,
65
createBrowserConfigurationAuthError,
76
} from "../../src/error/BrowserConfigurationAuthError";
7+
import { getDefaultErrorMessage } from "../../src/error/BrowserAuthError.js";
88

99
describe("BrowserConfigurationAuthError Unit Tests", () => {
1010
for (const key in BrowserConfigurationAuthErrorCodes) {
@@ -16,7 +16,7 @@ describe("BrowserConfigurationAuthError Unit Tests", () => {
1616
const err: BrowserConfigurationAuthError =
1717
createBrowserConfigurationAuthError(code);
1818

19-
const message = BrowserConfigurationAuthErrorMessages[code];
19+
const message = getDefaultErrorMessage(code);
2020
expect(message).toBeTruthy();
2121

2222
expect(err instanceof BrowserConfigurationAuthError).toBe(true);

0 commit comments

Comments
 (0)