-
Notifications
You must be signed in to change notification settings - Fork 1
Confirmation email to citizen on form submission #936
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2348661
Stash
jbarnsley10 c2f71cb
Stash
jbarnsley10 57857ed
Adds confirmation email in message
jbarnsley10 7f45a4b
Renamed param to 'options'
jbarnsley10 32dce57
Schema correction
jbarnsley10 6eb7b8a
Plugin no longer supports userConfirmationEmail, move to Runner
alexluckett 65c74df
Extend Summary view to add our email input
alexluckett f5abec7
Fixed tests
jbarnsley10 b14cf7d
Changed to use custom property in meta
jbarnsley10 04f3af5
Upversioned plugin
jbarnsley10 8d0f551
Extra test
jbarnsley10 c8d8d32
Added comments about coercing
jbarnsley10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
146 changes: 146 additions & 0 deletions
146
src/server/plugins/SummaryPageWithConfirmationEmailController.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,146 @@ | ||
| import { type CacheService } from '@defra/forms-engine-plugin/cache-service.js' | ||
| import { type QuestionPageController } from '@defra/forms-engine-plugin/controllers/QuestionPageController.js' | ||
| import { FormModel } from '@defra/forms-engine-plugin/engine/models/FormModel.js' | ||
| import { buildFormRequest } from '@defra/forms-engine-plugin/engine/pageControllers/__stubs__/request.js' | ||
| import { type FormSubmissionState } from '@defra/forms-engine-plugin/engine/types.js' | ||
| import { | ||
| type FormRequest, | ||
| type FormRequestPayload, | ||
| type FormResponseToolkit | ||
| } from '@defra/forms-engine-plugin/types' | ||
| import { | ||
| ControllerType, | ||
| type PageSummaryWithConfirmationEmail | ||
| } from '@defra/forms-model' | ||
|
|
||
| import { | ||
| SummaryPageWithConfirmationEmailController, | ||
| getUserConfirmationEmailAddress | ||
| } from '~/src/server/plugins/SummaryPageWithConfirmationEmailController.js' | ||
| import definition from '~/test/form/definitions/basic.js' | ||
|
|
||
| describe('SummaryPageWithConfirmationEmailController', () => { | ||
| let model: FormModel | ||
| let controller: SummaryPageWithConfirmationEmailController | ||
| let requestPage: FormRequest | ||
|
|
||
| const response = { | ||
| code: jest.fn().mockImplementation(() => response) | ||
| } | ||
| const h: FormResponseToolkit = { | ||
| redirect: jest.fn().mockReturnValue(response), | ||
| view: jest.fn() | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| model = new FormModel(definition, { | ||
| basePath: 'test' | ||
| }) | ||
|
|
||
| // Create a mock page for SummaryPageWithConfirmationEmailController | ||
| const mockPage = { | ||
| ...definition.pages[0], | ||
| controller: ControllerType.SummaryWithConfirmationEmail | ||
| } as unknown as PageSummaryWithConfirmationEmail | ||
|
|
||
| controller = new SummaryPageWithConfirmationEmailController(model, mockPage) | ||
|
|
||
| requestPage = buildFormRequest({ | ||
| method: 'get', | ||
| url: new URL('http://example.com/test/summary'), | ||
| path: '/test/summary', | ||
| params: { | ||
| path: 'summary', | ||
| slug: 'test' | ||
| }, | ||
| query: {}, | ||
| app: { model } | ||
| } as FormRequest) | ||
| }) | ||
|
|
||
| describe('handle errors', () => { | ||
| it('should display errors including summary', async () => { | ||
| const state: FormSubmissionState = { | ||
| $$__referenceNumber: 'foobar', | ||
| licenceLength: 365, | ||
| fullName: 'John Smith' | ||
| } | ||
| const request = { | ||
| ...requestPage, | ||
| method: 'post', | ||
| payload: { invalid: '123', action: 'send' } | ||
| } as unknown as FormRequestPayload | ||
|
|
||
| const context = model.getFormContext(request, state) | ||
|
|
||
| jest | ||
| .spyOn(controller as unknown as QuestionPageController, 'getState') | ||
| .mockResolvedValue({}) | ||
| jest | ||
| .spyOn(controller as unknown as QuestionPageController, 'setState') | ||
| .mockResolvedValue(state) | ||
|
|
||
| const postHandler = controller.makePostRouteHandler() | ||
| await postHandler(request, context, h) | ||
|
|
||
| const viewModel = controller.getSummaryViewModel(request, context) | ||
|
|
||
| expect(h.view).toHaveBeenCalledWith( | ||
| 'summary-with-confirmation', | ||
| expect.anything() | ||
| ) | ||
| expect(viewModel.errors).toHaveLength(1) | ||
| const errorText = viewModel.errors ? viewModel.errors[0].text : '' | ||
| expect(errorText).toBe('"invalid" is not allowed') | ||
| }) | ||
| }) | ||
|
|
||
| describe('handleSaveAndExit', () => { | ||
| it('should invoke saveAndExit plugin option', async () => { | ||
| const saveAndExitMock = jest.fn(() => ({})) | ||
| const state: FormSubmissionState = { | ||
| $$__referenceNumber: 'foobar', | ||
| licenceLength: 365, | ||
| fullName: 'John Smith' | ||
| } | ||
| const request = { | ||
| ...requestPage, | ||
| server: { | ||
| plugins: { | ||
| 'forms-engine-plugin': { | ||
| saveAndExit: saveAndExitMock, | ||
| cacheService: { | ||
| clearState: jest.fn() | ||
| } as unknown as CacheService | ||
| } | ||
| } | ||
| }, | ||
| method: 'post', | ||
| payload: { fullName: 'John Smith', action: 'save-and-exit' } | ||
| } as unknown as FormRequestPayload | ||
|
|
||
| const context = model.getFormContext(request, state) | ||
|
|
||
| const postHandler = controller.makePostRouteHandler() | ||
| await postHandler(request, context, h) | ||
|
|
||
| expect(saveAndExitMock).toHaveBeenCalledWith(request, h, context) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getUserConfirmationEmailAddress', () => { | ||
| test('should get confirmation email', () => { | ||
| const field = getUserConfirmationEmailAddress() | ||
| expect(field.name).toBe('userConfirmationEmailAddress') | ||
| expect(field.value).toBeUndefined() | ||
| }) | ||
|
|
||
| test('should get confirmation email with retained value', () => { | ||
| const field = getUserConfirmationEmailAddress({ | ||
| userConfirmationEmailAddress: 'emailval' | ||
| }) | ||
| expect(field.name).toBe('userConfirmationEmailAddress') | ||
| expect(field.value).toBe('emailval') | ||
| }) | ||
| }) | ||
| }) |
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.