diff --git a/app/containers/LoginServices/__tests__/serviceLogin.test.ts b/app/containers/LoginServices/__tests__/serviceLogin.test.ts new file mode 100644 index 0000000000..7f85873b72 --- /dev/null +++ b/app/containers/LoginServices/__tests__/serviceLogin.test.ts @@ -0,0 +1,35 @@ +import * as WebBrowser from 'expo-web-browser'; + +import { onPressGoogle } from '../serviceLogin'; + +jest.mock('expo-web-browser', () => ({ + openAuthSessionAsync: jest.fn(() => Promise.resolve({ type: 'dismiss' })) +})); + +jest.mock('../../../lib/services/connect', () => ({ + loginOAuthOrSso: jest.fn() +})); + +const service = { + _id: 'google', + name: 'google', + service: 'google', + authType: 'oauth', + buttonColor: '#fff', + buttonLabelColor: '#000', + clientConfig: { provider: 'google' }, + serverURL: '', + authorizePath: '', + clientId: 'client-id', + scope: '' +} as const; + +describe('onPressGoogle', () => { + it('opens the Google OAuth URL with prompt=select_account', () => { + onPressGoogle({ service, server: 'https://mpbila.qa.rocket.chat' }); + + const url = (WebBrowser.openAuthSessionAsync as jest.Mock).mock.calls[0][0]; + expect(url).toContain('accounts.google.com/o/oauth2/auth'); + expect(url).toContain('prompt=select_account'); + }); +}); diff --git a/app/containers/LoginServices/serviceLogin.ts b/app/containers/LoginServices/serviceLogin.ts index fad1a839ac..8eafda139b 100644 --- a/app/containers/LoginServices/serviceLogin.ts +++ b/app/containers/LoginServices/serviceLogin.ts @@ -54,7 +54,7 @@ export const onPressGoogle = ({ service, server }: IServiceLogin) => { const redirect_uri = `${server}/_oauth/google?close`; const scope = encodeURIComponent('profile email'); const state = getOAuthState('redirect'); - const params = `?client_id=${clientId}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}&response_type=code`; + const params = `?client_id=${clientId}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}&response_type=code&prompt=select_account`; openOAuthSession(`${endpoint}${params}`); };