chore(orchestration): replace workflow definition in v1 (#7181)

This commit is contained in:
Carlos R. L. Rodrigues
2024-04-30 13:19:58 -03:00
committed by GitHub
parent efa3308d78
commit 3affcc2525
3 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/orchestration": patch
---
Replace workflow definition if not v2

View File

@@ -80,7 +80,7 @@ describe("WorkflowManager", () => {
expect(wf).toEqual(["create-product", "broken-delivery", "deliver-product"])
})
it("should throw when registering a workflow with an existing id", () => {
it("should NOT throw when registering a workflow with an existing id in Medusa V1", () => {
let err
try {
WorkflowManager.register(
@@ -100,6 +100,32 @@ describe("WorkflowManager", () => {
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(
`Workflow with id "create-product" and step definition already exists.`
@@ -108,6 +134,9 @@ 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",
@@ -122,6 +151,7 @@ describe("WorkflowManager", () => {
} catch (e) {
err = e
}
process.env.MEDUSA_FF_MEDUSA_V2 = env
expect(err).not.toBeDefined()
})

View File

@@ -101,9 +101,11 @@ export class WorkflowManager {
: true
if (!areStepsEqual) {
throw new Error(
`Workflow with id "${workflowId}" and step definition already exists.`
)
if (process.env.MEDUSA_FF_MEDUSA_V2 == "true") {
throw new Error(
`Workflow with id "${workflowId}" and step definition already exists.`
)
}
}
}