Skip to content

Commit

Permalink
#2322 - IER12 E2E Tests - Validate Multiple Files (#2478)
Browse files Browse the repository at this point in the history
- Changed the `saveIER12TestInputData` to use provided locations instead
of creating a brand new one every time.
- Once the institutions/locations were no longer brand new every time
there were conflicts with the SABC program code. The logic was adapted
to allow reusing the programs for the same institution and the same SABC
code instead of creating new programs every time (which will generate
the conflict).
- Added the scenario to allow multiple files to be generated from
different institutions/locations.
- _Should generate 2 IER12 files for locations from different
institutions using distinct institution codes._
- Created `getUploadedFiles` to allow getting multiple uploaded files.
The method `getUploadedFile` was kept for now to prevent further
refactoring and also it can be used as a helper since most of the same
we upload one file only.
- Fix for a dynamic data assertion that was being treated as a constant
which will make the E2E tests fail.
  • Loading branch information
andrewsignori-aot authored Nov 6, 2023
1 parent e20534e commit 4596c01
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 59 deletions.
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");
}

/**
* 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`,
`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;
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;
return institutionLocation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,42 @@ 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(([input, remoteFilePath]) => {
const uploadedFile = {} as UploadedFile;
if (input) {
uploadedFile.fileLines = input.toString().split(END_OF_LINE);
}
if (remoteFilePath) {
uploadedFile.remoteFilePath = remoteFilePath.toString();
}
return uploadedFile;
});
}

/**
Expand Down

0 comments on commit 4596c01

Please sign in to comment.