-
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
Merged
andrewsignori-aot
merged 11 commits into
main
from
feature/#1683-application-tracker-e2e-tests
Mar 27, 2023
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e548084
First E2E tests for getCompletedApplicationDetails
andrewsignori-aot 955e60f
Sonarcloud fixes
andrewsignori-aot ec313af
Progress bar adjustments
andrewsignori-aot bc25e6b
Comments improvements
andrewsignori-aot f7745a0
Made statusType optional
andrewsignori-aot 185d1c7
PR comments
andrewsignori-aot 7816d39
PR comments fixes
andrewsignori-aot 1b95d89
PR comments fixes.
andrewsignori-aot b4f3a17
Changed saveFakeApplicationDisbursements
andrewsignori-aot 63d1b58
PR comments
andrewsignori-aot 9d9267b
STATUS_ICON_* refactor
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
233 changes: 233 additions & 0 deletions
233
...llers/application/_tests_/application.students.getCompletedApplicationDetails.e2e-spec.ts
This file contains 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,233 @@ | ||
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, | ||
Student, | ||
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; | ||
let student: Student; | ||
|
||
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()); | ||
student = await getStudentByFakeStudentUserType( | ||
FakeStudentUsersTypes.FakeStudentUserType1, | ||
dataSource, | ||
); | ||
}); | ||
|
||
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 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 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 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. | ||
// 'Student did not complete program' is the only 'scholastic standing that does not generate an assessment. | ||
// The below record has only a relationship with the application which must be enough to | ||
// have the scholasticStandingChangeType returned. | ||
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, | ||
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 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 submitted yesterday. | ||
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 pending student appeal submitted today. | ||
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(); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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.
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.
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)