From 7ce6dd929431c15b3ba4860318a7a7d5cac28025 Mon Sep 17 00:00:00 2001 From: Yaddalapalli-Charan-Kumar-Naidu Date: Mon, 17 Aug 2026 22:29:33 +0530 Subject: [PATCH] fix: Apple OAuth icon fallback and button label --- app/lib/services/connect.ios.test.ts | 97 +++++++++++++++++++++++++++- app/lib/services/connect.test.ts | 47 +++++++++++++- app/lib/services/connect.ts | 2 +- 3 files changed, 142 insertions(+), 4 deletions(-) diff --git a/app/lib/services/connect.ios.test.ts b/app/lib/services/connect.ios.test.ts index f09cf1778c2..3a265cad26f 100644 --- a/app/lib/services/connect.ios.test.ts +++ b/app/lib/services/connect.ios.test.ts @@ -1,4 +1,5 @@ -import { determineAuthType } from './connect'; +import { determineAuthType, getLoginServices } from './connect'; +import { setLoginServices } from '../../actions/login'; jest.mock('./voip/MediaSessionInstance', () => ({ mediaSessionInstance: { reset: jest.fn() } @@ -9,6 +10,14 @@ jest.mock('../methods/helpers/deviceInfo', () => ({ isIOS: true })); +const mockStoreDispatch = jest.fn(); +jest.mock('../store/auxStore', () => ({ + store: { + dispatch: (action: unknown) => mockStoreDispatch(action), + getState: jest.fn() + } +})); + interface IServices { [index: string]: string | boolean; name: string; @@ -143,4 +152,90 @@ describe('determineAuthType - iOS specific tests', () => { expect(result).toBe('not_supported'); }); }); + + describe('getLoginServices', () => { + const originalFetch = global.fetch; + + afterEach(() => { + global.fetch = originalFetch; + }); + + it('should correctly map Apple OAuth with service name "apple" instead of buttonLabelText', async () => { + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + success: true, + services: [ + { + _id: 'Accounts_OAuth_Apple', + service: 'apple', + buttonLabelText: 'Sign in with Apple', + buttonColor: '#000', + buttonLabelColor: '#FFF', + custom: false + } + ] + }) + }) as any; + + await getLoginServices('https://open.rocket.chat'); + + expect(mockStoreDispatch).toHaveBeenCalledWith( + setLoginServices({ + apple: { + _id: 'Accounts_OAuth_Apple', + service: 'apple', + buttonLabelText: 'Sign in with Apple', + buttonColor: '#000', + buttonLabelColor: '#FFF', + custom: false, + name: 'apple', + authType: 'apple' + } + }) + ); + }); + + it('should correctly map standard OAuth providers', async () => { + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + success: true, + services: [ + { + _id: 'Accounts_OAuth_Google', + service: 'google', + buttonLabelText: '', + custom: false + } + ] + }) + }) as any; + + await getLoginServices('https://open.rocket.chat'); + + expect(mockStoreDispatch).toHaveBeenCalledWith( + setLoginServices({ + google: { + _id: 'Accounts_OAuth_Google', + service: 'google', + buttonLabelText: '', + custom: false, + name: 'google', + authType: 'oauth' + } + }) + ); + }); + + it('should dispatch empty object when server returns no services or failure', async () => { + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + success: false + }) + }) as any; + + await getLoginServices('https://open.rocket.chat'); + + expect(mockStoreDispatch).toHaveBeenCalledWith(setLoginServices({})); + }); + }); }); diff --git a/app/lib/services/connect.test.ts b/app/lib/services/connect.test.ts index 7f1ad5edd3b..f91c5fd4779 100644 --- a/app/lib/services/connect.test.ts +++ b/app/lib/services/connect.test.ts @@ -1,7 +1,7 @@ -import { connect, determineAuthType, disconnect } from './connect'; +import { connect, determineAuthType, disconnect, getLoginServices } from './connect'; import { mediaSessionInstance } from './voip/MediaSessionInstance'; import { pendingHangups } from './voip/pendingHangups'; -import { setUser } from '../../actions/login'; +import { setLoginServices, setUser } from '../../actions/login'; import database from '../database'; jest.mock('./voip/MediaSessionInstance', () => ({ @@ -628,4 +628,47 @@ describe('connect — stream-notify-logged updateAvatar', () => { }); }); +describe('getLoginServices (non-iOS)', () => { + const originalFetch = global.fetch; + + afterEach(() => { + global.fetch = originalFetch; + }); + + it('should filter out Apple authentication on non-iOS devices', async () => { + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + success: true, + services: [ + { + _id: 'Accounts_OAuth_Apple', + service: 'apple', + buttonLabelText: 'Sign in with Apple', + custom: false + }, + { + _id: 'Accounts_OAuth_Google', + service: 'google', + custom: false + } + ] + }) + }) as any; + + await getLoginServices('https://open.rocket.chat'); + + expect(mockStoreDispatch).toHaveBeenCalledWith( + setLoginServices({ + google: { + _id: 'Accounts_OAuth_Google', + service: 'google', + custom: false, + name: 'google', + authType: 'oauth' + } + }) + ); + }); +}); + // Note: Apple authentication when isIOS is true is tested in connect.ios.test.ts diff --git a/app/lib/services/connect.ts b/app/lib/services/connect.ts index 1f9043efd1f..b69f08d90e2 100644 --- a/app/lib/services/connect.ts +++ b/app/lib/services/connect.ts @@ -480,7 +480,7 @@ async function getLoginServices(server: string) { loginServices = services; const loginServicesReducer = loginServices.reduce((ret: IServices[], item: IServices) => { - const name = item.name || item.buttonLabelText || item.service; + const name = item.name || item.service || item.buttonLabelText; const authType = determineAuthType(item); if (authType !== 'not_supported') {