Fix SecurityManager flaky test (#8753)

This commit is contained in:
Elias Nahum 2025-04-08 20:25:14 +08:00 committed by GitHub
parent 1c0e201edf
commit 74ee271012
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -394,7 +394,17 @@ describe('SecurityManager', () => {
});
describe('goToPreviousServer', () => {
afterAll(() => {
jest.clearAllMocks();
});
test('should switch to previous server', async () => {
jest.mocked(Emm.isDeviceSecured).mockResolvedValue(true);
jest.mocked(Emm.authenticate).mockResolvedValue(true);
jest.mocked(switchToServer).mockImplementation((serverUrl: string) => {
SecurityManager.setActiveServer(serverUrl);
return Promise.resolve();
});
SecurityManager.activeServer = undefined;
SecurityManager.addServer('server-10', {MobileEnableBiometrics: 'true'} as ClientConfig);
SecurityManager.setActiveServer('server-10');
@ -402,6 +412,7 @@ describe('SecurityManager', () => {
SecurityManager.setActiveServer('server-11');
await SecurityManager.goToPreviousServer(['server-10', 'server-11']);
expect(switchToServer).toHaveBeenCalledWith('server-10', expect.anything(), expect.anything());
expect(SecurityManager.activeServer).toBe('server-10');
});
});

View file

@ -292,7 +292,7 @@ class SecurityManagerSingleton {
defaultLocale: DEFAULT_LOCALE,
messages: getTranslations(locale),
});
switchToServer(lastAccessedServer, theme, intl);
await switchToServer(lastAccessedServer, theme, intl);
}
};