fix(workflows-sdk): fix step name config used before default (#12926)
This commit is contained in:
committed by
GitHub
parent
bccf1bb689
commit
1bd455bc7b
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/workflows-sdk": patch
|
||||
---
|
||||
|
||||
fix(workflows-sdk): step config name before default step
|
||||
@@ -1408,6 +1408,41 @@ describe("Workflow composer", function () {
|
||||
expect(logStepFn).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it("should run same step multiple times", async () => {
|
||||
const log = createStep("log", async (input: number) => {
|
||||
return new StepResponse(input)
|
||||
})
|
||||
|
||||
const sameStepWorkflow = createWorkflow("fake-workflow", () => {
|
||||
const a = log(1).config({ name: "aaaa" })
|
||||
const b = log(2) // without config on purpose
|
||||
const c = log(3).config({ name: "cccc" })
|
||||
return new WorkflowResponse([a, b, c])
|
||||
})
|
||||
|
||||
const sameStepWorkflow2 = createWorkflow("fake-workflow-2", () => {
|
||||
const a = log(1)
|
||||
const b = log(2).config({ name: "bbbb" })
|
||||
const c = log(3).config({ name: "cccc" })
|
||||
return new WorkflowResponse([a, b, c])
|
||||
})
|
||||
|
||||
const sameStepWorkflow3 = createWorkflow("fake-workflow-3", () => {
|
||||
const a = log(1).config({ name: "aaaa" })
|
||||
const b = log(2).config({ name: "bbbb" })
|
||||
const c = log(3)
|
||||
return new WorkflowResponse([a, b, c])
|
||||
})
|
||||
|
||||
const { result } = await sameStepWorkflow().run()
|
||||
const { result: result2 } = await sameStepWorkflow2().run()
|
||||
const { result: result3 } = await sameStepWorkflow3().run()
|
||||
|
||||
expect(result).toEqual([1, 2, 3])
|
||||
expect(result2).toEqual([1, 2, 3])
|
||||
expect(result3).toEqual([1, 2, 3])
|
||||
})
|
||||
|
||||
it("should skip steps until the named step in case of permanent failure", async () => {
|
||||
const logStepFn = jest.fn(async ({ input }: { input: object }) => {
|
||||
return new StepResponse("done and returned")
|
||||
|
||||
@@ -143,9 +143,9 @@ export function applyStep<
|
||||
|
||||
this.isAsync ||= !!(stepConfig.async || stepConfig.compensateAsync)
|
||||
|
||||
if (!this.handlers.has(stepName)) {
|
||||
this.handlers.set(stepName, handler)
|
||||
}
|
||||
this.overriddenHandler.set(stepName, this.handlers.get(stepName)!)
|
||||
|
||||
this.handlers.set(stepName, handler)
|
||||
|
||||
const ret = {
|
||||
__type: OrchestrationUtils.SymbolWorkflowStep,
|
||||
@@ -177,7 +177,7 @@ export function applyStep<
|
||||
newConfig.nested ||= newConfig.async
|
||||
}
|
||||
|
||||
delete localConfig.name
|
||||
delete newConfig.name
|
||||
|
||||
const handler = createStepHandler.bind(this)({
|
||||
stepName: newStepName,
|
||||
@@ -188,6 +188,9 @@ export function applyStep<
|
||||
|
||||
wrapAsyncHandler(newConfig, handler)
|
||||
|
||||
this.handlers.set(stepName, this.overriddenHandler.get(stepName)!)
|
||||
this.overriddenHandler.delete(stepName)
|
||||
|
||||
this.handlers.set(newStepName, handler)
|
||||
|
||||
this.flow.replaceAction(stepConfig.uuid!, newStepName, newConfig)
|
||||
|
||||
@@ -117,6 +117,7 @@ export function createWorkflow<TData, TResult, THooks extends any[]>(
|
||||
flow: WorkflowManager.getEmptyTransactionDefinition(),
|
||||
isAsync: false,
|
||||
handlers,
|
||||
overriddenHandler: new Map(),
|
||||
hooks_: {
|
||||
declared: [],
|
||||
registered: [],
|
||||
|
||||
@@ -113,6 +113,7 @@ export type CreateWorkflowComposerContext = {
|
||||
flow: OrchestratorBuilder
|
||||
isAsync: boolean
|
||||
handlers: WorkflowHandler
|
||||
overriddenHandler: WorkflowHandler
|
||||
stepBinder: <TOutput = unknown>(
|
||||
fn: StepFunctionResult
|
||||
) => WorkflowData<TOutput>
|
||||
|
||||
Reference in New Issue
Block a user