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

#4354 - Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application #4491

Merged
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
Expand Up @@ -30,16 +30,19 @@ import {
import {
AssessmentSequentialProcessingService,
SystemUsersService,
WorkflowClientService,
} from "@sims/services";
import { addDays, getISODateOnlyString } from "@sims/utilities";
import { StudentAssessmentService } from "../../../../services";
import { WorkflowWrapUpType } from "../../assessment.dto";

describe("AssessmentController(e2e)-workflowWrapUp", () => {
let db: E2EDataSources;
let assessmentController: AssessmentController;
let systemUsersService: SystemUsersService;
let studentAssessmentService: StudentAssessmentService;
let assessmentSequentialProcessingService: AssessmentSequentialProcessingService;
let workflowClientService: WorkflowClientService;
let now: Date;
let auditUser: User;

Expand All @@ -52,6 +55,7 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
assessmentSequentialProcessingService = nestApplication.get(
AssessmentSequentialProcessingService,
);
workflowClientService = nestApplication.get(WorkflowClientService);
auditUser = systemUsersService.systemUser;
now = new Date();
});
Expand All @@ -74,10 +78,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData,
),
}),
);

// Asserts
Expand Down Expand Up @@ -163,7 +166,7 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
currentApplicationToWrapUp.currentAssessment.id,
workflowData,
{ workflowData },
),
);

Expand Down Expand Up @@ -210,7 +213,7 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
currentAssessmentInitialValues: {
assessmentWorkflowId: "some fake id",
assessmentDate: new Date(),
studentAssessmentStatus: StudentAssessmentStatus.InProgress,
studentAssessmentStatus: StudentAssessmentStatus.Completed,
},
},
);
Expand All @@ -223,7 +226,7 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
// Monitor the updateAssessmentStatusAndSaveWorkflowData to ensure that it will be called.
const updateAssessmentStatusAndSaveWorkflowDataMock = jest.spyOn(
studentAssessmentService,
"updateAssessmentStatusAndSaveWorkflowData",
"updateAssessmentWrapUpData",
);
// Monitor the assessImpactedApplicationReassessmentNeeded to ensure that it will not be called.
const assessImpactedApplicationReassessmentNeededMock = jest.spyOn(
Expand All @@ -235,7 +238,7 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
currentApplicationToWrapUp.currentAssessment.id,
workflowData,
{ workflowData },
),
);

Expand Down Expand Up @@ -285,10 +288,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand Down Expand Up @@ -344,10 +346,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand Down Expand Up @@ -403,10 +404,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand Down Expand Up @@ -500,10 +500,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand Down Expand Up @@ -600,10 +599,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand Down Expand Up @@ -685,10 +683,9 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(
savedApplication.currentAssessment.id,
{} as WorkflowData,
),
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
workflowData: {} as WorkflowData,
}),
);

// Asserts
Expand All @@ -712,6 +709,60 @@ describe("AssessmentController(e2e)-workflowWrapUp", () => {
},
);

it(`Should update only the assessment status to completed when the workflow wrapUpType header is set to ${WorkflowWrapUpType.AssessmentStatusOnly}.`, async () => {
// Arrange
const savedApplication = await saveFakeApplicationDisbursements(
db.dataSource,
undefined,
{
applicationStatus: ApplicationStatus.Edited,
currentAssessmentInitialValues: {
studentAssessmentStatus: StudentAssessmentStatus.InProgress,
},
},
);
// Monitor the below methods to ensure that they won't be called.
const assessImpactedApplicationReassessmentNeededMock = jest.spyOn(
assessmentSequentialProcessingService,
"assessImpactedApplicationReassessmentNeeded",
);
const sendReleaseAssessmentCalculationMessageMock = jest.spyOn(
workflowClientService,
"sendReleaseAssessmentCalculationMessage",
);

// Act
const result = await assessmentController.workflowWrapUp(
createFakeWorkflowWrapUpPayload(savedApplication.currentAssessment.id, {
wrapUpType: WorkflowWrapUpType.AssessmentStatusOnly,
}),
);

// Assert
expect(FakeWorkerJobResult.getResultType(result)).toBe(
MockedZeebeJobResult.Complete,
);
const expectedAssessment = await db.studentAssessment.findOne({
select: {
id: true,
studentAssessmentStatus: true,
studentAssessmentStatusUpdatedOn: true,
},
where: { id: savedApplication.currentAssessment.id },
});
expect(expectedAssessment).toEqual({
id: savedApplication.currentAssessment.id,
studentAssessmentStatus: StudentAssessmentStatus.Completed,
studentAssessmentStatusUpdatedOn: expect.any(Date),
});
// Ensures assessImpactedApplicationReassessmentNeeded was not called.
expect(
assessImpactedApplicationReassessmentNeededMock,
).not.toHaveBeenCalled();
// Ensures sendReleaseAssessmentCalculationMessage was not called.
expect(sendReleaseAssessmentCalculationMessageMock).not.toHaveBeenCalled();
});

/**
* Saves an offering and assessment for that offering.
* @param savedApplication related saved application.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import { WorkflowData } from "@sims/sims-db";
import { createFakeWorkerJob } from "../../../../../test/utils/worker-job-mock";
import { WorkflowWrapUpJobInDTO } from "../../assessment.dto";
import {
ICustomHeaders,
IOutputVariables,
ZeebeJob,
} from "@camunda8/sdk/dist/zeebe/types";
WorkflowWrapUpJobHeaderDTO,
WorkflowWrapUpJobInDTO,
WorkflowWrapUpType,
} from "../../assessment.dto";
import { IOutputVariables, ZeebeJob } from "@camunda8/sdk/dist/zeebe/types";

/**
* Creates a fake workflow wrap up payload.
* @param assessmentId assessment id.
* @param workflowData workflow data.
* @param options customize the payload.
* - `workflowData` workflow data.
* - `wrapUpType` wrap-up type, default {@link WorkflowWrapUpType.CompleteWrapUp} if not provided.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

* @returns fake workflow wrap up payload.
*/
export function createFakeWorkflowWrapUpPayload(
assessmentId: number,
workflowData: WorkflowData,
options: {
workflowData?: WorkflowData;
wrapUpType?: WorkflowWrapUpType;
},
): Readonly<
ZeebeJob<WorkflowWrapUpJobInDTO, ICustomHeaders, IOutputVariables>
ZeebeJob<WorkflowWrapUpJobInDTO, WorkflowWrapUpJobHeaderDTO, IOutputVariables>
> {
return createFakeWorkerJob<
WorkflowWrapUpJobInDTO,
ICustomHeaders,
WorkflowWrapUpJobHeaderDTO,
IOutputVariables
>({
variables: { assessmentId, workflowData },
variables: { assessmentId, workflowData: options.workflowData },
customHeaders: {
wrapUpType: options.wrapUpType ?? WorkflowWrapUpType.CompleteWrapUp,
},
});
}
Loading
Loading