Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/containers/LoginServices/__tests__/serviceLogin.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
2 changes: 1 addition & 1 deletion app/containers/LoginServices/serviceLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

Expand Down
Loading