Skip to content
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
@@ -1,14 +1,19 @@
import { HttpStatus, INestApplication } from "@nestjs/common";
import * as request from "supertest";
import { DataSource } from "typeorm";
import { DataSource, IsNull } from "typeorm";
import {
AESTGroups,
BEARER_AUTH_TYPE,
createTestingAppModule,
getAESTToken,
getAESTUser,
} from "../../../../testHelpers";
import { ApplicationEditStatus, ApplicationStatus, User } from "@sims/sims-db";
import {
ApplicationEditStatus,
ApplicationStatus,
NotificationMessageType,
User,
} from "@sims/sims-db";
import { faker } from "@faker-js/faker";
import {
createE2EDataSources,
Expand All @@ -19,6 +24,8 @@ import {
import { ZeebeGrpcClient } from "@camunda8/sdk/dist/zeebe";
import MockDate from "mockdate";
import { INVALID_APPLICATION_EDIT_STATUS } from "@sims/services/constants";
import { GC_NOTIFY_TEMPLATE_IDS } from "@sims/test-utils/constants";
import { getPSTPDTDateTime } from "@sims/utilities";

describe("ApplicationChangeRequestAESTController(e2e)-assessApplicationChangeRequest", () => {
let app: INestApplication;
Expand All @@ -42,6 +49,15 @@ describe("ApplicationChangeRequestAESTController(e2e)-assessApplicationChangeReq

beforeEach(async () => {
MockDate.reset();
// Mark all existing change request review completed notifications as sent to isolate test assertions.
await db.notification.update(
{
notificationMessage: {
id: NotificationMessageType.StudentChangeRequestReviewCompleted,
},
},
{ dateSent: new Date() },
);
});

it("Should approve a change request and copy the offering and appeal when the application change request is waiting for approval.", async () => {
Expand Down Expand Up @@ -218,6 +234,25 @@ describe("ApplicationChangeRequestAESTController(e2e)-assessApplicationChangeReq
creator: ministryUser,
},
]);
// Validate notification.
const createdNotification = await db.notification.findOne({
select: { id: true, messagePayload: true },
where: {
notificationMessage: {
id: NotificationMessageType.StudentChangeRequestReviewCompleted,
},
dateSent: IsNull(),
},
});
expect(createdNotification.messagePayload).toStrictEqual({
template_id: GC_NOTIFY_TEMPLATE_IDS.StudentChangeRequestReviewCompleted,
email_address: changeRequest.student.user.email,
personalisation: {
givenNames: changeRequest.student.user.firstName ?? "",
lastName: changeRequest.student.user.lastName,
date: `${getPSTPDTDateTime(now)} PST/PDT`,
},
});
});

it("Should approve a change request and copy the offering and no appeals when the application change request is waiting for approval, and no appeals are present.", async () => {
Expand Down Expand Up @@ -320,6 +355,25 @@ describe("ApplicationChangeRequestAESTController(e2e)-assessApplicationChangeReq
},
},
});
// Validate notification.
const createdNotification = await db.notification.findOne({
select: { id: true, messagePayload: true },
where: {
notificationMessage: {
id: NotificationMessageType.StudentChangeRequestReviewCompleted,
},
dateSent: IsNull(),
},
});
expect(createdNotification.messagePayload).toStrictEqual({
template_id: GC_NOTIFY_TEMPLATE_IDS.StudentChangeRequestReviewCompleted,
email_address: changeRequest.student.user.email,
personalisation: {
givenNames: changeRequest.student.user.firstName ?? "",
lastName: changeRequest.student.user.lastName,
date: `${getPSTPDTDateTime(now)} PST/PDT`,
},
});
});

