chore(workflows-sdk): check exported workflow (#7592)

This commit is contained in:
Carlos R. L. Rodrigues
2024-06-04 07:18:40 -03:00
committed by GitHub
parent 68fb04b849
commit 41df24e2dc
5 changed files with 71 additions and 49 deletions

View File

@@ -80,9 +80,8 @@ describe("WorkflowManager", () => {
expect(wf).toEqual(["create-product", "broken-delivery", "deliver-product"])
})
it("should NOT throw when registering a workflow with an existing id in Medusa V1", () => {
let err
try {
it("should throw when registering a workflow with an existing id and different definition", () => {
const exec = () =>
WorkflowManager.register(
"create-product",
{
@@ -96,38 +95,8 @@ describe("WorkflowManager", () => {
},
handlers
)
} catch (e) {
err = e
}
expect(err).toBeUndefined()
})
it("should throw when registering a workflow with an existing id in Medusa V2", () => {
let err
const env = process.env.MEDUSA_FF_MEDUSA_V2
process.env.MEDUSA_FF_MEDUSA_V2 = "true"
try {
WorkflowManager.register(
"create-product",
{
action: "foo",
next: {
action: "bar",
next: {
action: "xor",
},
},
},
handlers
)
} catch (e) {
err = e
}
process.env.MEDUSA_FF_MEDUSA_V2 = env
expect(err).toBeDefined()
expect(err.message).toBe(
expect(exec).toThrowError(
`Workflow with id "create-product" and step definition already exists.`
)
})
@@ -135,8 +104,6 @@ describe("WorkflowManager", () => {
it("should not throw when registering a workflow with an existing id but identical definition", () => {
let err
const env = process.env.MEDUSA_FF_MEDUSA_V2
process.env.MEDUSA_FF_MEDUSA_V2 = "true"
try {
WorkflowManager.register(
"create-product",
@@ -151,7 +118,6 @@ describe("WorkflowManager", () => {
} catch (e) {
err = e
}
process.env.MEDUSA_FF_MEDUSA_V2 = env
expect(err).not.toBeDefined()
})

View File

@@ -77,6 +77,10 @@ export class WorkflowManager {
return new OrchestratorBuilder(workflow.flow_)
}
static getEmptyTransactionDefinition(): OrchestratorBuilder {
return new OrchestratorBuilder()
}
static register(
workflowId: string,
flow: TransactionStepsDefinition | OrchestratorBuilder | undefined,
@@ -101,11 +105,9 @@ export class WorkflowManager {
: true
if (!areStepsEqual) {
if (process.env.MEDUSA_FF_MEDUSA_V2 == "true") {
throw new Error(
`Workflow with id "${workflowId}" and step definition already exists.`
)
}
throw new Error(
`Workflow with id "${workflowId}" and step definition already exists.`
)
}
}