chore(orchestration): replace workflow definition in v1 (#7181)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/orchestration": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Replace workflow definition if not v2
|
||||||
@@ -80,7 +80,7 @@ describe("WorkflowManager", () => {
|
|||||||
expect(wf).toEqual(["create-product", "broken-delivery", "deliver-product"])
|
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
|
let err
|
||||||
try {
|
try {
|
||||||
WorkflowManager.register(
|
WorkflowManager.register(
|
||||||
@@ -100,6 +100,32 @@ describe("WorkflowManager", () => {
|
|||||||
err = 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).toBeDefined()
|
||||||
expect(err.message).toBe(
|
expect(err.message).toBe(
|
||||||
`Workflow with id "create-product" and step definition already exists.`
|
`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", () => {
|
it("should not throw when registering a workflow with an existing id but identical definition", () => {
|
||||||
let err
|
let err
|
||||||
|
|
||||||
|
const env = process.env.MEDUSA_FF_MEDUSA_V2
|
||||||
|
process.env.MEDUSA_FF_MEDUSA_V2 = "true"
|
||||||
try {
|
try {
|
||||||
WorkflowManager.register(
|
WorkflowManager.register(
|
||||||
"create-product",
|
"create-product",
|
||||||
@@ -122,6 +151,7 @@ describe("WorkflowManager", () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e
|
err = e
|
||||||
}
|
}
|
||||||
|
process.env.MEDUSA_FF_MEDUSA_V2 = env
|
||||||
|
|
||||||
expect(err).not.toBeDefined()
|
expect(err).not.toBeDefined()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -101,9 +101,11 @@ export class WorkflowManager {
|
|||||||
: true
|
: true
|
||||||
|
|
||||||
if (!areStepsEqual) {
|
if (!areStepsEqual) {
|
||||||
throw new Error(
|
if (process.env.MEDUSA_FF_MEDUSA_V2 == "true") {
|
||||||
`Workflow with id "${workflowId}" and step definition already exists.`
|
throw new Error(
|
||||||
)
|
`Workflow with id "${workflowId}" and step definition already exists.`
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user