-
Notifications
You must be signed in to change notification settings - Fork 1
TGC-1259: Add hoisting for API based config form, to match direct fil… #826
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
aaroncarroll82
merged 14 commits into
main
from
bugfix/TGC-1259-hoist-config-on-api-yaml
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
28d3938
TGC-1259: Add hoisting for API based config form, to match direct fil…
aaroncarroll82 04e9faf
prettier got me...
aaroncarroll82 93afa5b
Merge branch 'main' into bugfix/TGC-1259-hoist-config-on-api-yaml
aaroncarroll82 9367750
Update the test yaml used by config broker to match latest
aaroncarroll82 56cf0fe
Merge branch 'main' into bugfix/TGC-1259-hoist-config-on-api-yaml
aaroncarroll82 bb94674
Load form def on non-plugin extending controllers. Expose forms service
aaroncarroll82 c52a16e
Merge branch 'main' into bugfix/TGC-1259-hoist-config-on-api-yaml
aaroncarroll82 d25bb9b
lint check on types not happy
aaroncarroll82 383d5bb
make sonar happy after changes to make linter happy
aaroncarroll82 0aab160
prettier
aaroncarroll82 907e4c7
sonar again
aaroncarroll82 1fc039c
Address some review comments
aaroncarroll82 be770dc
Merge branch 'main' into bugfix/TGC-1259-hoist-config-on-api-yaml
aaroncarroll82 34f8f79
Add type definition for getFormService
aaroncarroll82 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
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
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
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
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
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,27 @@ | ||
| import { statusCodes } from '~/src/server/common/constants/status-codes.js' | ||
| import { findFormBySlug } from '~/src/server/common/forms/services/find-form-by-slug.js' | ||
|
|
||
| export async function validateRequestAndFindForm(request, h) { | ||
| const { slug } = request.params | ||
|
|
||
| if (!slug) { | ||
| return { error: h.response('Bad request - missing slug').code(statusCodes.badRequest).takeover() } | ||
| } | ||
|
|
||
| const form = await findFormBySlug(slug) | ||
| if (!form) { | ||
| return { error: h.response('Form not found').code(statusCodes.notFound).takeover() } | ||
| } | ||
|
|
||
| // For pages that do not extend the DXT controllers, this model will not be set, but it is required for retrieving the | ||
| // correct state from backend when using form definitions loaded via config API (as version is required) | ||
| if (!request.app?.model) { | ||
| request.app.model = { | ||
| def: { | ||
| metadata: form.metadata | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { form, slug } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
src/server/common/helpers/form-verify-and-request-load.test.js
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,40 @@ | ||
| import { mockHapiRequest, mockHapiResponseToolkit } from '~/src/__mocks__/index.js' | ||
| import { validateRequestAndFindForm } from './form-verify-and-request-load.js' | ||
| import { vi } from 'vitest' | ||
| import { findFormBySlug } from '../forms/services/find-form-by-slug.js' | ||
| import { MOCK_FORM_WITH_PATH } from '~/src/__test-fixtures__/mock-forms-cache.js' | ||
|
|
||
| vi.mock('../forms/services/find-form-by-slug.js') | ||
|
|
||
| const mockForm = MOCK_FORM_WITH_PATH | ||
|
|
||
| describe('form-verify-and-request-load', () => { | ||
| it('should return 400 response error when slug is missing', async () => { | ||
| const mockH = mockHapiResponseToolkit() | ||
| const result = await validateRequestAndFindForm(mockHapiRequest({ params: {} }), mockH) | ||
| expect(result.error).toBe(mockH) | ||
| expect(mockH.response).toHaveBeenCalledWith('Bad request - missing slug') | ||
| expect(mockH.code).toHaveBeenCalledWith(400) | ||
| }) | ||
|
|
||
| it('should return 404 response error when form not found', async () => { | ||
| findFormBySlug.mockResolvedValue(undefined) | ||
| const mockH = mockHapiResponseToolkit() | ||
| const result = await validateRequestAndFindForm(mockHapiRequest({ params: { slug: 'test-slug' } }), mockH) | ||
| expect(result.error).toBe(mockH) | ||
| expect(mockH.response).toHaveBeenCalledWith('Form not found') | ||
| expect(mockH.code).toHaveBeenCalledWith(404) | ||
| }) | ||
|
|
||
| it('should return form and slug and set request app model when inputs valid', async () => { | ||
| const formWithMetaData = { ...mockForm, metadata: { some: 'metadata' } } | ||
| findFormBySlug.mockResolvedValue(formWithMetaData) | ||
| const mockH = mockHapiResponseToolkit() | ||
| const requestProps = { params: { slug: 'test-slug' }, app: {} } | ||
| const result = await validateRequestAndFindForm(mockHapiRequest(requestProps), mockH) | ||
| expect(result.error).toBeUndefined() | ||
| expect(result.form).toBe(formWithMetaData) | ||
| expect(result.slug).toBe('test-slug') | ||
| expect(requestProps.app.model.def.metadata).toEqual({ some: 'metadata' }) | ||
| }) | ||
| }) |
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.