-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2979 - Email notification - PD/PPD Student reminder email 8 weeks be…
…fore end date Part 2 (#3759) **AC** - [X] Select all student applications where - Offerings end date within 8 weeks. - Applications with current disbursement pending. - Application not archived. - Remove assessments where a notification was already sent. - With the PD/PPD mismatch using the same logic from [validate-disbursement-base.ts](https://github.com/bcgov/SIMS/blob/main/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/validate-disbursement-base.ts#L44). - [X] Save the assessment ID as metadata and ensure the email will be sent once. - [x] E2E Tests suite added, E2E tests will be added in Part 3 PR - [] Ensure the email will be sent once for the same assessment. - [] Ensure the email will be sent again for different assessments for the same application. ![image](https://github.com/user-attachments/assets/6e2c5ec4-8cd4-4f53-a7a8-60ae60a756dd) Migrations Revert Demo: ![image](https://github.com/user-attachments/assets/6b1d1239-e818-468d-8352-ebe25e32401e) Sample Email ![image](https://github.com/user-attachments/assets/ad743e58-3284-4c02-81ff-1184ab862685) Underlying SQL for TypeOrm ``` SELECT "application"."application_number" AS "application_application_number", "application"."id" AS "application_id", "student_assessments"."id" AS "student_assessments_id", "students"."disability_status" AS "students_disability_status", "students"."id" AS "students_id", "users"."id" AS "users_id", "users"."email" AS "users_email", "users"."first_name" AS "users_first_name", "users"."last_name" AS "users_last_name" FROM "sims"."applications" "application" INNER JOIN "sims"."student_assessments" "student_assessments" ON "student_assessments"."id" = "application"."current_assessment_id" INNER JOIN "sims"."students" "students" ON "students"."id" = "application"."student_id" INNER JOIN "sims"."users" "users" ON "users"."id" = "students"."user_id" INNER JOIN "sims"."education_programs_offerings" "epo" ON "epo"."id" = "student_assessments"."offering_id" INNER JOIN "sims"."disbursement_schedules" "ds" ON "ds"."student_assessment_id" = "student_assessments"."id" WHERE "epo"."study_end_date" >= '2024-11-28T21:37:26.764Z' AND "students"."disability_status" NOT IN ('PD', 'PPD') AND json_extract_path_text(student_assessments.workflow_data::json, 'calculatedData', 'pdppdStatus') = 'true' AND "application"."is_archived" = false AND "ds"."disbursement_schedule_status" = 'Pending' AND NOT EXISTS ((SELECT 1 FROM "sims"."notifications" "n" WHERE "n"."notification_message_id" = 30 AND json_extract_path_text(n.metadata::json, 'assessmentId') = CAST("student_assessments"."id" AS TEXT))) AND NOT EXISTS ((SELECT 1 FROM "sims"."disbursement_schedules" "ds2" WHERE "ds2"."student_assessment_id" = "student_assessments"."id" AND "ds2"."disbursement_date" < "ds"."disbursement_date")) ```
- Loading branch information
1 parent
fbb17a9
commit 0464a84
Showing
11 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...-migrations/src/migrations/1727890225038-InsertStudentNotificationPdPpdStudentReminder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import { getSQLFileData } from "../utilities/sqlLoader"; | ||
|
||
export class InsertStudentNotificationPdPpdStudentReminder1727890225038 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
getSQLFileData( | ||
"Insert-student-notification-pd-ppd-student-reminder.sql", | ||
"NotificationMessages", | ||
), | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
getSQLFileData( | ||
"Rollback-insert-student-notification-pd-ppd-student-reminder.sql", | ||
"NotificationMessages", | ||
), | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ions/src/sql/NotificationMessages/Insert-student-notification-pd-ppd-student-reminder.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
INSERT INTO | ||
sims.notification_messages(id, description, template_id) | ||
VALUES | ||
( | ||
30, | ||
'Student application notification for PD/PPD reminder email 8 weeks before end date.', | ||
'7faea39f-cf8e-41ee-af02-c4790cac5b26' | ||
); |
4 changes: 4 additions & 0 deletions
4
...sql/NotificationMessages/Rollback-Insert-student-notification-pd-ppd-student-reminder.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DELETE FROM | ||
sims.notification_messages | ||
WHERE | ||
ID = 30; |
114 changes: 114 additions & 0 deletions
114
...application-notifications/_tests_/student-application-notifications.scheduler.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { createMock } from "@golevelup/ts-jest"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { QueueNames } from "@sims/utilities"; | ||
import { | ||
createTestingAppModule, | ||
describeProcessorRootTest, | ||
} from "../../../../../test/helpers"; | ||
import { | ||
E2EDataSources, | ||
createE2EDataSources, | ||
saveFakeApplicationDisbursements, | ||
saveFakeStudent, | ||
} from "@sims/test-utils"; | ||
import { Job } from "bull"; | ||
import { | ||
ApplicationStatus, | ||
DisabilityStatus, | ||
DisbursementScheduleStatus, | ||
NotificationMessageType, | ||
WorkflowData, | ||
} from "@sims/sims-db"; | ||
import { IsNull, Not } from "typeorm"; | ||
import { StudentApplicationNotificationsScheduler } from "../../student-application-notifications/student-application-notifications.scheduler"; | ||
|
||
describe( | ||
describeProcessorRootTest(QueueNames.StudentApplicationNotifications), | ||
() => { | ||
let app: INestApplication; | ||
let processor: StudentApplicationNotificationsScheduler; | ||
let db: E2EDataSources; | ||
|
||
beforeAll(async () => { | ||
// Setup the app and data sources. | ||
const { nestApplication, dataSource } = await createTestingAppModule(); | ||
app = nestApplication; | ||
db = createE2EDataSources(dataSource); | ||
// Processor under test. | ||
processor = app.get(StudentApplicationNotificationsScheduler); | ||
}); | ||
|
||
beforeEach(async () => { | ||
// Cancel all applications to ensure tha existing data will not affect these tests. | ||
await db.application.update( | ||
{ applicationStatus: Not(ApplicationStatus.Cancelled) }, | ||
{ applicationStatus: ApplicationStatus.Cancelled }, | ||
); | ||
}); | ||
|
||
it( | ||
"Should generate a notification for PD/PPD student mismatch close to the offering end date " + | ||
"when the application is completed and at least one disbursement is pending and there is a PD/PPD mismatch.", | ||
async () => { | ||
// Arrange | ||
// Create a student with a non-approved disability. | ||
const student = await saveFakeStudent(db.dataSource, undefined, { | ||
initialValue: { disabilityStatus: DisabilityStatus.Requested }, | ||
}); | ||
// Create an application with the disability as true. | ||
const application = await saveFakeApplicationDisbursements( | ||
db.dataSource, | ||
{ student }, | ||
{ | ||
applicationStatus: ApplicationStatus.Completed, | ||
currentAssessmentInitialValues: { | ||
workflowData: { | ||
calculatedData: { | ||
pdppdStatus: true, | ||
}, | ||
} as WorkflowData, | ||
}, | ||
createSecondDisbursement: true, | ||
firstDisbursementInitialValues: { | ||
disbursementScheduleStatus: DisbursementScheduleStatus.Sent, | ||
}, | ||
secondDisbursementInitialValues: { | ||
disbursementScheduleStatus: DisbursementScheduleStatus.Pending, | ||
}, | ||
}, | ||
); | ||
// Queued job. | ||
const job = createMock<Job<void>>(); | ||
|
||
// Act | ||
await processor.studentApplicationNotifications(job); | ||
|
||
// Assert | ||
const notification = await db.notification.findOne({ | ||
select: { | ||
id: true, | ||
messagePayload: true, | ||
}, | ||
relations: { notificationMessage: true }, | ||
where: { | ||
notificationMessage: { | ||
id: NotificationMessageType.StudentPDPPDApplicationNotification, | ||
}, | ||
dateSent: IsNull(), | ||
user: { id: student.user.id }, | ||
}, | ||
}); | ||
expect(notification).toBeDefined(); | ||
expect(notification.messagePayload).toStrictEqual({ | ||
email_address: application.student.user.email, | ||
template_id: "7faea39f-cf8e-41ee-af02-c4790cac5b26", | ||
personalisation: { | ||
lastName: application.student.user.lastName, | ||
givenNames: application.student.user.firstName, | ||
applicationNumber: application.applicationNumber, | ||
}, | ||
}); | ||
}, | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.