Documentation

7.2.2. Example: Write Integration Tests for Workflows

In this chapter, you'll learn how to write integration tests for workflows using the medusaIntegrationTestRunner utility function.

Write Integration Test for Workflow#

Consider you have the following workflow defined at src/workflows/hello-world.ts:

src/workflows/hello-world.ts
1import {2  createWorkflow,3  createStep,4  StepResponse,5  WorkflowResponse,6} from "@medusajs/workflows-sdk"7
8const step1 = createStep("step-1", () => {9  return new StepResponse("Hello, World!")10})11
12export const helloWorldWorkflow = createWorkflow(13  "hello-world-workflow",14  () => {15    const message = step1()16
17    return new WorkflowResponse(message)18  }19)

To write a test for this workflow, create the file integration-tests/http/workflow.spec.ts with the following content:

integration-tests/http/workflow.spec.ts
1import { medusaIntegrationTestRunner } from "medusa-test-utils"2import { helloWorldWorkflow } from "../../src/workflows/hello-world"3
4medusaIntegrationTestRunner({5  testSuite: ({ getContainer }) => {6    describe("Test hello-world workflow", () => {7      it("returns message", async () => {8        const { result } = await helloWorldWorkflow(getContainer())9          .run()10
11        expect(result).toEqual("Hello, World!")12      })13    })14  },15})

You use the medusaIntegrationTestRunner to write an integration test for the workflow. The test pases if the workflow returns the string "Hello, World!".


Run Test#

Run the following command to run your tests:

TipIf you don't have a test:integration script in package.json , refer to the Medusa Testing Tools chapter .

This runs your Medusa application and runs the tests available under the integrations/http directory.

Was this chapter helpful?
Edit this page