-
Notifications
You must be signed in to change notification settings - Fork 14
#5878 - Student Forms e2e Tests - getFormSubmission #5924
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
Open
andrewsignori-aot
wants to merge
10
commits into
main
Choose a base branch
from
feature/#5878-forms-e2e-tests-part-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a460ee
Starting E2E for getFormSubmission
andrewsignori-aot 9a46c83
getFormSubmission updates
andrewsignori-aot 19ad67d
Added getFormSubmission for FormSubmissionAESTController
andrewsignori-aot b1fe08c
Institutions getFormSubmission
andrewsignori-aot a44b9e0
Pre review changes
andrewsignori-aot 468185e
Adjusting data for Ministry user without approval role
andrewsignori-aot b601d69
Minor fixes
andrewsignori-aot c93bec6
Merge branch 'main' into feature/#5878-forms-e2e-tests-part-2
andrewsignori-aot 4944d3d
Copilot and other E2E fixes
andrewsignori-aot 8785129
PR comments
andrewsignori-aot 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
471 changes: 471 additions & 0 deletions
471
...form-submission/_tests_/e2e/form-submission.aest.controller.getFormSubmission.e2e-spec.ts
Large diffs are not rendered by default.
Oops, something went wrong.
284 changes: 284 additions & 0 deletions
284
...mission/_tests_/e2e/form-submission.institutions.controller.getFormSubmission.e2e-spec.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,284 @@ | ||
| import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
| import * as request from "supertest"; | ||
| import { | ||
| AESTGroups, | ||
| authorizeUserTokenForLocation, | ||
| BEARER_AUTH_TYPE, | ||
| createTestingAppModule, | ||
| getAESTUser, | ||
| getAuthRelatedEntities, | ||
| getInstitutionToken, | ||
| InstitutionTokenTypes, | ||
| } from "../../../../testHelpers"; | ||
| import { | ||
| createE2EDataSources, | ||
| createFakeInstitutionLocation, | ||
| E2EDataSources, | ||
| ensureDynamicFormConfigurationExists, | ||
| saveFakeApplication, | ||
| saveFakeFormSubmissionFromInputTestData, | ||
| } from "@sims/test-utils"; | ||
| import { | ||
| DynamicFormConfiguration, | ||
| FormCategory, | ||
| FormSubmissionDecisionStatus, | ||
| FormSubmissionStatus, | ||
| Institution, | ||
| InstitutionLocation, | ||
| User, | ||
| } from "@sims/sims-db"; | ||
|
|
||
| describe("FormSubmissionInstitutionsController(e2e)-getFormSubmission", () => { | ||
| let app: INestApplication; | ||
| let db: E2EDataSources; | ||
| let collegeF: Institution; | ||
| let collegeFLocation: InstitutionLocation; | ||
| let ministryUser: User; | ||
| let studentAppealApplicationA: DynamicFormConfiguration; | ||
| let studentAppealApplicationB: DynamicFormConfiguration; | ||
|
|
||
| beforeAll(async () => { | ||
| const { nestApplication, dataSource } = await createTestingAppModule(); | ||
| app = nestApplication; | ||
| db = createE2EDataSources(dataSource); | ||
| ministryUser = await getAESTUser( | ||
| db.dataSource, | ||
| AESTGroups.BusinessAdministrators, | ||
| ); | ||
| // College F. | ||
| const { institution } = await getAuthRelatedEntities( | ||
| db.dataSource, | ||
| InstitutionTokenTypes.CollegeFUser, | ||
| ); | ||
| collegeF = institution; | ||
| collegeFLocation = createFakeInstitutionLocation({ institution: collegeF }); | ||
| await authorizeUserTokenForLocation( | ||
| db.dataSource, | ||
| InstitutionTokenTypes.CollegeFUser, | ||
| collegeFLocation, | ||
| ); | ||
| // Create the form configurations to be used along the tests. | ||
| [studentAppealApplicationA, studentAppealApplicationB] = await Promise.all([ | ||
| ensureDynamicFormConfigurationExists(db, "Student application appeal A", { | ||
| formCategory: FormCategory.StudentAppeal, | ||
| }), | ||
| ensureDynamicFormConfigurationExists(db, "Student application appeal B", { | ||
| formCategory: FormCategory.StudentAppeal, | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| it("Should get a form submission as pending and its decisions as pending when the final decision is not yet made and there is an approved and a pending decision (no decision set).", async () => { | ||
| // Arrange | ||
| const application = await saveFakeApplication(db.dataSource, { | ||
| institutionLocation: collegeFLocation, | ||
| }); | ||
| const formSubmission = await saveFakeFormSubmissionFromInputTestData(db, { | ||
| application, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| submissionStatus: FormSubmissionStatus.Pending, | ||
| auditUser: ministryUser, | ||
| formSubmissionItems: [ | ||
| { | ||
| // Should be Pending as the final decision was not yet made. | ||
| dynamicFormConfiguration: studentAppealApplicationA, | ||
| decisions: [ | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Approved, | ||
| }, | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Pending, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| // Should be pending as it has no decision. | ||
| dynamicFormConfiguration: studentAppealApplicationB, | ||
| decisions: [], | ||
| }, | ||
| ], | ||
| }); | ||
| const [formSubmissionItemA, formSubmissionItemB] = | ||
| formSubmission.formSubmissionItems; | ||
| const endpoint = `/institutions/form-submission/student/${formSubmission.student.id}/form-submission/${formSubmission.id}`; | ||
| const studentToken = await getInstitutionToken( | ||
| InstitutionTokenTypes.CollegeFUser, | ||
| ); | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(studentToken, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body).toEqual({ | ||
| id: formSubmission.id, | ||
| applicationId: application.id, | ||
| applicationNumber: application.applicationNumber, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| status: FormSubmissionStatus.Pending, | ||
| submittedDate: formSubmission.submittedDate.toISOString(), | ||
| assessedDate: null, | ||
| submissionItems: [ | ||
| { | ||
| id: formSubmissionItemA.id, | ||
| formType: studentAppealApplicationA.formType, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| dynamicFormConfigurationId: studentAppealApplicationA.id, | ||
| submissionData: formSubmissionItemA.submittedData, | ||
| formDefinitionName: studentAppealApplicationA.formDefinitionName, | ||
| currentDecision: { | ||
| decisionStatus: FormSubmissionDecisionStatus.Pending, | ||
| }, | ||
| }, | ||
| { | ||
| id: formSubmissionItemB.id, | ||
| formType: studentAppealApplicationB.formType, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| dynamicFormConfigurationId: studentAppealApplicationB.id, | ||
| submissionData: formSubmissionItemB.submittedData, | ||
| formDefinitionName: studentAppealApplicationB.formDefinitionName, | ||
| currentDecision: { | ||
| decisionStatus: FormSubmissionDecisionStatus.Pending, | ||
| }, | ||
| }, | ||
| ], | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("Should get a form submission as completed and its decision statuses, including the decision notes, when form submission is completed.", async () => { | ||
| // Arrange | ||
| const application = await saveFakeApplication(db.dataSource, { | ||
| institutionLocation: collegeFLocation, | ||
| }); | ||
| const formSubmission = await saveFakeFormSubmissionFromInputTestData(db, { | ||
| application, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| submissionStatus: FormSubmissionStatus.Completed, | ||
| auditUser: ministryUser, | ||
| formSubmissionItems: [ | ||
| { | ||
| dynamicFormConfiguration: studentAppealApplicationA, | ||
| decisions: [ | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Approved, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| dynamicFormConfiguration: studentAppealApplicationB, | ||
| decisions: [ | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Declined, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| const [formSubmissionItemA, formSubmissionItemB] = | ||
| formSubmission.formSubmissionItems; | ||
| const [itemADecision1] = formSubmissionItemA.decisions; | ||
| const [itemBDecision1] = formSubmissionItemB.decisions; | ||
| const endpoint = `/institutions/form-submission/student/${formSubmission.student.id}/form-submission/${formSubmission.id}`; | ||
| const studentToken = await getInstitutionToken( | ||
| InstitutionTokenTypes.CollegeFUser, | ||
| ); | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(studentToken, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body).toEqual({ | ||
| id: formSubmission.id, | ||
| applicationId: application.id, | ||
| applicationNumber: application.applicationNumber, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| status: FormSubmissionStatus.Completed, | ||
| submittedDate: formSubmission.submittedDate.toISOString(), | ||
| assessedDate: formSubmission.assessedDate.toISOString(), | ||
| submissionItems: [ | ||
| { | ||
| id: formSubmissionItemA.id, | ||
| formType: studentAppealApplicationA.formType, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| dynamicFormConfigurationId: studentAppealApplicationA.id, | ||
| submissionData: formSubmissionItemA.submittedData, | ||
| formDefinitionName: studentAppealApplicationA.formDefinitionName, | ||
| currentDecision: { | ||
| decisionStatus: FormSubmissionDecisionStatus.Approved, | ||
| decisionNoteDescription: | ||
| itemADecision1.decisionNote.description, | ||
| }, | ||
| }, | ||
| { | ||
| id: formSubmissionItemB.id, | ||
| formType: studentAppealApplicationB.formType, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| dynamicFormConfigurationId: studentAppealApplicationB.id, | ||
| submissionData: formSubmissionItemB.submittedData, | ||
| formDefinitionName: studentAppealApplicationB.formDefinitionName, | ||
| currentDecision: { | ||
| decisionStatus: FormSubmissionDecisionStatus.Declined, | ||
| decisionNoteDescription: | ||
| itemBDecision1.decisionNote.description, | ||
| }, | ||
| }, | ||
| ], | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("Should throw a not found exception when the form submission ID exists for the student but the user does not have access to the location.", async () => { | ||
| // Arrange | ||
| const collegeFAlternativeLocation = createFakeInstitutionLocation({ | ||
| institution: collegeF, | ||
| }); | ||
| const application = await saveFakeApplication(db.dataSource, { | ||
| institutionLocation: collegeFAlternativeLocation, | ||
| }); | ||
| const formSubmission = await saveFakeFormSubmissionFromInputTestData(db, { | ||
| application, | ||
| formCategory: FormCategory.StudentAppeal, | ||
| submissionStatus: FormSubmissionStatus.Completed, | ||
| auditUser: ministryUser, | ||
| formSubmissionItems: [ | ||
| { | ||
| dynamicFormConfiguration: studentAppealApplicationA, | ||
| decisions: [ | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Approved, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| dynamicFormConfiguration: studentAppealApplicationB, | ||
| decisions: [ | ||
| { | ||
| decisionStatus: FormSubmissionDecisionStatus.Declined, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
| const endpoint = `/institutions/form-submission/student/${formSubmission.student.id}/form-submission/${formSubmission.id}`; | ||
| const token = await getInstitutionToken(InstitutionTokenTypes.CollegeFUser); | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.NOT_FOUND) | ||
| .expect({ | ||
| message: `Form submission with ID ${formSubmission.id} not found.`, | ||
| error: "Not Found", | ||
| statusCode: HttpStatus.NOT_FOUND, | ||
| }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await app?.close(); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is as good as
const application = await saveFakeApplication(db.dataSource);for the test and alternative location is not required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would work, but the idea was to have a location under the same institution being used for the other for the same scenario.