[WS-NA] - Add commands to package.json to enable toggles fetch from endpoint - #14271
Open
hotinglok wants to merge 6 commits into
Open
[WS-NA] - Add commands to package.json to enable toggles fetch from endpoint#14271hotinglok wants to merge 6 commits into
hotinglok wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds local developer ergonomics for testing remote feature toggles by introducing dedicated yarn scripts that set toggle-fetching env vars, updating the toggle-fetching utility to support a locally selectable service environment and to bypass caching on local, and aligning tests/docs with the new workflow.
Changes:
- Added
yarn dev:toggles:test/yarn dev:toggles:livescripts to runnext devwith remote toggle fetching enabled and a selectablectx-service-env. - Updated toggle fetching to derive
ctx-service-envfromTOGGLES_SERVICE_ENVwhen running locally and to bypass the LRU response cache on local. - Updated unit tests and documentation to reflect/verify the new local toggle-fetching behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| ws-nextjs-app/package.json | Adds new dev scripts for toggles test/live fetching. |
| src/app/lib/utilities/fetchToggles/index.ts | Supports local TOGGLES_SERVICE_ENV and disables caching when SIMORGH_APP_ENV=local. |
| src/app/lib/utilities/fetchToggles/index.client.test.ts | Extends test coverage for local cache-bypass and header behavior; adds env restoration. |
| src/app/lib/config/toggles/README.md | Documents the new yarn dev:toggles:* commands and intended behavior. |
| @@ -26,6 +28,18 @@ describe('getToggles', () => { | |||
| jest.resetModules(); | |||
| jest.restoreAllMocks(); | |||
| process.env.TOGGLES_BFF_PATH = originalTogglesBffPath; | |||
Comment on lines
97
to
+101
| const responseBody = await response.json(); | ||
| const fetchedToggles = responseBody?.data?.toggles; | ||
|
|
||
| cache.set(cacheKey, fetchedToggles); | ||
| if (!isLocal) { | ||
| cache.set(cacheKey, fetchedToggles); |
Comment on lines
41
to
+53
| const appEnvironment = getEnvConfig().SIMORGH_APP_ENV || 'local'; | ||
| const localToggles = defaultToggles[appEnvironment]; | ||
|
|
||
| if (!localToggles.enableFetchingToggles.enabled) { | ||
| return localToggles; | ||
| } | ||
|
|
||
| const togglesEndpoint = constructTogglesEndpoint({ service, isAmp }); | ||
|
|
||
| const isLocal = appEnvironment === 'local'; | ||
| const serviceEnv = isLocal ? 'test' : appEnvironment; | ||
| const serviceEnv = isLocal | ||
| ? process.env.TOGGLES_SERVICE_ENV || 'test' | ||
| : appEnvironment; |
Comment on lines
+95
to
+111
| it('should support a nested data.toggles response shape', async () => { | ||
| (global.fetch as jest.Mock).mockResolvedValueOnce({ | ||
| ok: true, | ||
| status: 200, | ||
| json: jest.fn(async () => ({ data: { toggles: remoteToggles } })), | ||
| } as unknown as Response); | ||
|
|
||
| const { default: getToggles } = await import('./index'); | ||
| const toggles = await getToggles({ | ||
| service: 'mundo', | ||
| }); | ||
|
|
||
| expect(toggles).toEqual({ | ||
| ...mockDefaultToggleDefinitions, | ||
| ...remoteToggles, | ||
| }); | ||
| }); |
pvaliani
approved these changes
Jul 28, 2026
emilysaffron
approved these changes
Jul 29, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Par of JIRA: WS-2817
Summary
Testing toggles across different environments is often inconvenient, requiring headers to switch between test/live as well as enabling/disabling fetching from iSite.
This PR adds a few commands to the package.json to make this easier and disables the cache on local.
Code changes
yarn dev:toggles:testandyarn dev:toggles:liveto package.jsonTesting
Useful Links