|
6 | 6 | WorkflowResponse, |
7 | 7 | } from "@medusajs/framework/workflows-sdk" |
8 | 8 | import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
9 | | -import { Modules } from "@medusajs/utils" |
| 9 | +import { Modules, TransactionState } from "@medusajs/utils" |
10 | 10 | import { |
11 | 11 | adminHeaders, |
12 | 12 | createAdminUser, |
@@ -95,6 +95,54 @@ medusaIntegrationTestRunner({ |
95 | 95 | }) |
96 | 96 | }) |
97 | 97 |
|
| 98 | + describe("POST /admin/workflow-execution/[workflow_id]/steps/failure", function () { |
| 99 | + it("should set step as failed", async () => { |
| 100 | + const stepId = 'test-step' |
| 101 | + const step = createStep({ |
| 102 | + name: stepId, |
| 103 | + async: true, |
| 104 | + }, () => { }) |
| 105 | + |
| 106 | + const workflowId = 'test-workflow' |
| 107 | + createWorkflow({ |
| 108 | + name: workflowId, |
| 109 | + retentionTime: 60, |
| 110 | + }, () => { |
| 111 | + step() |
| 112 | + return new WorkflowResponse(void 0) |
| 113 | + }) |
| 114 | + |
| 115 | + const transactionId = "test-transaction" |
| 116 | + const engine = container.resolve(Modules.WORKFLOW_ENGINE) as IWorkflowEngineService |
| 117 | + await engine.run(workflowId, { |
| 118 | + transactionId |
| 119 | + }) |
| 120 | + let workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution |
| 121 | + |
| 122 | + expect(workflowDetail.state).toBe(TransactionState.INVOKING) |
| 123 | + |
| 124 | + const setFailureResponse = await api.post(`/admin/workflows-executions/${workflowId}/steps/failure`, { |
| 125 | + transaction_id: transactionId, |
| 126 | + step_id: stepId |
| 127 | + }, adminHeaders) |
| 128 | + |
| 129 | + expect(setFailureResponse.status).toBe(200) |
| 130 | + expect(setFailureResponse.data).toEqual( |
| 131 | + expect.objectContaining({ |
| 132 | + success: true, |
| 133 | + }) |
| 134 | + ) |
| 135 | + |
| 136 | + workflowDetail = (await api.get(`/admin/workflows-executions/${workflowId}/${transactionId}`, adminHeaders)).data.workflow_execution |
| 137 | + |
| 138 | + expect(workflowDetail).toEqual( |
| 139 | + expect.objectContaining({ |
| 140 | + state: TransactionState.REVERTED, |
| 141 | + }) |
| 142 | + ) |
| 143 | + }) |
| 144 | + }) |
| 145 | + |
98 | 146 | describe("Workflow Orchestrator module subscribe", function () { |
99 | 147 | it("should subscribe to a workflow and receive the response when it finishes", async () => { |
100 | 148 | const step1 = createStep({ name: "step1" }, async () => { |
|
0 commit comments