#5878 - Student Forms e2e Tests - Ministry submitItemDecision#5966
#5878 - Student Forms e2e Tests - Ministry submitItemDecision#5966andrewsignori-aot merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds end-to-end coverage for the AEST/Ministry submitItemDecision endpoint on form submission items, along with supporting test utilities to make JWT payload manipulation and timestamp assertions reliable/deterministic.
Changes:
- Added comprehensive e2e tests for
PATCH /aest/form-submission/items/:id/decision(success + common failure scenarios). - Introduced a reusable
mockJWTTokenhelper to mutate JWT payloads in e2e tests (used to refactor student JWT mocking and enable role-removal scenarios). - Improved input handling for decision concurrency by transforming
lastUpdateDateto aDate, and stabilized test data timestamps by settingFormSubmission.createdAt.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sources/packages/backend/libs/test-utils/src/factories/form-submission.ts | Sets createdAt from the factory “now” value to keep timestamps deterministic in tests. |
| sources/packages/backend/apps/api/src/testHelpers/auth/token-helpers.ts | Adds mockJWTToken helper to mutate JWT payloads via JwtStrategy.validate spying. |
| sources/packages/backend/apps/api/src/testHelpers/auth/student-user-helpers.ts | Refactors mockJWTUserInfo to reuse mockJWTToken (reduces duplicated mocking logic). |
| sources/packages/backend/apps/api/src/testHelpers/auth/aest-token-helpers.ts | Adds removeJWTUserRoles helper for AEST authorization/role-negative test scenarios. |
| sources/packages/backend/apps/api/src/route-controllers/form-submission/models/form-submission.dto.ts | Ensures lastUpdateDate is transformed to Date for @IsDate() validation. |
| sources/packages/backend/apps/api/src/route-controllers/form-submission/tests/e2e/form-submission.aest.controller.submitItemDecision.e2e-spec.ts | New e2e suite validating decision submission behavior, authorization, concurrency/outdated handling, and not-found cases. |
|
| * Date when the decision record was last updated. Used for concurrency control | ||
| * to prevent overwriting a more recent decision. | ||
| */ | ||
| @Type(() => Date) |
There was a problem hiding this comment.
Did not find a reason why supertest is failing the DTO validation while Vue/axios is able to submit without any problem.
The recommendation seems to have the @Type(() => Date), hence I would like to keep it.
My best guess was some difference while setting the setGlobalPipes but we use the same method in E2E tests that is also used by the API.
| }; | ||
| const endpoint = `/aest/form-submission/items/${formSubmissionItemA.id}/decision`; | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| await removeJWTUserRoles(appModule, [Role.StudentApproveDeclineAppeals]); |
dheepak-aot
left a comment
There was a problem hiding this comment.
Good work @andrewsignori-aot 👍
| .expect({ | ||
| message: | ||
| "The application associated with the form submission is not in completed status.", | ||
| error: "Unprocessable Entity", |
There was a problem hiding this comment.
we should introduce a constant for this at some point
There was a problem hiding this comment.
Yeah, we are more lenient for E2E tests for these framework constants.
I am not opposed if someone starts it.
| .send(payload) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.UNPROCESSABLE_ENTITY) | ||
| .expect({ |
There was a problem hiding this comment.
I'm okay with this but i've been receiving the feedback to the use the new standard:
.expect(({ body }) => ...
There was a problem hiding this comment.
Is it about using the expect from supertest vs the expected from jest?
If yes, the idea of using the jest one for the body return was to allow easy troubleshooting for complex objects, especially when doing maintenance in existing E2E tests. I do not see it as necessary in this scenario.
@dheepak-aot FYI
tiago-graf
left a comment
There was a problem hiding this comment.
Just a couple of minor comments



PR Goal
Add some level of API endpoints E2E tests to all new endpoints introduced during the new forms implementation. At least one scenario for each endpoint must be present, and more scenarios can be added if time allows it. Suggestions for scenarios not covered are appreciated, but will be taken care of based on criticality and time available 😉
Ministry - submitItemDecision
New JWT Token Helpers
mockJWTTokento allow token manipulation.removeJWTUserRolesusing themockJWTTokenas a helper to remove existing roles from a Ministry user to test authorization scenarios. More variations can be added as needed.mockJWTUserInfois now also consuming themockJWTToken.