@@ -24,6 +24,7 @@ const workflow = createWorkflow(
|
||||
"sub-workflow",
|
||||
function (input: WorkflowData<{ outsideWorkflowData: string }>) {
|
||||
step1()
|
||||
step2({ filters: { id: [] } })
|
||||
const somethingHook = createHook("something", { id: "1" })
|
||||
step3()
|
||||
return new WorkflowResponse({ id: 1 }, { hooks: [somethingHook] })
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
WorkflowManager,
|
||||
WorkflowScheduler,
|
||||
} from "@medusajs/orchestration"
|
||||
import { IEventBusModuleService } from "@medusajs/types"
|
||||
import {
|
||||
Modules,
|
||||
composeMessage,
|
||||
@@ -138,14 +139,14 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -223,14 +224,14 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -331,14 +332,14 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -441,14 +442,14 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -557,14 +558,14 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation(function (...inputs) {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation(function (...inputs) {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -651,21 +652,21 @@ describe("Workflow composer", function () {
|
||||
return { inputs: [input], obj: "return from 1" }
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
}
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
}
|
||||
})
|
||||
const mockStep4Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 4",
|
||||
@@ -1001,14 +1002,14 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -1093,6 +1094,7 @@ describe("Workflow composer", function () {
|
||||
if (!input) {
|
||||
return StepResponse.skip()
|
||||
}
|
||||
return new StepResponse({ obj: "return from 2" })
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((inputs) => {
|
||||
return new StepResponse({
|
||||
@@ -1140,7 +1142,7 @@ describe("Workflow composer", function () {
|
||||
obj: "return from 1",
|
||||
},
|
||||
two: {
|
||||
__type: "Symbol(WorkflowWorkflowData)",
|
||||
obj: "return from 2",
|
||||
},
|
||||
input: "none",
|
||||
})
|
||||
@@ -1151,7 +1153,7 @@ describe("Workflow composer", function () {
|
||||
obj: "return from 1",
|
||||
},
|
||||
two: {
|
||||
__type: "Symbol(WorkflowWorkflowData)",
|
||||
obj: "return from 2",
|
||||
},
|
||||
input: "none",
|
||||
},
|
||||
@@ -1164,14 +1166,14 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -1272,14 +1274,14 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -1382,14 +1384,14 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -1498,14 +1500,14 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation(function (...inputs) {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation(function (...inputs) {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
@@ -1592,21 +1594,21 @@ describe("Workflow composer", function () {
|
||||
return new StepResponse({ inputs: [input], obj: "return from 1" })
|
||||
})
|
||||
const mockStep2Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 2",
|
||||
})
|
||||
})
|
||||
const mockStep3Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return new StepResponse({
|
||||
inputs,
|
||||
obj: "return from 3",
|
||||
})
|
||||
})
|
||||
const mockStep4Fn = jest.fn().mockImplementation((...inputs) => {
|
||||
const context = inputs.pop()
|
||||
inputs.pop()
|
||||
return {
|
||||
inputs,
|
||||
obj: "return from 4",
|
||||
@@ -2147,7 +2149,12 @@ describe("Workflow composer", function () {
|
||||
expect(mockStep1Fn).toHaveBeenCalledTimes(1)
|
||||
expect(mockStep1Fn.mock.calls[0]).toHaveLength(2)
|
||||
|
||||
const eventBusMock = container.resolve(Modules.EVENT_BUS)
|
||||
const eventBusMock = container.resolve<
|
||||
IEventBusModuleService & {
|
||||
emit: jest.Mock<any, any, any>
|
||||
releaseGroupedEvents: jest.Mock<any, any, any>
|
||||
}
|
||||
>(Modules.EVENT_BUS)
|
||||
expect(eventBusMock.emit).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusMock.emit.mock.calls[0][0]).toEqual("event1")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createStep } from "../create-step"
|
||||
import { createWorkflow } from "../create-workflow"
|
||||
import { StepResponse } from "../helpers"
|
||||
import { WorkflowResponse } from "../helpers/workflow-response"
|
||||
import { transform } from "../transform"
|
||||
import { WorkflowData } from "../type"
|
||||
import { when } from "../when"
|
||||
@@ -25,7 +26,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
step1()
|
||||
return step2(input)
|
||||
return new WorkflowResponse(step2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -33,7 +34,7 @@ describe("Workflow composer", () => {
|
||||
const subWorkflowRes = subWorkflow.runAsStep({
|
||||
input: "hi from outside",
|
||||
})
|
||||
return step3(subWorkflowRes.result)
|
||||
return new WorkflowResponse(step3(subWorkflowRes.result))
|
||||
})
|
||||
|
||||
const { result } = await workflow.run({ input: {} })
|
||||
@@ -59,7 +60,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
step1()
|
||||
return step2(input)
|
||||
return new WorkflowResponse(step2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -74,7 +75,7 @@ describe("Workflow composer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
return step3(subWorkflowRes.result)
|
||||
return new WorkflowResponse(step3(subWorkflowRes!.result))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -101,7 +102,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
step1()
|
||||
return step2(input)
|
||||
return new WorkflowResponse(step2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -116,7 +117,7 @@ describe("Workflow composer", () => {
|
||||
})
|
||||
})
|
||||
|
||||
return step3(subWorkflowRes.result)
|
||||
return new WorkflowResponse(step3(subWorkflowRes!.result))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -169,7 +170,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
step1()
|
||||
return step2(input)
|
||||
return new WorkflowResponse(step2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -179,7 +180,7 @@ describe("Workflow composer", () => {
|
||||
input: "hi from outside",
|
||||
})
|
||||
step4WithError()
|
||||
return subWorkflowRes
|
||||
return new WorkflowResponse(subWorkflowRes)
|
||||
})
|
||||
|
||||
const { errors } = await workflow.run({ throwOnError: false })
|
||||
@@ -219,7 +220,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
childWorkflowStep1()
|
||||
return childWorkflowStep2(input)
|
||||
return new WorkflowResponse(childWorkflowStep2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -227,7 +228,7 @@ describe("Workflow composer", () => {
|
||||
const subWorkflowRes = subWorkflow.runAsStep({
|
||||
input: "hi from outside",
|
||||
})
|
||||
return step1(subWorkflowRes.result)
|
||||
return new WorkflowResponse(step1(subWorkflowRes.result))
|
||||
})
|
||||
|
||||
const { result } = await workflow.run({
|
||||
@@ -271,7 +272,7 @@ describe("Workflow composer", () => {
|
||||
getNewWorkflowId(),
|
||||
function (input: WorkflowData<string>) {
|
||||
childWorkflowStep1()
|
||||
return childWorkflowStep2(input)
|
||||
return new WorkflowResponse(childWorkflowStep2(input))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -279,7 +280,7 @@ describe("Workflow composer", () => {
|
||||
const subWorkflowRes = subWorkflow.runAsStep({
|
||||
input: "hi from outside",
|
||||
})
|
||||
return step1(subWorkflowRes.result)
|
||||
return new WorkflowResponse(step1(subWorkflowRes.result))
|
||||
})
|
||||
|
||||
const { result } = await workflow.run({
|
||||
@@ -307,16 +308,19 @@ describe("Workflow composer", () => {
|
||||
})
|
||||
|
||||
const work = createWorkflow("id" as any, () => {
|
||||
const resStep1 = step1()
|
||||
step1()
|
||||
const resStep2 = step2()
|
||||
|
||||
const transformedData = transform({ data: resStep2 }, (data) => {
|
||||
// @ts-expect-error "Since we are reading result from undefined"
|
||||
return { result: data.data.result }
|
||||
})
|
||||
|
||||
return transform({ data: transformedData, resStep2 }, (data) => {
|
||||
return { result: data.data }
|
||||
})
|
||||
return new WorkflowResponse(
|
||||
transform({ data: transformedData, resStep2 }, (data) => {
|
||||
return { result: data.data }
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
const { errors } = await work.run({ input: {}, throwOnError: false })
|
||||
|
||||
Reference in New Issue
Block a user