-
Notifications
You must be signed in to change notification settings - Fork 1
Add devMode for NAC widgets #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0e3da7c
Add devMode to NAC widget config settings
rchlfryn 5f354e3
Pass devMode prop to all nac components
rchlfryn 6852c7c
Add migration to add devMode to settings
rchlfryn f96d272
Add unit test for getNACWidgetsConfig
rchlfryn 083c457
Add test for getAvalancheCenterPlatforms
rchlfryn 3e5fc08
Merge branch 'main' into nac-dev
rchlfryn 514ccdc
Fix bad migration from merging main
rchlfryn 840909d
Merge branch 'main' into nac-dev
rchlfryn 251372b
Change check to use getEnvironmentFriendlyName for production
rchlfryn 7b2ba3c
Merge branch 'main' into nac-dev
rchlfryn 2bceb78
Merge branch 'main' into nac-dev
rchlfryn 9ff7a91
Switch test to use msw
rchlfryn f03b268
Fix migration
rchlfryn c3f0966
Merge branch 'main' into nac-dev
rchlfryn 9a3fc7b
Adds NACWidgetsConfigProvider & useNACWidgetsConfig hook so component…
rchlfryn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
__tests__/server/getAvalancheCenterPlatforms.server.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { http, HttpResponse } from 'msw' | ||
| import { setupServer } from 'msw/node' | ||
|
|
||
| jest.mock('../../src/payload.config', () => ({})) | ||
|
|
||
| jest.mock('payload', () => ({ | ||
| getPayload: jest.fn(), | ||
| })) | ||
|
|
||
| import { getAvalancheCenterPlatforms } from '@/services/nac/nac' | ||
|
|
||
| const afpCentersResponse = { | ||
| centers: [ | ||
| { | ||
| id: 'NWAC', | ||
| display_id: 'NWAC', | ||
| platforms: { | ||
| warnings: true, | ||
| forecasts: true, | ||
| stations: true, | ||
| obs: true, | ||
| weather: true, | ||
| }, | ||
| }, | ||
| { | ||
| id: 'SAC', | ||
| display_id: 'SAC', | ||
| platforms: { | ||
| warnings: true, | ||
| forecasts: true, | ||
| stations: false, | ||
| obs: true, | ||
| weather: false, | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| const server = setupServer( | ||
| http.get('https://forecasts.avalanche.org/', () => HttpResponse.json(afpCentersResponse)), | ||
| ) | ||
|
|
||
| beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) | ||
| afterEach(() => server.resetHandlers()) | ||
| afterAll(() => server.close()) | ||
|
|
||
| describe('services: getAvalancheCenterPlatforms', () => { | ||
| it('returns platforms for a matching center slug', async () => { | ||
| const result = await getAvalancheCenterPlatforms('nwac') | ||
| expect(result).toEqual({ | ||
| warnings: true, | ||
| forecasts: true, | ||
| stations: true, | ||
| obs: true, | ||
| weather: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('maps dvac slug to nwac', async () => { | ||
| const result = await getAvalancheCenterPlatforms('dvac') | ||
| expect(result).toEqual({ | ||
| warnings: true, | ||
| forecasts: true, | ||
| stations: true, | ||
| obs: true, | ||
| weather: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('uppercases the slug for matching', async () => { | ||
| const result = await getAvalancheCenterPlatforms('sac') | ||
| expect(result).toEqual({ | ||
| warnings: true, | ||
| forecasts: true, | ||
| stations: false, | ||
| obs: true, | ||
| weather: false, | ||
| }) | ||
| }) | ||
|
|
||
| it('returns all-false platforms when center is not found', async () => { | ||
| const result = await getAvalancheCenterPlatforms('unknown') | ||
| expect(result).toEqual({ | ||
| warnings: false, | ||
| forecasts: false, | ||
| stations: false, | ||
| obs: false, | ||
| weather: false, | ||
| }) | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { getNACWidgetsConfig } from '@/utilities/getNACWidgetsConfig' | ||
|
|
||
| const mockConfig: { version: string; baseUrl: string; devMode?: boolean } = { | ||
| version: '20251207', | ||
| baseUrl: 'https://du6amfiq9m9h7.cloudfront.net/public/v2', | ||
| devMode: false, | ||
| } | ||
|
|
||
| jest.mock('../../src/utilities/getGlobals', () => ({ | ||
| getCachedGlobal: () => () => Promise.resolve(mockConfig), | ||
| })) | ||
|
|
||
| describe('utilities: getNACWidgetsConfig', () => { | ||
| const originalNodeEnv = process.env.NODE_ENV | ||
| const originalVercelEnv = process.env.VERCEL_ENV | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(process.env, 'NODE_ENV', { | ||
| value: originalNodeEnv, | ||
| configurable: true, | ||
| }) | ||
| if (originalVercelEnv === undefined) { | ||
| delete process.env.VERCEL_ENV | ||
| } else { | ||
| process.env.VERCEL_ENV = originalVercelEnv | ||
| } | ||
| mockConfig.devMode = false | ||
| }) | ||
|
|
||
| it('returns version and baseUrl from the global config', async () => { | ||
| const result = await getNACWidgetsConfig() | ||
| expect(result.version).toBe('20251207') | ||
| expect(result.baseUrl).toBe('https://du6amfiq9m9h7.cloudfront.net/public/v2') | ||
| }) | ||
|
|
||
| it('returns devMode from the global config in non-production', async () => { | ||
| Object.defineProperty(process.env, 'NODE_ENV', { value: 'development', configurable: true }) | ||
| mockConfig.devMode = true | ||
|
|
||
| const result = await getNACWidgetsConfig() | ||
| expect(result.devMode).toBe(true) | ||
| }) | ||
|
|
||
| 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 }) | ||
| process.env.VERCEL_ENV = 'production' | ||
| mockConfig.devMode = true | ||
|
|
||
| const result = await getNACWidgetsConfig() | ||
| expect(result.devMode).toBe(false) | ||
| }) | ||
|
|
||
| it('defaults devMode to false when not set in global config', async () => { | ||
| Object.defineProperty(process.env, 'NODE_ENV', { value: 'development', configurable: true }) | ||
| delete mockConfig.devMode | ||
|
|
||
| const result = await getNACWidgetsConfig() | ||
| expect(result.devMode).toBe(false) | ||
| }) | ||
|
|
||
| it('throws when version is missing', async () => { | ||
| const original = mockConfig.version | ||
| mockConfig.version = '' | ||
|
|
||
| await expect(getNACWidgetsConfig()).rejects.toThrow('Could not determine NAC widgets version') | ||
|
|
||
| mockConfig.version = original | ||
| }) | ||
|
|
||
| it('throws when baseUrl is missing', async () => { | ||
| const original = mockConfig.baseUrl | ||
| mockConfig.baseUrl = '' | ||
|
|
||
| await expect(getNACWidgetsConfig()).rejects.toThrow('Could not determine NAC widgets base url') | ||
|
|
||
| mockConfig.baseUrl = original | ||
| }) | ||
| }) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.