|
| 1 | +import { |
| 2 | + createE2EDataSources, |
| 3 | + E2EDataSources, |
| 4 | + saveFakeApplication, |
| 5 | +} from "@sims/test-utils"; |
| 6 | +import { |
| 7 | + FAKE_WORKER_JOB_RESULT_PROPERTY, |
| 8 | + MockedZeebeJobResult, |
| 9 | +} from "../../../../../test/utils/worker-job-mock"; |
| 10 | +import { createTestingAppModule } from "../../../../../test/helpers"; |
| 11 | +import { createFakeWorkflowWrapUpPayload } from "./workflow-wrap-up-factory"; |
| 12 | +import { AssessmentController } from "../../assessment.controller"; |
| 13 | +import { StudentAssessmentStatus, WorkflowData } from "@sims/sims-db"; |
| 14 | +import { SystemUsersService } from "@sims/services"; |
| 15 | + |
| 16 | +describe("AssessmentController(e2e)-workflowWrapUp", () => { |
| 17 | + let db: E2EDataSources; |
| 18 | + let assessmentController: AssessmentController; |
| 19 | + let systemUsersService: SystemUsersService; |
| 20 | + |
| 21 | + beforeAll(async () => { |
| 22 | + const { nestApplication, dataSource } = await createTestingAppModule(); |
| 23 | + db = createE2EDataSources(dataSource); |
| 24 | + assessmentController = nestApplication.get(AssessmentController); |
| 25 | + systemUsersService = nestApplication.get(SystemUsersService); |
| 26 | + }); |
| 27 | + |
| 28 | + it(`Should update assessment status to completed when it does not have a status ${StudentAssessmentStatus.InProgress}.`, async () => { |
| 29 | + // Arrange |
| 30 | + const savedApplication = await saveFakeApplication(db.dataSource); |
| 31 | + const workflowData = { |
| 32 | + studentData: { |
| 33 | + dependantStatus: "independant", |
| 34 | + }, |
| 35 | + } as WorkflowData; |
| 36 | + savedApplication.currentAssessment.studentAssessmentStatus = |
| 37 | + StudentAssessmentStatus.InProgress; |
| 38 | + await db.studentAssessment.save(savedApplication.currentAssessment); |
| 39 | + |
| 40 | + // Act |
| 41 | + const result = await assessmentController.workflowWrapUp( |
| 42 | + createFakeWorkflowWrapUpPayload( |
| 43 | + savedApplication.currentAssessment.id, |
| 44 | + workflowData, |
| 45 | + ), |
| 46 | + ); |
| 47 | + |
| 48 | + // Asserts |
| 49 | + expect(result).toHaveProperty( |
| 50 | + FAKE_WORKER_JOB_RESULT_PROPERTY, |
| 51 | + MockedZeebeJobResult.Complete, |
| 52 | + ); |
| 53 | + |
| 54 | + // Asserts that the student assessment status has changed to completed. |
| 55 | + const expectedAssessment = await db.studentAssessment.findOne({ |
| 56 | + select: { |
| 57 | + id: true, |
| 58 | + studentAssessmentStatus: true, |
| 59 | + workflowData: true as unknown, |
| 60 | + studentAssessmentStatusUpdatedOn: true, |
| 61 | + modifier: { id: true }, |
| 62 | + updatedAt: true, |
| 63 | + }, |
| 64 | + relations: { modifier: true }, |
| 65 | + where: { id: savedApplication.currentAssessment.id }, |
| 66 | + }); |
| 67 | + expect(expectedAssessment.studentAssessmentStatus).toBe( |
| 68 | + StudentAssessmentStatus.Completed, |
| 69 | + ); |
| 70 | + expect(expectedAssessment.workflowData).toEqual(workflowData); |
| 71 | + expect(expectedAssessment.studentAssessmentStatusUpdatedOn).toBeInstanceOf( |
| 72 | + Date, |
| 73 | + ); |
| 74 | + const auditUser = await systemUsersService.systemUser(); |
| 75 | + expect(expectedAssessment.modifier).toEqual(auditUser); |
| 76 | + expect(expectedAssessment.updatedAt).toBeInstanceOf(Date); |
| 77 | + }); |
| 78 | +}); |
0 commit comments