it("Should be able to decline a change request and create a student note when the application change request is waiting for approval.", async () => {
Expand Down Expand Up @@ -402,6 +456,25 @@ describe("ApplicationChangeRequestAESTController(e2e)-assessApplicationChangeReq
creator: ministryUser,
},
]);
// Validate notification.
const createdNotification = await db.notification.findOne({
select: { id: true, messagePayload: true },
where: {
notificationMessage: {
id: NotificationMessageType.StudentChangeRequestReviewCompleted,
},
dateSent: IsNull(),
},
});
expect(createdNotification.messagePayload).toStrictEqual({
template_id: GC_NOTIFY_TEMPLATE_IDS.StudentChangeRequestReviewCompleted,
email_address: changeRequest.student.user.email,
personalisation: {
givenNames: changeRequest.student.user.firstName ?? "",
lastName: changeRequest.student.user.lastName,
date: `${getPSTPDTDateTime(now)} PST/PDT`,
},
});
});

it("Should throw a BadRequestException when the application change request approval has an invalid status.", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { In, IsNull } from "typeorm";
import { HttpStatus, INestApplication } from "@nestjs/common";
import * as request from "supertest";
import {
Expand All @@ -19,12 +20,15 @@ import {
ApplicationStatus,
AssessmentTriggerType,
ModifiedIndependentStatus,
NotificationMessageType,
NoteType,
StudentAppealActionType,
StudentAppealStatus,
} from "@sims/sims-db";
import { StudentAppealApprovalAPIInDTO } from "../../../../route-controllers";
import MockDate from "mockdate";
import { getPSTPDTDateTime } from "@sims/utilities";
import { GC_NOTIFY_TEMPLATE_IDS } from "@sims/test-utils/constants";

describe("StudentAppealAESTController(e2e)-approveStudentAppealRequests", () => {
let app: INestApplication;
Expand All @@ -39,6 +43,18 @@ describe("StudentAppealAESTController(e2e)-approveStudentAppealRequests", () =>

beforeEach(async () => {
MockDate.reset();
// Mark all existing student appeal notifications as sent to isolate test assertions.
await db.notification.update(
{
notificationMessage: {
id: In([
NotificationMessageType.StudentChangeRequestReviewCompleted,
NotificationMessageType.MinistryAppealCompleted,
]),
},
},
{ dateSent: new Date() },
);
});

it("Should approve student appeal requests and add note when the appeal with appeal requests submitted for approval are in pending status.", async () => {
Expand Down Expand Up @@ -121,6 +137,25 @@ describe("StudentAppealAESTController(e2e)-approveStudentAppealRequests", () =>
},
],
});
// Validate notification.
const createdNotification = await db.notification.findOne({
select: { id: true, messagePayload: true },
where: {
notificationMessage: {
id: NotificationMessageType.StudentChangeRequestReviewCompleted,
},
dateSent: IsNull(),
},
});
expect(createdNotification.messagePayload).toStrictEqual({
template_id: GC_NOTIFY_TEMPLATE_IDS.StudentChangeRequestReviewCompleted,
email_address: application.student.user.email,
personalisation: {
givenNames: application.student.user.firstName ?? "",
lastName: application.student.user.lastName,
date: `${getPSTPDTDateTime(now)} PST/PDT`,
},
});
});

it("Should throw an unprocessable entity error when the application associated with the appeal is not in completed status.", async () => {
Expand Down Expand Up @@ -291,6 +326,25 @@ describe("StudentAppealAESTController(e2e)-approveStudentAppealRequests", () =>
},
],
});
// Validate notification.
const createdNotification = await db.notification.findOne({
select: { id: true, messagePayload: true },
where: {
notificationMessage: {
id: NotificationMessageType.MinistryAppealCompleted,
},
dateSent: IsNull(),
},
});
expect(createdNotification.messagePayload).toStrictEqual({
template_id: GC_NOTIFY_TEMPLATE_IDS.MinistryAppealCompleted,
email_address: student.user.email,
personalisation: {
givenNames: student.user.firstName ?? "",
lastName: student.user.lastName,
date: `${getPSTPDTDateTime(now)} PST/PDT`,
},
});
});
}
});
Expand Down
Loading
Loading