-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 711 - Hooked up feature flag api with UI (#302)
--------- Co-authored-by: Scott Alexander <[email protected]> Co-authored-by: Rio Knightley <[email protected]>
- Loading branch information
1 parent
0c8fdae
commit d763338
Showing
20 changed files
with
341 additions
and
228 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
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
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
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,45 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import useConfig from './useConfig'; | ||
import ConfigProvider, { GlobalConfig } from '../../providers/configProvider/ConfigProvider'; | ||
import { defaultFeatureFlags } from '../requests/getFeatureFlags'; | ||
|
||
describe('useConfig', () => { | ||
beforeEach(() => { | ||
sessionStorage.setItem('FeatureFlags', ''); | ||
process.env.REACT_APP_ENVIRONMENT = 'jest'; | ||
}); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('returns true when feature flag in context', () => { | ||
const config: GlobalConfig = { | ||
featureFlags: { ...defaultFeatureFlags, testFeature1: true }, | ||
mockLocal: {}, | ||
}; | ||
renderHook(config); | ||
expect(screen.getByText(`FLAG: true`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('returns false when there is no feature flag in context', () => { | ||
const config: GlobalConfig = { | ||
featureFlags: { ...defaultFeatureFlags, testFeature1: false }, | ||
mockLocal: {}, | ||
}; | ||
renderHook(config); | ||
expect(screen.getByText(`FLAG: false`)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
const TestApp = () => { | ||
const config = useConfig(); | ||
return <div>{`FLAG: ${!!config.featureFlags.testFeature1}`.normalize()}</div>; | ||
}; | ||
|
||
const renderHook = (config?: GlobalConfig) => { | ||
return render( | ||
<ConfigProvider configOverride={config}> | ||
<TestApp /> | ||
</ConfigProvider>, | ||
); | ||
}; |
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,8 @@ | ||
import { useConfigContext } from '../../providers/configProvider/ConfigProvider'; | ||
|
||
function useConfig() { | ||
const [config] = useConfigContext(); | ||
return config; | ||
} | ||
|
||
export default useConfig; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
import { AuthHeaders } from '../../types/blocks/authHeaders'; | ||
import { endpoints } from '../../types/generic/endpoints'; | ||
|
||
import axios from 'axios'; | ||
import { FeatureFlags } from '../../types/generic/featureFlags'; | ||
|
||
type Args = { | ||
baseUrl: string; | ||
baseHeaders: AuthHeaders; | ||
}; | ||
|
||
type GetFeatureFlagsResponse = { | ||
data: FeatureFlags; | ||
}; | ||
|
||
export const defaultFeatureFlags = { | ||
testFeature1: false, | ||
testFeature2: false, | ||
testFeature3: false, | ||
}; | ||
|
||
const getFeatureFlags = async ({ baseUrl, baseHeaders }: Args) => { | ||
const gatewayUrl = baseUrl + endpoints.FEATURE_FLAGS; | ||
try { | ||
const { data }: GetFeatureFlagsResponse = await axios.get(gatewayUrl, { | ||
headers: { | ||
...baseHeaders, | ||
}, | ||
}); | ||
return data; | ||
} catch (e) { | ||
return defaultFeatureFlags; | ||
} | ||
}; | ||
|
||
export default getFeatureFlags; |
Oops, something went wrong.