Skip to content

[WS-NA] - Add commands to package.json to enable toggles fetch from endpoint - #14271

Open
hotinglok wants to merge 6 commits into
WS-2817-refactor-toggles-urlfrom
WS-NA-add-script-to-change-toggles
Open

[WS-NA] - Add commands to package.json to enable toggles fetch from endpoint#14271
hotinglok wants to merge 6 commits into
WS-2817-refactor-toggles-urlfrom
WS-NA-add-script-to-change-toggles

Conversation

@hotinglok

@hotinglok hotinglok commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

  • Adds yarn dev:toggles:test and yarn dev:toggles:live to package.json
  • Adds dynamic variables to change based on command run

Testing

  1. List the steps required to test this PR.

Useful Links

@hotinglok
hotinglok changed the base branch from latest to WS-2817-refactor-toggles-url July 28, 2026 10:20
@hotinglok
hotinglok marked this pull request as ready for review July 28, 2026 11:38
@hotinglok
hotinglok requested a review from a team as a code owner July 28, 2026 11:38
Copilot AI review requested due to automatic review settings July 28, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:live scripts to run next dev with remote toggle fetching enabled and a selectable ctx-service-env.
  • Updated toggle fetching to derive ctx-service-env from TOGGLES_SERVICE_ENV when 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,
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants