Skip to content

Add devMode for NAC widgets#969

Merged
rchlfryn merged 15 commits intomainfrom
nac-dev
Apr 17, 2026
Merged

Add devMode for NAC widgets#969
rchlfryn merged 15 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:

20260417_202409_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

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.

Did you forget to push? I'm not seeing this update in that commit or in this PR?

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.

This was so long ago I have no idea what I meant but this was not done in that commit. I remember coding this but don't know what happened. Done in 9ff7a91

Comment thread __tests__/server/getNACWidgetsConfig.server.test.ts
Comment thread src/utilities/getNACWidgetsConfig.ts Outdated
@rchlfryn
Copy link
Copy Markdown
Collaborator Author

@busbyk this is ready for re-review

Copy link
Copy Markdown
Collaborator

@busbyk busbyk left a comment

Choose a reason for hiding this comment

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

Re-reviewing this I had the thought: I wonder if we could use a provider and hook to provide the NAC Widgets Config to the NACWidget client component instead of all of this prop passing. This PR had to touch so many files just to add an option to that component.

@rchlfryn
Copy link
Copy Markdown
Collaborator Author

@busbyk Made this update. Good suggestion

@rchlfryn rchlfryn added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit f09946e Apr 17, 2026
9 checks passed
@rchlfryn rchlfryn deleted the nac-dev branch April 17, 2026 21:54
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