-
Notifications
You must be signed in to change notification settings - Fork 14
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
#1724 - E2E/Units Tests - Review Queue Consumers E2E Tests #1872
Merged
andrewsignori-aot
merged 27 commits into
main
from
feature/#1724-queue-conumers-e2e-tests
Apr 13, 2023
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
267d6fd
E2E StartApplicationAssessmentProcessor
andrewsignori-aot 540538b
Added E2E for CancelApplicationAssessment
andrewsignori-aot 30601f4
Removed unnecessary methods from createMockedZeebeModule
andrewsignori-aot 3152fc9
Reviewing eCert full-time test
andrewsignori-aot 3a4887c
Fixed Sonarcloud issue
andrewsignori-aot 1e53193
Files renaming,
andrewsignori-aot c9c2443
Files renaming, revert
andrewsignori-aot 30ddc15
Merge branch 'feature/#1724-queue-conumers-e2e-tests' of https://gith…
andrewsignori-aot 8345fb3
Fix index file conflict
andrewsignori-aot f8329f8
Fix tests
andrewsignori-aot 5fcaff5
E2E fix
andrewsignori-aot 7e4811c
E2E description change
andrewsignori-aot c622158
Moving E2E e-cert file
andrewsignori-aot 80948ec
Moving file
andrewsignori-aot dc2d3d5
Fire renamed
andrewsignori-aot dffaee7
Test rename file
andrewsignori-aot 0ac78ec
E2E e-cert restored.
andrewsignori-aot 06f519d
Moving file
andrewsignori-aot 07b8928
e-Cert E2E updates
andrewsignori-aot f72a6c3
Revert unwanted file.
andrewsignori-aot 8eb0d26
Added some missing periods.
andrewsignori-aot 9b2c78c
Random generated workflowInstanceId
andrewsignori-aot 84c4f3f
Removing redis dependency
andrewsignori-aot 552bc54
Code cleanup
andrewsignori-aot 5869794
PR review changes
andrewsignori-aot 742cc3c
PR comments
andrewsignori-aot 7bb4389
PR comments
andrewsignori-aot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
186 changes: 186 additions & 0 deletions
186
...ers/src/processors/assessment/_tests_/cancel-application-assessment.processor.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,186 @@ | ||
import { ZBClient } from "zeebe-node"; | ||
import { Job } from "bull"; | ||
import { createMock } from "@golevelup/ts-jest"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { CancelAssessmentQueueInDTO } from "@sims/services/queue"; | ||
import { QueueNames } from "@sims/utilities"; | ||
import { | ||
createTestingAppModule, | ||
describeProcessorRootTest, | ||
} from "../../../../test/helpers"; | ||
import { CancelApplicationAssessmentProcessor } from "../cancel-application-assessment.processor"; | ||
import { DataSource, Repository } from "typeorm"; | ||
import { | ||
createFakeDisbursementOveraward, | ||
saveFakeApplicationDisbursements, | ||
} from "@sims/test-utils"; | ||
import { | ||
ApplicationStatus, | ||
DisbursementOveraward, | ||
DisbursementSchedule, | ||
DisbursementScheduleStatus, | ||
StudentAssessment, | ||
} from "@sims/sims-db"; | ||
|
||
describe( | ||
describeProcessorRootTest(QueueNames.CancelApplicationAssessment), | ||
() => { | ||
let app: INestApplication; | ||
let processor: CancelApplicationAssessmentProcessor; | ||
let zbClientMock: ZBClient; | ||
let appDataSource: DataSource; | ||
let studentAssessmentRepo: Repository<StudentAssessment>; | ||
let disbursementOverawardRepo: Repository<DisbursementOveraward>; | ||
let disbursementScheduleRepo: Repository<DisbursementSchedule>; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, dataSource, zbClient } = | ||
await createTestingAppModule(); | ||
app = nestApplication; | ||
zbClientMock = zbClient; | ||
appDataSource = dataSource; | ||
studentAssessmentRepo = dataSource.getRepository(StudentAssessment); | ||
disbursementOverawardRepo = dataSource.getRepository( | ||
DisbursementOveraward, | ||
); | ||
disbursementScheduleRepo = dataSource.getRepository(DisbursementSchedule); | ||
// Processor under test. | ||
processor = app.get(CancelApplicationAssessmentProcessor); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("Should cancel the assessment pending disbursements and rollback overawards when the cancelled application has overawards and also one sent and one pending disbursements.", async () => { | ||
// Arrange | ||
const workflowInstanceId = "2251799814028835"; | ||
// Application and disbursements. | ||
const application = await saveFakeApplicationDisbursements( | ||
appDataSource, | ||
null, | ||
{ | ||
applicationStatus: ApplicationStatus.Cancelled, | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createSecondDisbursement: true, | ||
}, | ||
); | ||
// Adjust assessment. | ||
const studentAssessment = application.currentAssessment; | ||
studentAssessment.assessmentWorkflowId = workflowInstanceId; | ||
await studentAssessmentRepo.save(application.currentAssessment); | ||
dheepak-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Adjust disbursements. | ||
const [firstDisbursement, secondDisbursement] = | ||
studentAssessment.disbursementSchedules; | ||
firstDisbursement.disbursementScheduleStatus = | ||
DisbursementScheduleStatus.Sent; | ||
await disbursementScheduleRepo.save(firstDisbursement); | ||
// Add a student overaward. | ||
const overaward = createFakeDisbursementOveraward({ | ||
student: application.student, | ||
studentAssessment, | ||
}); | ||
await disbursementOverawardRepo.save(overaward); | ||
// Queued job. | ||
const job = createMock<Job<CancelAssessmentQueueInDTO>>({ | ||
data: { assessmentId: studentAssessment.id }, | ||
}); | ||
|
||
// Act | ||
const result = await processor.cancelAssessment(job); | ||
|
||
// Assert | ||
expect(zbClientMock.cancelProcessInstance).toBeCalledWith( | ||
workflowInstanceId, | ||
); | ||
expect(result.summary).toContain( | ||
dheepak-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Workflow instance successfully cancelled.", | ||
); | ||
expect(result.summary).toContain("Assessment cancelled with success."); | ||
|
||
// Assert that overawards were soft deleted. | ||
const updatedOveraward = await disbursementOverawardRepo.findOne({ | ||
where: { id: overaward.id }, | ||
withDeleted: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
expect(updatedOveraward.deletedAt).toBeDefined(); | ||
|
||
// Assert sent disbursement was not affected. | ||
const firstDisbursementUpdated = await disbursementScheduleRepo.findOneBy( | ||
{ id: firstDisbursement.id }, | ||
); | ||
expect(firstDisbursementUpdated.disbursementScheduleStatus).toBe( | ||
DisbursementScheduleStatus.Sent, | ||
); | ||
|
||
// Assert pending disbursement was cancelled. | ||
const secondDisbursementUpdated = | ||
await disbursementScheduleRepo.findOneBy({ id: secondDisbursement.id }); | ||
expect(secondDisbursementUpdated.disbursementScheduleStatus).toBe( | ||
DisbursementScheduleStatus.Cancelled, | ||
); | ||
}); | ||
|
||
it("Should cancel the assessment and log a warning when the workflowInstanceId is not present.", async () => { | ||
// Arrange | ||
const application = await saveFakeApplicationDisbursements( | ||
appDataSource, | ||
null, | ||
{ applicationStatus: ApplicationStatus.Overwritten }, | ||
); | ||
const studentAssessment = application.currentAssessment; | ||
// Queued job. | ||
const job = createMock<Job<CancelAssessmentQueueInDTO>>({ | ||
data: { assessmentId: studentAssessment.id }, | ||
}); | ||
|
||
// Act | ||
const result = await processor.cancelAssessment(job); | ||
|
||
// Assert | ||
expect(zbClientMock.cancelProcessInstance).not.toHaveBeenCalled(); | ||
expect(result.warnings).toContain( | ||
"Assessment was queued to be cancelled but there is no workflow id associated with.", | ||
); | ||
expect(result.summary).toContain("Assessment cancelled with success."); | ||
}); | ||
|
||
it("Should throw an error and call job.discard when the application is not in the expected status.", async () => { | ||
// Arrange | ||
const errorMessage = `Application must be in the ${ApplicationStatus.Cancelled} or ${ApplicationStatus.Overwritten} state to have the assessment cancelled.`; | ||
const expectedError = new Error(errorMessage); | ||
const application = await saveFakeApplicationDisbursements( | ||
appDataSource, | ||
null, | ||
{ applicationStatus: ApplicationStatus.Completed }, | ||
); | ||
const studentAssessment = application.currentAssessment; | ||
// Queued job. | ||
const job = createMock<Job<CancelAssessmentQueueInDTO>>({ | ||
data: { assessmentId: studentAssessment.id }, | ||
}); | ||
|
||
// Act and Assert | ||
await expect(processor.cancelAssessment(job)).rejects.toStrictEqual( | ||
expectedError, | ||
); | ||
expect(job.discard).toBeCalled(); | ||
}); | ||
|
||
it("Should throw an error and call job.discard when the assessment id was not found.", async () => { | ||
// Arrange | ||
const assessmentId = 9999; | ||
const errorMessage = `Assessment id ${assessmentId} was not found.`; | ||
const error = new Error(errorMessage); | ||
// Queued job. | ||
const job = createMock<Job<CancelAssessmentQueueInDTO>>({ | ||
dheepak-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data: { assessmentId }, | ||
}); | ||
|
||
// Act and Assert | ||
await expect(processor.cancelAssessment(job)).rejects.toStrictEqual( | ||
error, | ||
); | ||
expect(job.discard).toBeCalled(); | ||
}); | ||
}, | ||
); |
67 changes: 67 additions & 0 deletions
67
...mers/src/processors/assessment/_tests_/start-application-assessment.processor.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,67 @@ | ||
import { ZBClient } from "zeebe-node"; | ||
import { Job } from "bull"; | ||
import { createMock } from "@golevelup/ts-jest"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { StartApplicationAssessmentProcessor } from "../start-application-assessment.processor"; | ||
import { StartAssessmentQueueInDTO } from "@sims/services/queue"; | ||
import { QueueNames } from "@sims/utilities"; | ||
import { | ||
createTestingAppModule, | ||
describeProcessorRootTest, | ||
} from "../../../../test/helpers"; | ||
|
||
describe( | ||
describeProcessorRootTest(QueueNames.StartApplicationAssessment), | ||
() => { | ||
let app: INestApplication; | ||
let processor: StartApplicationAssessmentProcessor; | ||
let zbClientMock: ZBClient; | ||
|
||
beforeAll(async () => { | ||
const { nestApplication, zbClient } = await createTestingAppModule(); | ||
app = nestApplication; | ||
zbClientMock = zbClient; | ||
// Processor under test. | ||
processor = app.get(StartApplicationAssessmentProcessor); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("Should throw an error when the workflow createProcessInstance method throws an error.", async () => { | ||
// Arrange | ||
const dummyException = new Error("Dummy error"); | ||
const job = createMock<Job<StartAssessmentQueueInDTO>>(); | ||
zbClientMock.createProcessInstance = jest.fn().mockImplementation(() => { | ||
throw dummyException; | ||
}); | ||
|
||
// Act and Assert. | ||
await expect(processor.startAssessment(job)).rejects.toBe(dummyException); | ||
ann-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it("Should invoke the workflow create instance method with the received job parameters.", async () => { | ||
// Arrange | ||
const workflowName = "dummy workflow name"; | ||
const assessmentId = 999; | ||
const variables = { assessmentId }; | ||
// Queued job. | ||
const job = createMock<Job<StartAssessmentQueueInDTO>>({ | ||
data: { | ||
workflowName, | ||
assessmentId, | ||
}, | ||
}); | ||
|
||
// Act | ||
await processor.startAssessment(job); | ||
|
||
// Assert | ||
expect(zbClientMock.createProcessInstance).toHaveBeenCalledWith( | ||
workflowName, | ||
variables, | ||
); | ||
}); | ||
}, | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking. Any particular reason for changing the name to
createZeebeModuleMock
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class was moved to the lib and it seems more aligned with others.