-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestration,workflows): pipe oncomplete and workflow preparati…
…on (#4697) * chore: pipe onComplete and workflow preparation step * changeset * fix: tests --------- Co-authored-by: Adrien de Peretti <[email protected]> Co-authored-by: Oli Juhl <[email protected]>
- Loading branch information
1 parent
d1e298f
commit c0ca002
Showing
11 changed files
with
205 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/orchestration": minor | ||
"@medusajs/workflows": minor | ||
--- | ||
|
||
Add pipe onComplete callback and preparation function to exportsWorkflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/workflows/src/helper/__tests__/workflow-export.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { exportWorkflow } from "../workflow-export" | ||
|
||
jest.mock("@medusajs/orchestration", () => { | ||
return { | ||
TransactionHandlerType: { | ||
INVOKE: "invoke", | ||
COMPENSATE: "compensate", | ||
}, | ||
TransactionState: { | ||
FAILED: "failed", | ||
REVERTED: "reverted", | ||
}, | ||
LocalWorkflow: jest.fn(() => { | ||
return { | ||
run: jest.fn(() => { | ||
return { | ||
getErrors: jest.fn(), | ||
getState: jest.fn(() => "done"), | ||
getContext: jest.fn(() => { | ||
return { | ||
invoke: { result_step: "invoke_test" }, | ||
} | ||
}), | ||
} | ||
}), | ||
} | ||
}), | ||
} | ||
}) | ||
|
||
describe("Export Workflow", function () { | ||
it("should prepare the input data before initializing the transaction", async function () { | ||
let transformedInput | ||
const prepare = jest.fn().mockImplementation(async (data) => { | ||
data.__transformed = true | ||
transformedInput = data | ||
|
||
return data | ||
}) | ||
|
||
const work = exportWorkflow("id" as any, "result_step", prepare) | ||
|
||
const wfHandler = work() | ||
|
||
const input = { | ||
test: "payload", | ||
} | ||
|
||
const { result } = await wfHandler.run({ | ||
input, | ||
}) | ||
|
||
expect(input).toEqual({ | ||
test: "payload", | ||
}) | ||
|
||
expect(transformedInput).toEqual({ | ||
test: "payload", | ||
__transformed: true, | ||
}) | ||
|
||
expect(result).toEqual("invoke_test") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters