fix(workflows-sdk): name for when/then step (#10459)
This commit is contained in:
committed by
GitHub
parent
7ff3f15d6d
commit
90ae187e09
@@ -18,6 +18,7 @@ import {
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { asValue } from "awilix"
|
||||
import { setTimeout } from "timers/promises"
|
||||
import { setTimeout as setTimeoutSync } from "timers"
|
||||
import { WorkflowsModuleService } from "../../src/services"
|
||||
import "../__fixtures__"
|
||||
import { createScheduled } from "../__fixtures__/workflow_scheduled"
|
||||
@@ -25,6 +26,18 @@ import { TestDatabase } from "../utils"
|
||||
|
||||
jest.setTimeout(999900000)
|
||||
|
||||
const failTrap = (done) => {
|
||||
setTimeoutSync(() => {
|
||||
// REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending
|
||||
console.warn(
|
||||
"Jest is breaking the event emit with its debouncer. This allows to continue the test by managing the timeout of the test manually."
|
||||
)
|
||||
done()
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
// REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending
|
||||
|
||||
moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
moduleName: Modules.WORKFLOW_ENGINE,
|
||||
resolve: __dirname + "/../..",
|
||||
@@ -359,9 +372,9 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it.skip("should complete an async workflow that returns a StepResponse", (done) => {
|
||||
it("should complete an async workflow that returns a StepResponse", (done) => {
|
||||
const transactionId = "transaction_1"
|
||||
void workflowOrcModule
|
||||
workflowOrcModule
|
||||
.run("workflow_async_background", {
|
||||
input: {
|
||||
myInput: "123",
|
||||
@@ -369,7 +382,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
transactionId,
|
||||
throwOnError: true,
|
||||
})
|
||||
.then(({ transaction, result }) => {
|
||||
.then(({ transaction, result }: any) => {
|
||||
expect(transaction.flow.state).toEqual(
|
||||
TransactionStepState.INVOKING
|
||||
)
|
||||
@@ -385,14 +398,14 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
failTrap(done)
|
||||
})
|
||||
|
||||
it.skip("should subscribe to a async workflow and receive the response when it finishes", (done) => {
|
||||
it("should subscribe to a async workflow and receive the response when it finishes", (done) => {
|
||||
const transactionId = "trx_123"
|
||||
|
||||
const onFinish = jest.fn(() => {
|
||||
done()
|
||||
})
|
||||
const onFinish = jest.fn()
|
||||
|
||||
void workflowOrcModule.run("workflow_async_background", {
|
||||
input: {
|
||||
@@ -408,11 +421,36 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
|
||||
subscriber: (event) => {
|
||||
if (event.eventType === "onFinish") {
|
||||
onFinish()
|
||||
done()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
expect(onFinish).toHaveBeenCalledTimes(0)
|
||||
|
||||
failTrap(done)
|
||||
})
|
||||
|
||||
it("should not skip step if condition is true", function (done) {
|
||||
void workflowOrcModule.run("wf-when", {
|
||||
input: {
|
||||
callSubFlow: true,
|
||||
},
|
||||
transactionId: "trx_123_when",
|
||||
throwOnError: true,
|
||||
logOnError: true,
|
||||
})
|
||||
|
||||
void workflowOrcModule.subscribe({
|
||||
workflowId: "wf-when",
|
||||
subscriber: (event) => {
|
||||
if (event.eventType === "onFinish") {
|
||||
done()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
failTrap(done)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user