Skip to content

Commit

Permalink
#2510 - e-Cert Implementation for Individual Student Processing - E2E…
Browse files Browse the repository at this point in the history
… Tests (#2566)

### Local Load Test
- Executed tests with 15,000 eligible disbursements and executed
refactors to improve performance and fix issues.
- Some `save` operations were converted to `update`, for performance
improvement.
- During e-Cert generation, the records were updated to `Sent` at one
single operation which for a large amount of records was leading to an
idle transaction error because the SQL command was taking too long to be
executed.

### New E2Es added for part-time/full-time.

#### Full-time

_Should disburse BC funding for a close-to-maximum disbursement, reduce
BC funding when passing the maximum, and withhold BC Funding when a
restriction was applied due to the maximum configured value for the year
being reached._

This E2E was useful to validate a restriction being added to a
disbursement and affecting the upcoming disbursement for the same
student.

#### Part-time
_Should create an e-Cert with three disbursements for two different
students with two disbursements each where three records are eligible._

#### New E2E helpers

- Created a full-time/part-time parser to alow verification of
individual fields in an e-Cert.
- Created a helper to mock the Bull Job and also allow access to check
the generated logs.

### Minor refactor
as pointed out by @guru-aot, there was a type on
`DisbursementScheduleStatus.ReadyToSend` enum. The migration file names
were not updated.
  • Loading branch information
andrewsignori-aot authored Dec 8, 2023
1 parent c5a876e commit 0309080
Show file tree
Hide file tree
Showing 24 changed files with 1,082 additions and 182 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { DisbursementSchedule, DisbursementValue } from "@sims/sims-db";
import { E2EDataSources } from "@sims/test-utils";
import { In } from "typeorm";

/**
* Load disbursement awards for further validations.
* The method {@link awardAssert} can be used in conjunction with this.
* @param dataSource application dataSource.
* @param disbursementId disbursement id to have the awards loaded.
* @param options load options.
* - `valueCode` award value code to be filtered.
* @returns disbursement awards.
*/
export async function loadAwardValues(
dataSource: E2EDataSources,
disbursementId: number,
options?: {
valueCode: string[];
},
): Promise<DisbursementValue[]> {
return dataSource.disbursementValue.find({
select: {
valueCode: true,
valueAmount: true,
effectiveAmount: true,
restrictionAmountSubtracted: true,
restrictionSubtracted: {
id: true,
},
},
relations: {
restrictionSubtracted: true,
},
where: {
disbursementSchedule: { id: disbursementId },
valueCode: options?.valueCode.length ? In(options.valueCode) : undefined,
},
});
}

/**
* Check the award updated values to ensure that they were updated as expected.
* @param awards list of awards.
* @param valueCode award code.
* @param options method optional award values to be asserted.
* - `valueAmount` eligible award value.
* - `effectiveAmount` value calculated to be added to the e-Cert.
* - `restrictionAmountSubtracted` amount subtracted from the eligible award
* value due to a restriction.
* @returns true if all assertions were successful.
*/
export function awardAssert(
awards: DisbursementValue[],
valueCode: string,
options: {
valueAmount?: number;
effectiveAmount?: number;
restrictionAmountSubtracted?: number;
},
): boolean {
const award = awards.find((award) => award.valueCode === valueCode);
if (!award) {
return false;
}
if (options.valueAmount && options.valueAmount !== award.valueAmount) {
return false;
}
if (
options.effectiveAmount &&
options.effectiveAmount !== award.effectiveAmount
) {
return false;
}
if (
options.restrictionAmountSubtracted &&
(options.restrictionAmountSubtracted !==
award.restrictionAmountSubtracted ||
!award.restrictionSubtracted.id)
) {
// If a restriction is expected, a restriction id should also be present.
return false;
}
return true;
}

/**
* Load the disbursement schedules for the assessment.
* @param dataSource application dataSource.
* @param studentAssessmentId assessment id.
* @returns disbursement schedules for the assessment.
*/
export async function loadDisbursementSchedules(
dataSource: E2EDataSources,
studentAssessmentId: number,
): Promise<DisbursementSchedule[]> {
return dataSource.disbursementSchedule.find({
select: {
id: true,
disbursementScheduleStatus: true,
},
where: {
studentAssessment: {
id: studentAssessmentId,
},
},
order: { disbursementDate: "ASC" },
});
}
Loading

0 comments on commit 0309080

Please sign in to comment.