diff --git a/src/hooks/__tests__/useUIInstance.spec.ts b/src/hooks/__tests__/useUIInstance.spec.ts index 06f162f..11f2b0a 100644 --- a/src/hooks/__tests__/useUIInstance.spec.ts +++ b/src/hooks/__tests__/useUIInstance.spec.ts @@ -16,7 +16,7 @@ describe('getInternalInstance', () => { it('should return correct env for internal instance host', () => { mockLocation({ hostname: 'konflux.apps.stone-prod-p01.wcfb.p1.openshiftapps.com' }); expect(getInternalInstance()).toEqual('prod'); - mockLocation({ hostname: 'rhtap.apps.rosa.stone-stage-p01.apys.p3.openshiftapps.com' }); + mockLocation({ hostname: 'rhtap.apps.rosa.stone-stg-p01.apys.p3.openshiftapps.com' }); expect(getInternalInstance()).toEqual('stage'); mockLocation({ hostname: 'abcd.com' }); expect(getInternalInstance()).toEqual(undefined); @@ -33,7 +33,7 @@ describe('useUIInstance', () => { it('should return correct env for internal instance', () => { mockEnv.mockReturnValue('prod'); - mockLocation({ hostname: 'rhtap.apps.rosa.stone-stage-p01.apys.p3.openshiftapps.com' }); + mockLocation({ hostname: 'rhtap.apps.rosa.stone-stg-p01.apys.p3.openshiftapps.com' }); const { result, rerender } = renderHook(() => useUIInstance()); expect(result.current).toEqual('stage'); mockEnv.mockReturnValue('qa'); diff --git a/src/hooks/useUIInstance.ts b/src/hooks/useUIInstance.ts index 3535f23..6cbf31a 100644 --- a/src/hooks/useUIInstance.ts +++ b/src/hooks/useUIInstance.ts @@ -9,16 +9,24 @@ export enum ConsoleDotEnvironments { internalStage = 'stage', } +enum EnvironmentShortName { + stage = 'stg', + prod = 'prod', +} + export const getEnv = (): ConsoleDotEnvironments => ConsoleDotEnvironments.prod; -const internalInstance = (host: string) => (env: 'prod' | 'stage') => - new RegExp(`stone-${env}-([A-Za-z0-9]+).([a-z]+).([a-z0-9]+).openshiftapps.com`, 'g').test(host); +const internalInstance = + (host: string) => (env: EnvironmentShortName.prod | EnvironmentShortName.stage) => + new RegExp(`stone-${env}-([A-Za-z0-9]+).([a-z]+).([a-z0-9]+).openshiftapps.com`, 'g').test( + host, + ); export const getInternalInstance = () => { const matchInternalInstance = internalInstance(window.location.hostname); - if (matchInternalInstance('prod')) { + if (matchInternalInstance(EnvironmentShortName.prod)) { return ConsoleDotEnvironments.internalProd; - } else if (matchInternalInstance('stage')) { + } else if (matchInternalInstance(EnvironmentShortName.stage)) { return ConsoleDotEnvironments.internalStage; } return undefined;