Skip to content

Add devMode for NAC widgets#969

Open
rchlfryn wants to merge 9 commits intomainfrom
nac-dev
Open

Add devMode for NAC widgets#969
rchlfryn wants to merge 9 commits intomainfrom
nac-dev

Conversation

@rchlfryn
Copy link
Copy Markdown
Collaborator

@rchlfryn rchlfryn commented Mar 4, 2026

Description

Add a devMode setting to the NAC Widgets Config admin panel and pass it through to all NAC widget components.

Previously, devMode was always hardcoded to false. This makes it impossible for staging/preview deployments to point widgets at the NAC staging base URL — needed for AvyApp development and testing custom data entered in staging. In production, devMode is always forced to false regardless of the admin panel setting.

Related Issues

Fixes #717

Key Changes

  • Add devMode checkbox to NAC Widgets Config global
  • Respect the admin panel devMode setting in non-production environments, force false in production
  • Pass devMode through to all NAC widget components (was hardcoded false)
  • Add tests for getNACWidgetsConfig and getAvalancheCenterPlatforms using MSW to intercept HTTP requests
  • Add MSW as a dev dependency for realistic API mocking in tests
  • Migration to add devMode column

How to test

  1. Local/staging
    2. with admin panel devMode off→ widgets use production URL (devMode: false)
    3. with admin panel devMode on → widgets use staging URL (devMode: true)
  2. Production → widgets always use production URL (devMode: false) regardless of admin setting
  3. Check /api/[center]/nac-config returns the correct devMode value
  4. Run pnpm test — all tests pass

Migration Explanation

Adds a devMode boolean column (default false) to the NAC widgets config table. Non-destructive — existing rows get the default value.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Migration Safety Check

Found 1 potential issue:

20260325_173659_add_dev_mode.ts

Warning (line 6): ALTER keyword detected - review for data loss

sql`ALTER TABLE \`nac_widgets_config\` ADD \`dev_mode\` integer DEFAULT false NOT NULL;`,

Review these patterns and add backup/restore logic if needed. See docs/migration-safety.md for guidance.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

Preview deployment: https://nac-dev.preview.avy-fx.org

@rchlfryn
Copy link
Copy Markdown
Collaborator Author

rchlfryn commented Mar 5, 2026

@busbyk Leaving this as a draft. It is ready fro review but I am curious if you think this is the correct approach based on the issue you wrote.

@rchlfryn rchlfryn marked this pull request as ready for review March 10, 2026 16:28
@rchlfryn
Copy link
Copy Markdown
Collaborator Author

@busbyk Ready for review

Comment on lines +31 to +37
jest.mock('../../src/services/nac/nac', () => ({
getAvalancheCenterPlatforms: jest.fn(async (centerSlug: string) => {
const centerSlugToUse = centerSlug === 'dvac' ? 'nwac' : centerSlug

return mockCenters[centerSlugToUse] ?? allFalsePlatforms
}),
}))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replacing the function we're testing here with a mocked function that's only used in this test doesn't actually test the getAvalancheCenterPlatforms function.

Ideally, we would intercept the API requests and return mocked data using MSW or something similar so that we would be testing the actual implementation of getAvalancheCenterPlatforms.

If you don't want to set up MSW, I suggest removing this test file completely.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good callout - set up MSW you linked and implemented this in 251372b

Comment on lines +30 to +36
it('forces devMode to false in production even when global config has it enabled', async () => {
Object.defineProperty(process.env, 'NODE_ENV', { value: 'production', configurable: true })
mockConfig.devMode = true

const result = await getNACWidgetsConfig()
expect(result.devMode).toBe(false)
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR description says that nacWidgetsConfig.devMode should be respected when NAC_WIDGET_DEV_MODE is not set.

Copy link
Copy Markdown
Collaborator Author

@rchlfryn rchlfryn Mar 25, 2026

Choose a reason for hiding this comment

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

Ah good shout - this was implemented incorrectly and overengineered. I somehow got confused. The priority is:

  • if prod -> always false
  • nacWidgetsConfig.devMode from admin panel (if env var not set)
  • false (if neither is set)

Comment on lines +19 to +21
// In production, always force devMode off regardless of the admin setting
const devMode =
process.env.NODE_ENV === 'production' ? false : (nacWidgetsConfig?.devMode ?? false)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea I don't see why we wouldn't respect this in production.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The intention was we would never want this to be accidentally true in production, but I guess we might want that? I can't think of a use case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

from slack convo: we will check our environment friendly name via https://github.com/NWACus/web/blob/main/src/utilities/getEnvironmentFriendlyName.ts and disable in prod but allow in other environments like dev and preview.

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.

NAC Widgets devMode

2 participants