-
Notifications
You must be signed in to change notification settings - Fork 14
#5599 - Active SIN Numbers External API #5939
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
+460
−1
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
724e825
Initial changes for SDPR api
tiago-graf f098271
Update query to get last valid SIN
tiago-graf 8b9d6b3
Update endpoint name
tiago-graf 946f39c
Update sources/packages/backend/apps/api/src/route-controllers/studen…
tiago-graf e303724
Update student-information.service.ts
tiago-graf 526c5b4
Update student.external.controller.ts
tiago-graf de10835
Comments updated
tiago-graf 23897f8
Update student.external.controller.getActiveSINs.e2e-spec.ts
tiago-graf 52c9db3
Update SIN query
tiago-graf a66944d
Update student-information.service.ts
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
339 changes: 339 additions & 0 deletions
339
...ute-controllers/student/_tests_/e2e/student.external.controller.getActiveSINs.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,339 @@ | ||
| import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
| import * as request from "supertest"; | ||
| import { | ||
| createE2EDataSources, | ||
| createFakeSFASApplication, | ||
| createFakeSFASApplicationDisbursement, | ||
| createFakeSINValidation, | ||
| E2EDataSources, | ||
| saveFakeApplicationDisbursements, | ||
| saveFakeSFASIndividual, | ||
| saveFakeStudent, | ||
| } from "@sims/test-utils"; | ||
| import { | ||
| ApplicationStatus, | ||
| DisbursementScheduleStatus, | ||
| OfferingIntensity, | ||
| } from "@sims/sims-db"; | ||
| import { | ||
| createTestingAppModule, | ||
| BEARER_AUTH_TYPE, | ||
| getExternalUserToken, | ||
| } from "../../../../testHelpers"; | ||
| import { addDays, getISODateOnlyString } from "@sims/utilities"; | ||
|
|
||
| describe("StudentExternalController(e2e)-getActiveSINs", () => { | ||
| let app: INestApplication; | ||
| let db: E2EDataSources; | ||
| const endpoint = "/external/student/active-sins"; | ||
|
|
||
| beforeAll(async () => { | ||
| const { nestApplication, dataSource } = await createTestingAppModule(); | ||
| app = nestApplication; | ||
| db = createE2EDataSources(dataSource); | ||
| }); | ||
|
|
||
| it("Should include SIMS student SIN when student has a FT application with start date between now and 90 days in the future and no cancelled status.", async () => { | ||
| // Arrange | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| // Create a FT application with a study start date 45 days in the future. | ||
| await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| offeringInitialValues: { | ||
| studyStartDate: getISODateOnlyString(addDays(45)), | ||
| studyEndDate: getISODateOnlyString(addDays(120)), | ||
| }, | ||
| }, | ||
| ); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body.sins).toEqual( | ||
| expect.arrayContaining([student.sinValidation.sin]), | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| it("Should include SIMS student SIN when student has a FT application currently within the study period and no cancelled status.", async () => { | ||
| // Arrange | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| // Create a FT application with a study start date in the past and end date in the future. | ||
| await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| }, | ||
| ); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body.sins).toEqual( | ||
| expect.arrayContaining([student.sinValidation.sin]), | ||
| ), | ||
| ); | ||
| }); | ||
| it("Should include SIMS student SIN when student has a FT application with a disbursement sent in the last 90 days and no cancelled status.", async () => { | ||
| // Arrange | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| // Create a FT application with a disbursement sent 60 days ago. | ||
| const application = await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| offeringInitialValues: { | ||
| studyStartDate: getISODateOnlyString(addDays(-120)), | ||
| studyEndDate: getISODateOnlyString(addDays(-60)), | ||
| }, | ||
| // Set the disbursement as Sent with dateSent within the last 90 days. | ||
| firstDisbursementInitialValues: { | ||
| disbursementScheduleStatus: DisbursementScheduleStatus.Sent, | ||
| dateSent: addDays(-60), | ||
| }, | ||
| }, | ||
| ); | ||
| const [disbursement] = application.currentAssessment.disbursementSchedules; | ||
| await db.disbursementSchedule.save(disbursement); | ||
| const token = await getExternalUserToken(); | ||
| // Act | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body.sins).toEqual( | ||
| expect.arrayContaining([student.sinValidation.sin]), | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| it("Should not include SIMS student SIN when student has only a cancelled FT application that would otherwise match the study start date criteria.", async () => { | ||
| // Arrange | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| // Create a cancelled FT application with a study start date 45 days in the future. | ||
| await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| applicationStatus: ApplicationStatus.Cancelled, | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| offeringInitialValues: { | ||
| studyStartDate: getISODateOnlyString(addDays(45)), | ||
| studyEndDate: getISODateOnlyString(addDays(120)), | ||
| }, | ||
| }, | ||
| ); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => | ||
| expect(body.sins).not.toContain(student.sinValidation.sin), | ||
| ); | ||
| }); | ||
|
|
||
| it("Should return only the most recent valid SIMS student SIN when a student has multiple valid SIN records.", async () => { | ||
| // Arrange | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| const olderValidSIN = student.sinValidation.sin; | ||
| // Create a newer SIN validation with a different SIN also marked as valid. | ||
| const newerSINValidation = createFakeSINValidation( | ||
| { student }, | ||
| { initialValue: { isValidSIN: true } }, | ||
| ); | ||
| // Update the student to point to the newer SIN validation as the current one. | ||
| student.sinValidation = newerSINValidation; | ||
| await db.student.save(student); | ||
| // Create a FT application with a study start date 45 days in the future. | ||
| await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| offeringInitialValues: { | ||
| studyStartDate: getISODateOnlyString(addDays(45)), | ||
| studyEndDate: getISODateOnlyString(addDays(120)), | ||
| }, | ||
| }, | ||
| ); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).toContain(newerSINValidation.sin); | ||
| expect(body.sins).not.toContain(olderValidSIN); | ||
| }); | ||
| }); | ||
|
|
||
| it("Should include SFAS student SIN when student has a FT application with start date between now and 90 days in the future and no cancelled status.", async () => { | ||
| // Arrange | ||
| const individual = await saveFakeSFASIndividual(db.dataSource); | ||
| const sfasApplication = createFakeSFASApplication( | ||
| { individual }, | ||
| { | ||
| initialValues: { | ||
| startDate: getISODateOnlyString(addDays(45)), | ||
| endDate: getISODateOnlyString(addDays(120)), | ||
| applicationCancelDate: null, | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplication.save(sfasApplication); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).toContain(individual.sin); | ||
| }); | ||
| }); | ||
|
|
||
| it("Should include SFAS student SIN when student has a FT application currently within the study period and no cancelled status.", async () => { | ||
| // Arrange | ||
| const individual = await saveFakeSFASIndividual(db.dataSource); | ||
| const sfasApplication = createFakeSFASApplication( | ||
| { individual }, | ||
| { | ||
| initialValues: { | ||
| startDate: getISODateOnlyString(addDays(-30)), | ||
| endDate: getISODateOnlyString(addDays(30)), | ||
| applicationCancelDate: null, | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplication.save(sfasApplication); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).toContain(individual.sin); | ||
| }); | ||
| }); | ||
| it("Should include SFAS student SIN when student has a FT application with disbursement date issued in the last 90 days and no cancelled status.", async () => { | ||
| // Arrange | ||
| const individual = await saveFakeSFASIndividual(db.dataSource); | ||
| // Create a SFAS application with a past study period. | ||
| const sfasApplication = createFakeSFASApplication( | ||
| { individual }, | ||
| { | ||
| initialValues: { | ||
| startDate: getISODateOnlyString(addDays(-120)), | ||
| endDate: getISODateOnlyString(addDays(-60)), | ||
| applicationCancelDate: null, | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplication.save(sfasApplication); | ||
| // Create a disbursement with dateIssued within the last 90 days. | ||
| const disbursement = createFakeSFASApplicationDisbursement( | ||
| { sfasApplication }, | ||
| { | ||
| initialValues: { | ||
| dateIssued: getISODateOnlyString(addDays(-60)), | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplicationDisbursement.save(disbursement); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).toContain(individual.sin); | ||
| }); | ||
| }); | ||
|
|
||
| it("Should not include SFAS student SIN when student has only a cancelled FT application that would otherwise match the study start date criteria.", async () => { | ||
| // Arrange | ||
| const individual = await saveFakeSFASIndividual(db.dataSource); | ||
| // Create a cancelled SFAS application with a start date in the next 90 days. | ||
| const sfasApplication = createFakeSFASApplication( | ||
| { individual }, | ||
| { | ||
| initialValues: { | ||
| startDate: getISODateOnlyString(addDays(45)), | ||
| endDate: getISODateOnlyString(addDays(120)), | ||
| applicationCancelDate: getISODateOnlyString(addDays(-5)), | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplication.save(sfasApplication); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).not.toContain(individual.sin); | ||
| }); | ||
| }); | ||
|
|
||
| it("Should include both a SIMS and a SFAS student SIN when each has a qualifying FT application with start date between now and 90 days in the future.", async () => { | ||
| // Arrange | ||
| // Create a SIMS student with a FT application starting 45 days in the future. | ||
| const student = await saveFakeStudent(db.dataSource); | ||
| await saveFakeApplicationDisbursements( | ||
| db.dataSource, | ||
| { student }, | ||
| { | ||
| offeringIntensity: OfferingIntensity.fullTime, | ||
| offeringInitialValues: { | ||
| studyStartDate: getISODateOnlyString(addDays(45)), | ||
| studyEndDate: getISODateOnlyString(addDays(120)), | ||
| }, | ||
| }, | ||
| ); | ||
| // Create a SFAS individual with a FT application starting 45 days in the future. | ||
| const individual = await saveFakeSFASIndividual(db.dataSource); | ||
| const sfasApplication = createFakeSFASApplication( | ||
| { individual }, | ||
| { | ||
| initialValues: { | ||
| startDate: getISODateOnlyString(addDays(45)), | ||
| endDate: getISODateOnlyString(addDays(120)), | ||
| applicationCancelDate: null, | ||
| }, | ||
| }, | ||
| ); | ||
| await db.sfasApplication.save(sfasApplication); | ||
| const token = await getExternalUserToken(); | ||
| // Act/Assert | ||
| await request(app.getHttpServer()) | ||
| .get(endpoint) | ||
| .auth(token, BEARER_AUTH_TYPE) | ||
| .expect(HttpStatus.OK) | ||
| .expect(({ body }) => { | ||
| expect(body.sins).toContain(student.sinValidation.sin); | ||
| expect(body.sins).toContain(individual.sin); | ||
| }); | ||
| }); | ||
|
|
||
| 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.