Skip to content

Commit f58c07d

Browse files
committed
fix tests
1 parent 92291d8 commit f58c07d

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

__mocks__/@azure/msal-browser

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
export class PublicClientApplication {
2-
constructor(configuration: any) {
3-
// Mock constructor
4-
}
2+
constructor(configuration: any) {
3+
// Mock constructor
4+
}
55

6-
initialize() {
7-
// Mock initialize method
8-
}
6+
async initialize() {
7+
// Mock implementation of initialize
8+
return Promise.resolve();
9+
}
910

10-
acquireTokenSilent() {
11-
// Mock acquireTokenSilent method
12-
return Promise.resolve({ accessToken: 'mock-access-token' });
13-
}
11+
acquireTokenSilent() {
12+
// Mock acquireTokenSilent method
13+
return Promise.resolve({ accessToken: 'mock-access-token' });
14+
}
1415

15-
acquireTokenPopup() {
16-
// Mock acquireTokenPopup method
17-
return Promise.resolve({ accessToken: 'mock-access-token' });
18-
}
16+
acquireTokenPopup() {
17+
// Mock acquireTokenPopup method
18+
return Promise.resolve({ accessToken: 'mock-access-token' });
19+
}
1920

20-
loginPopup() {
21-
// Mock loginPopup method
22-
return Promise.resolve({ account: { username: 'mock-user' } });
23-
}
21+
loginPopup() {
22+
// Mock loginPopup method
23+
return Promise.resolve({ account: { username: 'mock-user' } });
24+
}
2425

25-
logout() {
26-
// Mock logout method
27-
return Promise.resolve();
28-
}
29-
}
26+
logout() {
27+
// Mock logout method
28+
return Promise.resolve();
29+
}
30+
}

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ import { IDevxAPI } from './types/devx-api';
3333
import { Mode } from './types/enums';
3434
import { IHistoryItem } from './types/history';
3535
import { Collection } from './types/resources';
36+
import { initializeMsal } from './modules/authentication/msal-app';
3637

3738

3839
const appRoot: HTMLElement = document.getElementById('root')!;
3940
initializeIcons();
41+
await initializeMsal();
4042

4143
let currentTheme = readFromLocalStorage(CURRENT_THEME) || 'light';
4244
export function removeSpinners() {

src/modules/authentication/msal-app.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,18 @@ export const configuration: Configuration = {
6868
}
6969
};
7070

71-
const initializeMsal = async (): Promise<void> => {
72-
await msalApplication.initialize();
73-
};
71+
export const msalApplication = new PublicClientApplication(configuration);
7472

75-
const msalApplication = new PublicClientApplication(configuration);
76-
await initializeMsal();
77-
export { msalApplication };
73+
export async function initializeMsal(): Promise<void> {
74+
try {
75+
await msalApplication.initialize();
76+
return Promise.resolve();
77+
} catch (error) {
78+
telemetry.trackException(
79+
new Error(errorTypes.OPERATIONAL_ERROR),
80+
SeverityLevel.Error,
81+
{ ComponentName: 'MSAL', Message: 'Failed to initialize MSAL' }
82+
);
83+
return Promise.reject(error);
84+
}
85+
}

0 commit comments

Comments
 (0)