-
Notifications
You must be signed in to change notification settings - Fork 14
#5845 - Make institution location code optional #5900
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
16 commits
Select commit
Hold shift + click to select a range
920ca4a
Make location code optional
tiago-graf 1e9b902
Added e2e tests
tiago-graf ea1cfd8
Fix e2e test
tiago-graf 5adcbf0
PR comments
tiago-graf de0af9e
Potential fix for pull request finding
tiago-graf d31d287
Update institution-location.service.ts
tiago-graf 2b5e2b6
Updated institutionCode type
tiago-graf 5c44b04
Update ApproveDenyDesignationModal.vue
tiago-graf fee3664
Update PR Comments
tiago-graf 3d48d1b
Revert changes: institution code mandatory for Ministry
tiago-graf abf9105
Update institution-location.aest.controller.getInstitutionLocation.e2…
tiago-graf 9351c3c
Update institution-location.dto.ts
tiago-graf ebf40fc
Update institution-location.aest.controller.update.e2e-spec.ts
tiago-graf 80790d5
Update institutionlocation.json
tiago-graf 2ed5e43
Update ApproveDenyDesignationModal.vue
tiago-graf 7852a32
Update institutionlocation.json
tiago-graf 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
279 changes: 279 additions & 0 deletions
279
.../_tests_/e2e/designation-agreement.aest.controller.updateDesignationAgreement.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,279 @@ | ||
| import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
| import * as request from "supertest"; | ||
| import { DesignationAgreementStatus, NoteType, User } from "@sims/sims-db"; | ||
| import { | ||
| AESTGroups, | ||
| BEARER_AUTH_TYPE, | ||
| createTestingAppModule, | ||
| getAESTToken, | ||
| getAESTUser, | ||
| } from "../../../../testHelpers"; | ||
| import { | ||
| E2EDataSources, | ||
| createE2EDataSources, | ||
| createFakeDesignationAgreement, | ||
| createFakeInstitution, | ||
| createFakeInstitutionLocation, | ||
| createFakeUser, | ||
| } from "@sims/test-utils"; | ||
|
|
||
| describe("DesignationAgreementAESTController(e2e)-updateDesignationAgreement", () => { | ||
| let app: INestApplication; | ||
| let db: E2EDataSources; | ||
| let fakeUser: User; | ||
|
|
||
| beforeAll(async () => { | ||
| const { nestApplication, dataSource } = await createTestingAppModule(); | ||
| app = nestApplication; | ||
| db = createE2EDataSources(dataSource); | ||
| fakeUser = await db.user.save(createFakeUser()); | ||
| }); | ||
|
|
||
| it("Should approve a designation agreement and persist all fields when all payload locations belong to the institution.", async () => { | ||
| // Arrange | ||
| const institution = await db.institution.save(createFakeInstitution()); | ||
| const fakeLocation = createFakeInstitutionLocation({ institution }); | ||
| const savedLocation = await db.institutionLocation.save(fakeLocation); | ||
| const fakeDesignation = createFakeDesignationAgreement( | ||
| { | ||
| fakeInstitution: institution, | ||
| fakeInstitutionLocations: [savedLocation], | ||
| fakeUser, | ||
| }, | ||
| { | ||
| initialValue: { designationStatus: DesignationAgreementStatus.Pending }, | ||
| }, | ||
| ); | ||
| const savedDesignation = | ||
| await db.designationAgreement.save(fakeDesignation); | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| const endpoint = `/aest/designation-agreement/${savedDesignation.id}`; | ||
|
|
||
| // Act | ||
| await request(app.getHttpServer()) | ||
| .patch(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .send({ | ||
| designationStatus: DesignationAgreementStatus.Approved, | ||
| startDate: "2026-01-01", | ||
| endDate: "2027-12-31", | ||
| locationsDesignations: [ | ||
| { locationId: savedLocation.id, approved: true }, | ||
| ], | ||
| note: "Designation approved.", | ||
| }) | ||
| .expect(HttpStatus.OK); | ||
|
|
||
| // Assert | ||
| const auditUser = await getAESTUser( | ||
| db.dataSource, | ||
| AESTGroups.BusinessAdministrators, | ||
| ); | ||
| const updatedDesignation = await db.designationAgreement.findOne({ | ||
| select: { | ||
| id: true, | ||
| designationStatus: true, | ||
| startDate: true, | ||
| endDate: true, | ||
| designationAgreementLocations: { | ||
| id: true, | ||
| institutionLocation: { id: true }, | ||
| approved: true, | ||
| }, | ||
| institution: { | ||
| id: true, | ||
| notes: { id: true, noteType: true, description: true }, | ||
| }, | ||
| assessedBy: { id: true }, | ||
| assessedDate: true, | ||
| }, | ||
| relations: { | ||
| designationAgreementLocations: { institutionLocation: true }, | ||
| institution: { notes: true }, | ||
| assessedBy: true, | ||
| }, | ||
| where: { id: savedDesignation.id }, | ||
| loadEagerRelations: false, | ||
| }); | ||
| expect(updatedDesignation).toEqual({ | ||
| id: savedDesignation.id, | ||
| designationStatus: DesignationAgreementStatus.Approved, | ||
| startDate: "2026-01-01", | ||
| endDate: "2027-12-31", | ||
| designationAgreementLocations: [ | ||
| { | ||
| id: expect.any(Number), | ||
| institutionLocation: { id: savedLocation.id }, | ||
| approved: true, | ||
| }, | ||
| ], | ||
| institution: { | ||
| id: institution.id, | ||
| notes: [ | ||
| { | ||
| id: expect.any(Number), | ||
| noteType: NoteType.Designation, | ||
| description: "Designation approved.", | ||
| }, | ||
| ], | ||
| }, | ||
| assessedBy: { id: auditUser.id }, | ||
| assessedDate: expect.any(Date), | ||
| }); | ||
| }); | ||
|
|
||
| it("Should decline a designation agreement.", async () => { | ||
| // Arrange | ||
| const institution = await db.institution.save(createFakeInstitution()); | ||
| const fakeLocation = createFakeInstitutionLocation({ institution }); | ||
| const savedLocation = await db.institutionLocation.save(fakeLocation); | ||
| const fakeDesignation = createFakeDesignationAgreement( | ||
| { | ||
| fakeInstitution: institution, | ||
| fakeInstitutionLocations: [savedLocation], | ||
| fakeUser, | ||
| }, | ||
| { | ||
| initialValue: { designationStatus: DesignationAgreementStatus.Pending }, | ||
| }, | ||
| ); | ||
| const savedDesignation = | ||
| await db.designationAgreement.save(fakeDesignation); | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| const endpoint = `/aest/designation-agreement/${savedDesignation.id}`; | ||
|
|
||
| // Act | ||
| await request(app.getHttpServer()) | ||
| .patch(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .send({ | ||
| designationStatus: DesignationAgreementStatus.Declined, | ||
| note: "Designation declined.", | ||
| }) | ||
| .expect(HttpStatus.OK); | ||
|
|
||
| // Assert | ||
| const updatedDesignation = await db.designationAgreement.findOneBy({ | ||
| id: savedDesignation.id, | ||
| }); | ||
| expect(updatedDesignation.designationStatus).toBe( | ||
| DesignationAgreementStatus.Declined, | ||
| ); | ||
| }); | ||
|
|
||
| it("Should return not found when the designation agreement does not exist.", async () => { | ||
| // Arrange | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| const endpoint = `/aest/designation-agreement/99999999`; | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .patch(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .send({ | ||
| designationStatus: DesignationAgreementStatus.Declined, | ||
| note: "Some note.", | ||
| }) | ||
| .expect(HttpStatus.NOT_FOUND) | ||
| .expect({ | ||
| statusCode: HttpStatus.NOT_FOUND, | ||
| message: | ||
| "Designation agreement not found or it has been declined already.", | ||
| error: "Not Found", | ||
| }); | ||
| }); | ||
|
|
||
| it("Should return unprocessable entity when approved location does not belong to the designation institution.", async () => { | ||
| // Arrange | ||
| const institution = await db.institution.save(createFakeInstitution()); | ||
| const fakeLocation = createFakeInstitutionLocation({ institution }); | ||
| const savedLocation = await db.institutionLocation.save(fakeLocation); | ||
| const fakeDesignation = createFakeDesignationAgreement( | ||
| { | ||
| fakeInstitution: institution, | ||
| fakeInstitutionLocations: [savedLocation], | ||
| fakeUser, | ||
| }, | ||
| { | ||
| initialValue: { designationStatus: DesignationAgreementStatus.Pending }, | ||
| }, | ||
| ); | ||
| const savedDesignation = | ||
| await db.designationAgreement.save(fakeDesignation); | ||
| // Create a location that belongs to a different institution. | ||
| const unrelatedLocation = await db.institutionLocation.save( | ||
| createFakeInstitutionLocation(), | ||
| ); | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| const endpoint = `/aest/designation-agreement/${savedDesignation.id}`; | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .patch(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .send({ | ||
| designationStatus: DesignationAgreementStatus.Approved, | ||
| startDate: "2026-01-01", | ||
| endDate: "2027-12-31", | ||
| locationsDesignations: [ | ||
| { locationId: unrelatedLocation.id, approved: true }, | ||
| ], | ||
| note: "Attempt with unrelated location.", | ||
| }) | ||
| .expect(HttpStatus.UNPROCESSABLE_ENTITY) | ||
| .expect({ | ||
| message: | ||
| "One or more locations provided do not belong to designation institution.", | ||
| error: "Unprocessable Entity", | ||
| statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
| }); | ||
| }); | ||
|
|
||
| it("Should return unprocessable entity when an approved location is missing an institution location code.", async () => { | ||
| // Arrange | ||
| const institution = await db.institution.save(createFakeInstitution()); | ||
| // Create a location without an institution code to simulate locations | ||
| // submitted with the "I do not have an institution location code" option selected. | ||
| const fakeLocation = createFakeInstitutionLocation({ institution }); | ||
| fakeLocation.institutionCode = undefined; | ||
| const savedLocation = await db.institutionLocation.save(fakeLocation); | ||
| const fakeDesignation = createFakeDesignationAgreement( | ||
| { | ||
| fakeInstitution: institution, | ||
| fakeInstitutionLocations: [savedLocation], | ||
| fakeUser, | ||
| }, | ||
| { | ||
| initialValue: { designationStatus: DesignationAgreementStatus.Pending }, | ||
| }, | ||
| ); | ||
| const savedDesignation = | ||
| await db.designationAgreement.save(fakeDesignation); | ||
| const token = await getAESTToken(AESTGroups.BusinessAdministrators); | ||
| const endpoint = `/aest/designation-agreement/${savedDesignation.id}`; | ||
|
|
||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .patch(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .send({ | ||
| designationStatus: DesignationAgreementStatus.Approved, | ||
| startDate: "2026-01-01", | ||
| endDate: "2027-12-31", | ||
| locationsDesignations: [ | ||
| { locationId: savedLocation.id, approved: true }, | ||
| ], | ||
| note: "Attempt to approve location without code.", | ||
| }) | ||
| .expect(HttpStatus.UNPROCESSABLE_ENTITY) | ||
| .expect({ | ||
| message: | ||
dheepak-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "One or more approved locations are missing an institution location code.", | ||
| error: "Unprocessable Entity", | ||
| statusCode: HttpStatus.UNPROCESSABLE_ENTITY, | ||
| }); | ||
| }); | ||
| afterAll(async () => { | ||
| await app?.close(); | ||
| }); | ||
| }); | ||
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.