-
Notifications
You must be signed in to change notification settings - Fork 14
#1683 - Completed application - E2E tests for application tracker #1832
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
Changes from 3 commits
e548084
955e60f
ec313af
bc25e6b
f7745a0
185d1c7
7816d39
1b95d89
b4f3a17
63d1b58
9d9267b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
import { HttpStatus, INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { DataSource, Repository } from "typeorm"; | ||
import { | ||
BEARER_AUTH_TYPE, | ||
createTestingAppModule, | ||
FakeStudentUsersTypes, | ||
getStudentToken, | ||
getStudentByFakeStudentUserType, | ||
} from "../../../testHelpers"; | ||
import { | ||
createFakeStudentAppeal, | ||
createFakeStudentAppealRequest, | ||
createFakeStudentScholasticStanding, | ||
createFakeUser, | ||
saveFakeApplicationDisbursements, | ||
} from "@sims/test-utils"; | ||
import { | ||
Application, | ||
ApplicationStatus, | ||
COEStatus, | ||
DisbursementSchedule, | ||
StudentAppeal, | ||
StudentAppealStatus, | ||
StudentScholasticStanding, | ||
StudentScholasticStandingChangeType, | ||
User, | ||
} from "@sims/sims-db"; | ||
import { addDays } from "@sims/utilities"; | ||
|
||
describe("ApplicationStudentsController(e2e)-getCompletedApplicationDetails", () => { | ||
let app: INestApplication; | ||
let appDataSource: DataSource; | ||
let applicationRepo: Repository<Application>; | ||
let disbursementScheduleRepo: Repository<DisbursementSchedule>; | ||
let studentScholasticStandingRepo: Repository<StudentScholasticStanding>; | ||
let studentAppealRepo: Repository<StudentAppeal>; | ||
let submittedByInstitutionUser: User; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
appDataSource = dataSource; | ||
const userRepo = dataSource.getRepository(User); | ||
applicationRepo = dataSource.getRepository(Application); | ||
disbursementScheduleRepo = dataSource.getRepository(DisbursementSchedule); | ||
studentScholasticStandingRepo = dataSource.getRepository( | ||
StudentScholasticStanding, | ||
); | ||
studentAppealRepo = dataSource.getRepository(StudentAppeal); | ||
submittedByInstitutionUser = await userRepo.save(createFakeUser()); | ||
}); | ||
|
||
it("Should throw NotFoundException when the application is not associated with the authenticated student.", async () => { | ||
// Arrange | ||
// The application will be generated with a fake user. | ||
const application = await saveFakeApplicationDisbursements(appDataSource); | ||
const endpoint = `/students/application/${application.id}/completed`; | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: 404, | ||
message: "Application not found or not on Completed status.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
it("Should throw NotFoundException when the application is not in 'Completed' status.", async () => { | ||
// Arrange | ||
const student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
appDataSource, | ||
); | ||
const application = await saveFakeApplicationDisbursements( | ||
appDataSource, | ||
{ student }, | ||
{ createSecondDisbursement: true }, | ||
); | ||
const endpoint = `/students/application/${application.id}/completed`; | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.NOT_FOUND) | ||
.expect({ | ||
statusCode: 404, | ||
message: "Application not found or not on Completed status.", | ||
error: "Not Found", | ||
}); | ||
}); | ||
|
||
it("Should get application details when application is in 'Completed' status.", async () => { | ||
// Arrange | ||
const student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
appDataSource, | ||
); | ||
const application = await saveFakeApplicationDisbursements( | ||
appDataSource, | ||
{ student }, | ||
{ createSecondDisbursement: true }, | ||
); | ||
application.applicationStatus = ApplicationStatus.Completed; | ||
await applicationRepo.save(application); | ||
const [firstDisbursement, secondDisbursement] = | ||
application.currentAssessment.disbursementSchedules; | ||
firstDisbursement.coeStatus = COEStatus.completed; | ||
await disbursementScheduleRepo.save(firstDisbursement); | ||
const endpoint = `/students/application/${application.id}/completed`; | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
firstDisbursement: { | ||
coeStatus: firstDisbursement.coeStatus, | ||
disbursementScheduleStatus: | ||
firstDisbursement.disbursementScheduleStatus, | ||
}, | ||
secondDisbursement: { | ||
coeStatus: secondDisbursement.coeStatus, | ||
disbursementScheduleStatus: | ||
secondDisbursement.disbursementScheduleStatus, | ||
}, | ||
assessmentTriggerType: application.currentAssessment.triggerType, | ||
}); | ||
}); | ||
|
||
it(`Should get application details with scholastic standing change type when application has a scholastic standing '${StudentScholasticStandingChangeType.StudentDidNotCompleteProgram} associated with.`, async () => { | ||
// Arrange | ||
const student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
appDataSource, | ||
); | ||
const application = await saveFakeApplicationDisbursements(appDataSource, { | ||
student, | ||
}); | ||
application.applicationStatus = ApplicationStatus.Completed; | ||
await applicationRepo.save(application); | ||
const [firstDisbursement] = | ||
application.currentAssessment.disbursementSchedules; | ||
firstDisbursement.coeStatus = COEStatus.completed; | ||
await disbursementScheduleRepo.save(firstDisbursement); | ||
// Create a scholastic standing and have it associated with the completed application. | ||
const scholasticStanding = createFakeStudentScholasticStanding({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
submittedBy: submittedByInstitutionUser, | ||
}); | ||
// 'Student did not complete program' is the only'scholastic standing that does not generate an assessment. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
// The below record has only a relationship with the application which must be enough to | ||
// have the scholasticStandingChangeType returned. | ||
scholasticStanding.application = application; | ||
await studentScholasticStandingRepo.save(scholasticStanding); | ||
|
||
const endpoint = `/students/application/${application.id}/completed`; | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
firstDisbursement: { | ||
coeStatus: firstDisbursement.coeStatus, | ||
disbursementScheduleStatus: | ||
firstDisbursement.disbursementScheduleStatus, | ||
}, | ||
assessmentTriggerType: application.currentAssessment.triggerType, | ||
scholasticStandingChangeType: | ||
StudentScholasticStandingChangeType.StudentDidNotCompleteProgram, | ||
}); | ||
}); | ||
|
||
it(`Should get application details with the most updated appeal status when the application has more than one student appeals associated with.`, async () => { | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Arrange | ||
const student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
appDataSource, | ||
); | ||
const application = await saveFakeApplicationDisbursements(appDataSource, { | ||
student, | ||
}); | ||
application.applicationStatus = ApplicationStatus.Completed; | ||
await applicationRepo.save(application); | ||
const [firstDisbursement] = | ||
application.currentAssessment.disbursementSchedules; | ||
firstDisbursement.coeStatus = COEStatus.completed; | ||
await disbursementScheduleRepo.save(firstDisbursement); | ||
// Create approved student appeal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. full stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add the period. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Period added. |
||
const approvedAppealRequest = createFakeStudentAppealRequest(); | ||
approvedAppealRequest.appealStatus = StudentAppealStatus.Approved; | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const approvedAppeal = createFakeStudentAppeal({ | ||
application, | ||
appealRequests: [approvedAppealRequest], | ||
}); | ||
approvedAppeal.submittedDate = addDays(-1); | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Create declined student appeal from yesterday | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. full stop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add the period. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Period added. |
||
const pendingAppealRequest = createFakeStudentAppealRequest(); | ||
pendingAppealRequest.appealStatus = StudentAppealStatus.Pending; | ||
const pendingAppeal = createFakeStudentAppeal({ | ||
application, | ||
appealRequests: [pendingAppealRequest], | ||
}); | ||
await studentAppealRepo.save([approvedAppeal, pendingAppeal]); | ||
|
||
const endpoint = `/students/application/${application.id}/completed`; | ||
const token = await getStudentToken( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
); | ||
// Act/Assert | ||
await request(app.getHttpServer()) | ||
.get(endpoint) | ||
.auth(token, BEARER_AUTH_TYPE) | ||
.expect(HttpStatus.OK) | ||
.expect({ | ||
firstDisbursement: { | ||
coeStatus: firstDisbursement.coeStatus, | ||
disbursementScheduleStatus: | ||
firstDisbursement.disbursementScheduleStatus, | ||
}, | ||
assessmentTriggerType: application.currentAssessment.triggerType, | ||
appealStatus: StudentAppealStatus.Pending, | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app?.close(); | ||
}); | ||
}); |
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.
mm, instead of getting a fake disbursement application and changing the data in the test to make it completed, can't we create a fakecompletedAppliaction? is there any reason for it?
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.
When we need an application with disbursements we will need:
createFakeApplication
,createFakeStudentAssessment
,createFakeDisbursementSchedule
,createFakeEducationProgramOffering
,createFakeUser
,createFakeStudent
, etc., and then have all of them saved properly. When this method was introduced in the past for COE (and now renamed/moved for disbursements), the idea was to concentrate all the complexity of calling the previously mentionedcreateFake
methods and coordinate the way that they must be saved.Does it answer? If not maybe I am not getting the point and we can have a chat. Please let me know.
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.
I guess that the answer is the same from #1832 (comment)