Skip to content

#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
merged 11 commits into from
Mar 27, 2023
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(
Copy link
Contributor

@ann-aot ann-aot Mar 24, 2023

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?

Copy link
Collaborator Author

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 mentioned createFake 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.

Copy link
Collaborator Author

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)

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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application can be passed here itself right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only scholastic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 () => {
// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full stop

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add the period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Period added.

const approvedAppealRequest = createFakeStudentAppealRequest();
approvedAppealRequest.appealStatus = StudentAppealStatus.Approved;
const approvedAppeal = createFakeStudentAppeal({
application,
appealRequests: [approvedAppealRequest],
});
approvedAppeal.submittedDate = addDays(-1);
// Create declined student appeal from yesterday
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full stop

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add the period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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,
});
});

afterAll(async () => {
await app?.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
getAuthRelatedEntities,
InstitutionTokenTypes,
} from "../../../../testHelpers";
import { createFakeInstitutionLocation } from "@sims/test-utils";
import { saveFakeApplicationCOE } from "@sims/test-utils/factories/confirmation-of-enrollment";
import {
createFakeInstitutionLocation,
saveFakeApplicationDisbursements,
} from "@sims/test-utils";
import {
Application,
ApplicationStatus,
Expand All @@ -19,9 +21,8 @@ import {
InstitutionLocation,
} from "@sims/sims-db";
import { addDays, getISODateOnlyString } from "@sims/utilities";
import { ClientTypeBaseRoute } from "../../../../types";

describe(`${ClientTypeBaseRoute.AEST}-ConfirmationOfEnrollmentInstitutionsController(e2e)-confirmEnrollment`, () => {
describe("ConfirmationOfEnrollmentInstitutionsController(e2e)-confirmEnrollment", () => {
let app: INestApplication;
let appDataSource: DataSource;
let applicationRepo: Repository<Application>;
Expand All @@ -46,7 +47,7 @@ describe(`${ClientTypeBaseRoute.AEST}-ConfirmationOfEnrollmentInstitutionsContro

it("Should allow the COE confirmation when COE is outside the valid COE window.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import {
createFakeDisbursementValue,
createFakeInstitutionLocation,
saveFakeApplicationDisbursements,
} from "@sims/test-utils";
import { saveFakeApplicationCOE } from "@sims/test-utils/factories/confirmation-of-enrollment";
import {
Application,
ApplicationStatus,
Expand All @@ -28,9 +28,8 @@ import {
MONEY_VALUE_FOR_UNKNOWN_MAX_VALUE,
} from "../../../../utilities";
import { addDays, getISODateOnlyString } from "@sims/utilities";
import { ClientTypeBaseRoute } from "../../../../types";

describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitutionsController(e2e)-confirmEnrollment`, () => {
describe("ConfirmationOfEnrollmentInstitutionsController(e2e)-confirmEnrollment", () => {
let app: INestApplication;
let appDataSource: DataSource;
let applicationRepo: Repository<Application>;
Expand Down Expand Up @@ -62,7 +61,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should allow the COE confirmation when the application is on Enrolment status and all the conditions are fulfilled.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down Expand Up @@ -91,7 +90,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should allow the COE confirmation when the application is on Completed status and all the conditions are fulfilled.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down Expand Up @@ -121,7 +120,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should throw NotFoundException when application status is not valid.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down Expand Up @@ -149,7 +148,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should throw UnprocessableEntityException when COE is not within approval window.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down Expand Up @@ -222,7 +221,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should throw an UnprocessableEntityException when trying to confirm the second COE before confirming the first one.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(
const application = await saveFakeApplicationDisbursements(
appDataSource,
{
institution: collegeC,
Expand Down Expand Up @@ -257,7 +256,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should throw an exception when the maxTuitionRemittance if over the limit.", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
disbursementValues: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
createFakeDisbursementOveraward,
createFakeDisbursementValue,
createFakeInstitutionLocation,
saveFakeApplicationDisbursements,
} from "@sims/test-utils";
import { saveFakeApplicationCOE } from "@sims/test-utils/factories/confirmation-of-enrollment";
import { getDateOnlyFormat } from "@sims/utilities";
import { deliveryMethod, getUserFullName } from "../../../../utilities";
import { COEApprovalPeriodStatus } from "../../../../services";
Expand All @@ -26,9 +26,8 @@ import {
Institution,
InstitutionLocation,
} from "@sims/sims-db";
import { ClientTypeBaseRoute } from "../../../../types";

describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitutionsController(e2e)-getApplicationForCOE`, () => {
describe("ConfirmationOfEnrollmentInstitutionsController(e2e)-getApplicationForCOE", () => {
let app: INestApplication;
let appDataSource: DataSource;
let disbursementOverawardRepo: Repository<DisbursementOveraward>;
Expand Down Expand Up @@ -78,7 +77,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should get the COE with calculated maxTuitionRemittanceAllowed when the COE exists under the location", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
disbursementValues: [
Expand Down Expand Up @@ -145,7 +144,7 @@ describe(`${ClientTypeBaseRoute.Institution}-ConfirmationOfEnrollmentInstitution

it("Should return hasOverawardBalance as true when there is an overaward balance on the student account", async () => {
// Arrange
const application = await saveFakeApplicationCOE(appDataSource, {
const application = await saveFakeApplicationDisbursements(appDataSource, {
institution: collegeC,
institutionLocation: collegeCLocation,
});
Expand Down
Loading