fix(workflows-sdk): Value resolver should resolve non StepResponse (#6726)
This commit is contained in:
1 parent
0c705d7bd4
commit
4b06c17dc0
5 files changed
+38
-27
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/workflows-sdk": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(workflows-sdk): Value resolver should resolve non StepResponse
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
StepResponse,
|
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
|
StepResponse,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
const step_1 = createStep(
|
const step_1 = createStep(
|
||||||
@@ -15,7 +15,6 @@ const step_1 = createStep(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("reverted", compensateInput.compensate)
|
|
||||||
return new StepResponse({
|
return new StepResponse({
|
||||||
reverted: true,
|
reverted: true,
|
||||||
})
|
})
|
||||||
@@ -25,8 +24,6 @@ const step_1 = createStep(
|
|||||||
const step_2 = createStep(
|
const step_2 = createStep(
|
||||||
"step_2",
|
"step_2",
|
||||||
jest.fn((input, context) => {
|
jest.fn((input, context) => {
|
||||||
console.log("triggered async request", context.metadata.idempotency_key)
|
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
return new StepResponse({ notAsyncResponse: input.hey })
|
return new StepResponse({ notAsyncResponse: input.hey })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
StepResponse,
|
|
||||||
createStep,
|
createStep,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
|
StepResponse,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
const step_1 = createStep(
|
const step_1 = createStep(
|
||||||
@@ -15,22 +15,20 @@ const step_1 = createStep(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("reverted", compensateInput.compensate)
|
|
||||||
return new StepResponse({
|
return new StepResponse({
|
||||||
reverted: true,
|
reverted: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const workflow2Step2Invoke = jest.fn((input, context) => {
|
||||||
|
if (input) {
|
||||||
|
return new StepResponse({ notAsyncResponse: input.hey })
|
||||||
|
}
|
||||||
|
})
|
||||||
const step_2 = createStep(
|
const step_2 = createStep(
|
||||||
"step_2",
|
"step_2",
|
||||||
jest.fn((input, context) => {
|
workflow2Step2Invoke,
|
||||||
console.log("triggered async request", context.metadata.idempotency_key)
|
|
||||||
|
|
||||||
if (input) {
|
|
||||||
return new StepResponse({ notAsyncResponse: input.hey })
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
jest.fn((_, context) => {
|
jest.fn((_, context) => {
|
||||||
return new StepResponse({
|
return new StepResponse({
|
||||||
step: context.metadata.action,
|
step: context.metadata.action,
|
||||||
@@ -40,16 +38,14 @@ const step_2 = createStep(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const step_3 = createStep(
|
export const workflow2Step3Invoke = jest.fn((res) => {
|
||||||
"step_3",
|
return new StepResponse({
|
||||||
jest.fn((res) => {
|
done: {
|
||||||
return new StepResponse({
|
inputFromSyncStep: res.notAsyncResponse,
|
||||||
done: {
|
},
|
||||||
inputFromSyncStep: res.notAsyncResponse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
|
const step_3 = createStep("step_3", workflow2Step3Invoke)
|
||||||
|
|
||||||
createWorkflow(
|
createWorkflow(
|
||||||
{
|
{
|
||||||
@@ -59,13 +55,13 @@ createWorkflow(
|
|||||||
function (input) {
|
function (input) {
|
||||||
step_1(input)
|
step_1(input)
|
||||||
|
|
||||||
const ret2 = step_2({ hey: "oh" })
|
step_2({ hey: "oh" })
|
||||||
|
|
||||||
step_2({ hey: "async hello" }).config({
|
const ret2_async = step_2({ hey: "async hello" }).config({
|
||||||
name: "new_step_name",
|
name: "new_step_name",
|
||||||
async: true,
|
async: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return step_3(ret2)
|
return step_3(ret2_async)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -6,6 +6,7 @@ import { knex } from "knex"
|
|||||||
import { setTimeout } from "timers/promises"
|
import { setTimeout } from "timers/promises"
|
||||||
import "../__fixtures__"
|
import "../__fixtures__"
|
||||||
import { DB_URL, TestDatabase } from "../utils"
|
import { DB_URL, TestDatabase } from "../utils"
|
||||||
|
import { workflow2Step2Invoke, workflow2Step3Invoke } from "../__fixtures__"
|
||||||
|
|
||||||
const sharedPgConnection = knex<any, any>({
|
const sharedPgConnection = knex<any, any>({
|
||||||
client: "pg",
|
client: "pg",
|
||||||
@@ -124,6 +125,17 @@ describe("Workflow Orchestrator module", function () {
|
|||||||
stepResponse: { uhuuuu: "yeaah!" },
|
stepResponse: { uhuuuu: "yeaah!" },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
expect(workflow2Step2Invoke).toBeCalledTimes(2)
|
||||||
|
expect(workflow2Step2Invoke.mock.calls[0][0]).toEqual({ hey: "oh" })
|
||||||
|
expect(workflow2Step2Invoke.mock.calls[1][0]).toEqual({
|
||||||
|
hey: "async hello",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(workflow2Step3Invoke).toBeCalledTimes(1)
|
||||||
|
expect(workflow2Step3Invoke.mock.calls[0][0]).toEqual({
|
||||||
|
uhuuuu: "yeaah!",
|
||||||
|
})
|
||||||
|
|
||||||
executionsList = await query({
|
executionsList = await query({
|
||||||
workflow_executions: {
|
workflow_executions: {
|
||||||
fields: ["id"],
|
fields: ["id"],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { OrchestrationUtils, deepCopy, promiseAll } from "@medusajs/utils"
|
import { deepCopy, OrchestrationUtils, promiseAll } from "@medusajs/utils"
|
||||||
|
|
||||||
async function resolveProperty(property, transactionContext) {
|
async function resolveProperty(property, transactionContext) {
|
||||||
const { invoke: invokeRes } = transactionContext
|
const { invoke: invokeRes } = transactionContext
|
||||||
@@ -12,7 +12,8 @@ async function resolveProperty(property, transactionContext) {
|
|||||||
} else if (property?.__type === OrchestrationUtils.SymbolWorkflowHook) {
|
} else if (property?.__type === OrchestrationUtils.SymbolWorkflowHook) {
|
||||||
return await property.__value(transactionContext)
|
return await property.__value(transactionContext)
|
||||||
} else if (property?.__type === OrchestrationUtils.SymbolWorkflowStep) {
|
} else if (property?.__type === OrchestrationUtils.SymbolWorkflowStep) {
|
||||||
const output = invokeRes[property.__step__]?.output
|
const output =
|
||||||
|
invokeRes[property.__step__]?.output ?? invokeRes[property.__step__]
|
||||||
if (output?.__type === OrchestrationUtils.SymbolWorkflowStepResponse) {
|
if (output?.__type === OrchestrationUtils.SymbolWorkflowStepResponse) {
|
||||||
return output.output
|
return output.output
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user