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

#2322 - IER12 E2E Tests - Validate Multiple Files #2478

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -3,6 +3,7 @@ import {
DisbursementSchedule,
DisbursementScheduleStatus,
DisbursementValue,
EducationProgram,
FullTimeAssessment,
InstitutionLocation,
ProgramYear,
Expand All @@ -11,7 +12,6 @@ import {
} from "@sims/sims-db";
import {
E2EDataSources,
createFakeInstitutionLocation,
createFakeStudent,
createFakeUser,
ensureProgramYearExists,
Expand All @@ -36,6 +36,8 @@ import * as faker from "faker";
* will be part of the IER12 file generation.
* @param db data source helper.
* @param testInputData IER12 test input data.
* @param relations IER12 relations:
* - `institutionLocation` related IER12 location.
* @param options method options:
* - `programYearPrefix` program year prefix to create or find the program year to
* be associated. Default 2000, would will create the program year 2000-2001.
Expand All @@ -45,6 +47,9 @@ import * as faker from "faker";
export async function saveIER12TestInputData(
db: E2EDataSources,
testInputData: IER12TestInputData,
relations: {
institutionLocation: InstitutionLocation;
},
options?: {
programYearPrefix?: number;
submittedDate?: Date;
Expand Down Expand Up @@ -78,19 +83,22 @@ export async function saveIER12TestInputData(
db,
testInputData.student,
);
// Location
const institutionLocation = createFakeInstitutionLocation();
institutionLocation.institutionCode = "ZZZY";
institutionLocation.hasIntegration = true;
// Check if a program already exists for the institution to reuse it.
// SABC codes are unique inside for the same institution.
const program = await db.educationProgram.findOneBy({
institution: { id: relations.institutionLocation.institution.id },
sabcCode: testInputData.educationProgram.sabcCode,
});
// Application
const application = await saveIER12ApplicationFromTestInput(
db,
testInputData.application,
student,
institutionLocation,
relations.institutionLocation,
programYear,
createSecondDisbursement,
referenceSubmission,
program,
);
// Assessment and its awards.
const assessment = await saveIER12AssessmentFromTestInput(
Expand Down Expand Up @@ -165,6 +173,7 @@ async function saveIER12StudentFromTestInput(
* @param programYear previously saved program year.
* @param createSecondDisbursement indicates if a second disbursement should be created.
* @param referenceSubmission date when the application was submitted.
* @param program education program that will have the offering created.
* @returns the saved applications and its dependencies.
*/
async function saveIER12ApplicationFromTestInput(
Expand All @@ -175,10 +184,11 @@ async function saveIER12ApplicationFromTestInput(
programYear: ProgramYear,
createSecondDisbursement: boolean,
referenceSubmission: Date,
program?: EducationProgram,
): Promise<Application> {
const application = await saveFakeApplicationDisbursements(
db.dataSource,
{ student, institutionLocation, disbursementValues: [] },
{ student, institutionLocation, program, disbursementValues: [] },
{ createSecondDisbursement },
);
application.applicationNumber = testInputApplication.applicationNumber;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const PROGRAM_UNDERGRADUATE_CERTIFICATE_WITHOUT_INSTITUTION_PROGRAM_CODE:
fieldOfStudyCode: 1,
cipCode: "12.1234",
nocCode: "1234",
sabcCode: "ADR2",
sabcCode: "ADR1",
institutionProgramCode: undefined,
completionYears: "5YearsOrMore",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatDate } from "@sims/utilities";
import { QueueProcessSummaryResult } from "../../../../../../../processors/models/processors.models";

/**
Expand All @@ -14,6 +15,15 @@ export function numberToText(
return value.toString().padStart(options?.length ?? 10, "0");
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this method used anywhere?

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 am not sure if I am following the question. This method was added in the previous PR and it is used in 18 places.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

got it

* Converts a date to its fixed date-only text format.
* @param date date to be converted.
* @returns converted data as a string formatted as YYYYMMDD.
*/
export function dateToDateOnlyText(date: Date | string): string {
return formatDate(date, "YYYYMMDD");
}

/**
* Get the success string messages when a file is uploaded with success.
* @param timestamp file timestamp.
Expand All @@ -25,12 +35,13 @@ export function numberToText(
export function getSuccessSummaryMessages(
timestamp: string,
options?: {
institutionCode?: string;
expectedRecords?: number;
},
): QueueProcessSummaryResult {
return {
summary: [
`The uploaded file: ${process.env.INSTITUTION_REQUEST_FOLDER}\\ZZZY\\IER_012_${timestamp}.txt`,
`The uploaded file: ${process.env.INSTITUTION_REQUEST_FOLDER}\\${options?.institutionCode}\\IER_012_${timestamp}.txt`,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

`The number of records: ${options?.expectedRecords ?? 1}`,
],
} as QueueProcessSummaryResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DisbursementScheduleStatus,
DisbursementValue,
DisbursementValueType,
EducationProgram,
EducationProgramOffering,
Institution,
InstitutionLocation,
Expand Down Expand Up @@ -68,6 +69,8 @@ export function createFakeApplication(relations?: {
* - `institutionLocation` related location.
* - `disbursementValues` related disbursement schedules.
* - `student` related student.
* - `msfaaNumber` related MSFAA number.
* - `program` related education program.
* @param options additional options:
* - `applicationStatus` if provided sets the application status of the application or else defaults to Assessment status.
* - `offeringIntensity` if provided sets the offering intensity for the created fakeApplication.
Expand All @@ -86,6 +89,7 @@ export async function saveFakeApplicationDisbursements(
disbursementValues?: DisbursementValue[];
student?: Student;
msfaaNumber?: MSFAANumber;
program?: EducationProgram;
},
options?: {
applicationStatus?: ApplicationStatus;
Expand Down Expand Up @@ -159,6 +163,7 @@ export async function saveFakeApplicationDisbursements(
* - `institution` related institution.
* - `institutionLocation` related location.
* - `student` related student.
* - `program` related education program.
* @param options additional options:
* - `applicationStatus` application status for the application.
* - `offeringIntensity` if provided sets the offering intensity for the created fakeApplication, otherwise sets it to fulltime by default.
Expand All @@ -170,6 +175,7 @@ export async function saveFakeApplication(
institution?: Institution;
institutionLocation?: InstitutionLocation;
student?: Student;
program?: EducationProgram;
},
options?: {
applicationStatus?: ApplicationStatus;
Expand Down Expand Up @@ -204,6 +210,7 @@ export async function saveFakeApplication(
const fakeOffering = createFakeEducationProgramOffering({
institution: relations?.institution,
institutionLocation: relations?.institutionLocation,
program: relations?.program,
auditUser: savedUser,
});
fakeOffering.offeringIntensity =
Expand All @@ -213,10 +220,10 @@ export async function saveFakeApplication(
if (savedApplication.applicationStatus !== ApplicationStatus.Draft) {
// Original assessment.
const fakeOriginalAssessment = createFakeStudentAssessment({
application: savedApplication,
offering: savedOffering,
auditUser: savedUser,
});
fakeOriginalAssessment.application = savedApplication;
fakeOriginalAssessment.offering = savedOffering;
const savedOriginalAssessment = await studentAssessmentRepo.save(
fakeOriginalAssessment,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export function createFakeEducationProgramOffering(relations?: {
institution?: Institution;
institutionLocation?: InstitutionLocation;
}): EducationProgramOffering {
// Case an institution location is provided already associated with
// an institution ensure that the relationship will be kept and
// another institution will not be generated.
const institution =
relations?.institutionLocation?.institution ?? relations.institution;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

const offering = new EducationProgramOffering();
offering.name = faker.random.word();
offering.actualTuitionCosts = faker.random.number(1000);
Expand All @@ -30,7 +35,7 @@ export function createFakeEducationProgramOffering(relations?: {
offering.educationProgram =
relations?.program ??
createFakeEducationProgram({
institution: relations?.institution,
institution,
auditUser: relations.auditUser,
});
offering.institutionLocation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function createFakeInstitutionLocation(
count: 4,
upcase: true,
});
institutionLocation.hasIntegration = options?.initialValue?.hasIntegration;
Copy link
Contributor

Choose a reason for hiding this comment

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

did we miss this in the previous iterations? or why was this added now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was not needed till now.

return institutionLocation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,43 @@ export function createSSHServiceMock(
}

/**
* Get the parameters provided to the put method of the SSH client that represents the
* remote file path and the data that would be uploaded to the SFTP in a real scenario.
* Get the parameters provided to the put method of the SSH client that
* represents the data that would be uploaded to the SFTP in a real scenario.
* @param sshClientMock SSH mocked client.
* @returns file name and file content of the supposed-to-be uploaded file.
*/
export function getUploadedFile(
sshClientMock: DeepMocked<Client>,
): UploadedFile {
const uploadedFile = {} as UploadedFile;
const [uploadedFile] = getUploadedFiles(sshClientMock);
return uploadedFile;
}

/**
* Get the parameters provided to the put method of the SSH client that represents the
* remote file(s) path and the data that would be uploaded to the SFTP in a real scenario.
* @param sshClientMock SSH mocked client.
* @returns file(s) name and file(s) content of the supposed-to-be uploaded file(s).
*/
export function getUploadedFiles(
sshClientMock: DeepMocked<Client>,
): UploadedFile[] {
if (!sshClientMock.put.mock.calls.length) {
throw new Error(
"SSH client mock was not invoked which means that there was no attempt to upload a file.",
);
}
const [[input, remoteFilePath]] = sshClientMock.put.mock.calls;
if (input) {
uploadedFile.fileLines = input.toString().split(END_OF_LINE);
}
if (remoteFilePath) {
uploadedFile.remoteFilePath = remoteFilePath.toString();
}
return uploadedFile;
return sshClientMock.put.mock.calls.map((call) => {
const uploadedFile = {} as UploadedFile;
const [input, remoteFilePath] = call;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a show stopper, just a suggestion. I believe we can remove this const and pass it in the call itself.

return sshClientMock.put.mock.calls.map(([input, remoteFilePath]) => {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can, I did the change and I am still not sure which one is cleaner from a code perspective.
Either way, I am accepting the suggestion.

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.

if (input) {
uploadedFile.fileLines = input.toString().split(END_OF_LINE);
}
if (remoteFilePath) {
uploadedFile.remoteFilePath = remoteFilePath.toString();
}
return uploadedFile;
});
}

/**
Expand Down