-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRAH-5056] Suisin/chore: change app ID based on FF value (#17889)
* chore: change app ID based on FF value * chore: add a check to not set app id if its exists * chore: add staging app id * chore: add hooks for hub redirection * chore: check app id on AppContent instead of app * chore: update hooks to have own App ID check logic * chore: remove test const variable
- Loading branch information
1 parent
ac6d910
commit 4e9ceda
Showing
5 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useClientCountry, useSettings } from '@deriv/api'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import useGrowthbookGetFeatureValue from '../useGrowthbookGetFeatureValue'; | ||
import useIsHubRedirectionEnabled from '../useIsHubRedirectionEnabled'; | ||
|
||
jest.mock('@deriv/api', () => ({ | ||
...jest.requireActual('@deriv/api'), | ||
useClientCountry: jest.fn(() => ({ data: 'US' })), | ||
useSettings: jest.fn(() => ({ data: { citizen: 'US' } })), | ||
})); | ||
|
||
jest.mock('../useGrowthbookGetFeatureValue', () => | ||
jest.fn(() => [ | ||
{ | ||
hub_enabled_country_list: [''], | ||
}, | ||
]) | ||
); | ||
|
||
describe('useIsHubRedirectionEnabled', () => { | ||
it('should return initial state correctly', () => { | ||
const { result } = renderHook(() => useIsHubRedirectionEnabled()); | ||
|
||
expect(result.current.isHubRedirectionEnabled).toBe(false); | ||
expect(result.current.isChangingToHubAppId).toBe(false); | ||
}); | ||
|
||
it('should return false if client country is not in the hub enabled list', () => { | ||
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' }); | ||
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'UK' } }); | ||
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ | ||
{ | ||
hub_enabled_country_list: ['US', 'AU'], | ||
}, | ||
]); | ||
const { result } = renderHook(() => useIsHubRedirectionEnabled()); | ||
expect(result.current.isHubRedirectionEnabled).toBe(false); | ||
}); | ||
|
||
it('should return true if client country is in the hub enabled list', () => { | ||
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' }); | ||
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'UK' } }); | ||
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ | ||
{ | ||
hub_enabled_country_list: ['US', 'AU', 'UK'], | ||
}, | ||
]); | ||
const { result } = renderHook(() => useIsHubRedirectionEnabled()); | ||
expect(result.current.isHubRedirectionEnabled).toBe(true); | ||
}); | ||
|
||
it('should return isChangingToHubAppId true if client country is in the hub enabled list but not in the citizen list', () => { | ||
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' }); | ||
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'MY' } }); | ||
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ | ||
{ | ||
hub_enabled_country_list: ['US', 'AU', 'UK'], | ||
}, | ||
]); | ||
const { result } = renderHook(() => useIsHubRedirectionEnabled()); | ||
expect(result.current.isChangingToHubAppId).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useClientCountry, useSettings } from '@deriv/api'; | ||
|
||
import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue'; | ||
|
||
type THubEnabledCountryList = { | ||
hub_enabled_country_list: string[]; | ||
}; | ||
|
||
const useIsHubRedirectionEnabled = () => { | ||
const [hubEnabledCountryList] = useGrowthbookGetFeatureValue({ | ||
featureFlag: 'hub_enabled_country_list', | ||
}); | ||
const { data: clientCountry } = useClientCountry(); | ||
const { data: accountSettings } = useSettings(); | ||
const { citizen } = accountSettings; | ||
|
||
const isHubRedirectionEnabled = | ||
typeof hubEnabledCountryList === 'object' && | ||
hubEnabledCountryList !== null && | ||
Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && | ||
citizen && | ||
(hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(citizen); | ||
|
||
const isChangingToHubAppId = | ||
typeof hubEnabledCountryList === 'object' && | ||
hubEnabledCountryList !== null && | ||
Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && | ||
clientCountry && | ||
(hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(clientCountry); | ||
|
||
return { isHubRedirectionEnabled, isChangingToHubAppId }; | ||
}; | ||
|
||
export default useIsHubRedirectionEnabled; |