Skip to content
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

#4041 - Ignore Cancelled Legacy Applications on SIMS Validations and Calculations #4042

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SystemUsersService } from "@sims/services";
import { FormNames, FormService } from "../../../services";
import { AppStudentsModule } from "../../../app.students.module";
import { createFakeSFASPartTimeApplication } from "@sims/test-utils/factories/sfas-part-time-application";
import { createFakeSFASApplication } from "@sims/test-utils/factories/sfas-application";

describe("ApplicationStudentsController(e2e)-submitApplication", () => {
let app: INestApplication;
Expand Down Expand Up @@ -154,7 +155,7 @@ describe("ApplicationStudentsController(e2e)-submitApplication", () => {
});
});

it("Should throw study dates overlap error when an application submitted for a student via the SFAS system has overlapping study start or study end dates with another application.", async () => {
it("Should throw study dates overlap error when a part-time application submitted for a student via the SFAS system has overlapping study start or study end dates with another application.", async () => {
// Arrange
const student = await saveFakeStudent(db.dataSource);
const sfasIndividual = await saveFakeSFASIndividual(db.dataSource, {
Expand Down Expand Up @@ -251,6 +252,99 @@ describe("ApplicationStudentsController(e2e)-submitApplication", () => {
});
});

it("Should throw study dates overlap error when a full-time application is submitted for a student via the SFAS system has overlapping study start or study end dates with another application.", async () => {
// Arrange
const student = await saveFakeStudent(db.dataSource);
const sfasIndividual = await saveFakeSFASIndividual(db.dataSource, {
initialValues: {
lastName: student.user.lastName,
birthDate: student.birthDate,
sin: student.sinValidation.sin,
},
});

const sfasFullTimeApplication = createFakeSFASApplication(
{ individual: sfasIndividual },
{
initialValues: {
startDate: getISODateOnlyString(new Date()),
endDate: getISODateOnlyString(addDays(50)),
},
},
);
await db.sfasApplication.save(sfasFullTimeApplication);
// Create a fake offering for the second application.
const auditUser = await db.user.save(createFakeUser());

// SIMS Offering having overlapping study period with SFAS.
const simsApplicationOfferingInitialValues = {
studyStartDate: getISODateOnlyString(addDays(40)),
studyEndDate: getISODateOnlyString(addDays(90)),
offeringIntensity: OfferingIntensity.partTime,
};
const fakeOffering = createFakeEducationProgramOffering(
{
auditUser,
},
{
initialValues: simsApplicationOfferingInitialValues,
},
);
const savedOffering = await db.educationProgramOffering.save(fakeOffering);
const simsApplication = createFakeApplication(
{
student,
location: fakeOffering.institutionLocation,
},
{
initialValue: {
data: {},
applicationStatus: ApplicationStatus.Draft,
applicationStatusUpdatedOn: new Date(),
creator: systemUsersService.systemUser,
createdAt: new Date(),
} as Application,
},
);
const secondDraftApplication = await db.application.save(simsApplication);
const applicationData = {
selectedOfferingDate: simsApplicationOfferingInitialValues.studyStartDate,
selectedOfferingEndDate:
simsApplicationOfferingInitialValues.studyEndDate,
howWillYouBeAttendingTheProgram:
simsApplicationOfferingInitialValues.offeringIntensity,
selectedProgram: savedOffering.educationProgram.id,
selectedOffering: savedOffering.id,
};
const payload = {
associatedFiles: [],
data: applicationData,
programYearId: simsApplication.programYear.id,
} as SaveApplicationAPIInDTO;
const endpoint = `/students/application/${secondDraftApplication.id}/submit`;
const token = await getStudentToken(
FakeStudentUsersTypes.FakeStudentUserType1,
);
const dryRunSubmissionMock = jest.fn().mockResolvedValue({
valid: true,
formName: FormNames.Application,
data: { data: applicationData },
});
formService.dryRunSubmission = dryRunSubmissionMock;
await mockUserLoginInfo(appModule, student);
// Act/Assert
await request(app.getHttpServer())
.patch(endpoint)
.send(payload)
.auth(token, BEARER_AUTH_TYPE)
.expect(HttpStatus.UNPROCESSABLE_ENTITY)
.expect({
message:
"There is an existing application already with overlapping study period or a pending PIR.",
errorType: "STUDY_DATE_OVERLAP_ERROR",
});
});

it("Should submit an application for a student when the application study dates do not have any overlap with the study dates of any existing application.", async () => {
// Arrange
const student = await saveFakeStudent(db.dataSource);
Expand Down Expand Up @@ -341,6 +435,104 @@ describe("ApplicationStudentsController(e2e)-submitApplication", () => {
.expect({});
});

it(
"Should submit an application for a student when there is a cancelled full-time application in SFAS with overlapping study dates" +
" ignoring the cancelled SFAS application.",
async () => {
// Arrange
const student = await saveFakeStudent(db.dataSource);
const sfasIndividual = await saveFakeSFASIndividual(db.dataSource, {
initialValues: {
lastName: student.user.lastName,
birthDate: student.birthDate,
sin: student.sinValidation.sin,
},
});
// Cancelled SFAS full time application with overlapping study dates.
const sfasFullTimeApplication = createFakeSFASApplication(
{ individual: sfasIndividual },
{
initialValues: {
startDate: getISODateOnlyString(new Date()),
endDate: getISODateOnlyString(addDays(50)),
// The SFAS application is cancelled.
applicationCancelDate: getISODateOnlyString(new Date()),
},
},
);
await db.sfasApplication.save(sfasFullTimeApplication);

// SIMS Offering having overlapping study period with SFAS.
const simsApplicationOfferingInitialValues = {
studyStartDate: getISODateOnlyString(addDays(30)),
studyEndDate: getISODateOnlyString(addDays(90)),
offeringIntensity: OfferingIntensity.partTime,
};
const simsApplication = createFakeApplication(
{
student,
},
{
initialValue: {
data: {},
applicationStatus: ApplicationStatus.Draft,
applicationStatusUpdatedOn: new Date(),
creator: systemUsersService.systemUser,
createdAt: new Date(),
} as Application,
},
);
const simsDraftApplication = await db.application.save(simsApplication);
const auditUser = await db.user.save(createFakeUser());
const simsApplicationOffering = await db.educationProgramOffering.save(
createFakeEducationProgramOffering(
{
auditUser,
institutionLocation: simsApplication.location,
},
{
initialValues: simsApplicationOfferingInitialValues,
},
),
);
const secondApplicationProgram = simsApplicationOffering.educationProgram;
const applicationData = {
selectedOfferingDate:
simsApplicationOfferingInitialValues.studyStartDate,
selectedOfferingEndDate:
simsApplicationOfferingInitialValues.studyEndDate,
howWillYouBeAttendingTheProgram:
simsApplicationOfferingInitialValues.offeringIntensity,
selectedProgram: secondApplicationProgram.id,
selectedOffering: simsApplicationOffering.id,
selectedLocation: simsApplication.location.id,
};
const payload = {
associatedFiles: [],
data: applicationData,
programYearId: simsApplication.programYear.id,
} as SaveApplicationAPIInDTO;
const endpoint = `/students/application/${simsDraftApplication.id}/submit`;
const token = await getStudentToken(
FakeStudentUsersTypes.FakeStudentUserType1,
);
const dryRunSubmissionMock = jest.fn().mockResolvedValue({
valid: true,
formName: FormNames.Application,
data: { data: applicationData },
});
formService.dryRunSubmission = dryRunSubmissionMock;
await mockUserLoginInfo(appModule, student);
// Act/Assert
await request(app.getHttpServer())
.patch(endpoint)
.send(payload)
.auth(token, BEARER_AUTH_TYPE)
.expect(HttpStatus.OK)
.expect({});
},
);

afterAll(async () => {
await app?.close();
});
Expand Down
Loading
Loading