docs: added to workflow legend + example improvements (#11895)
This commit is contained in:
@@ -19,13 +19,13 @@ In this chapter, find an example of writing an integration test for a module usi
|
||||
|
||||
## Write Integration Test for Module
|
||||
|
||||
Consider a `hello` module with a `HelloModuleService` that has a `getMessage` method:
|
||||
Consider a `blog` module with a `BlogModuleService` that has a `getMessage` method:
|
||||
|
||||
```ts title="src/modules/hello/service.ts"
|
||||
```ts title="src/modules/blog/service.ts"
|
||||
import { MedusaService } from "@medusajs/framework/utils"
|
||||
import MyCustom from "./models/my-custom"
|
||||
|
||||
class HelloModuleService extends MedusaService({
|
||||
class BlogModuleService extends MedusaService({
|
||||
MyCustom,
|
||||
}){
|
||||
getMessage(): string {
|
||||
@@ -33,23 +33,23 @@ class HelloModuleService extends MedusaService({
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloModuleService
|
||||
export default BlogModuleService
|
||||
```
|
||||
|
||||
To create an integration test for the method, create the file `src/modules/hello/__tests__/service.spec.ts` with the following content:
|
||||
To create an integration test for the method, create the file `src/modules/blog/__tests__/service.spec.ts` with the following content:
|
||||
|
||||
```ts title="src/modules/hello/__tests__/service.spec.ts"
|
||||
```ts title="src/modules/blog/__tests__/service.spec.ts"
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { HELLO_MODULE } from ".."
|
||||
import HelloModuleService from "../service"
|
||||
import { BLOG_MODULE } from ".."
|
||||
import BlogModuleService from "../service"
|
||||
import MyCustom from "../models/my-custom"
|
||||
|
||||
moduleIntegrationTestRunner<HelloModuleService>({
|
||||
moduleName: HELLO_MODULE,
|
||||
moduleIntegrationTestRunner<BlogModuleService>({
|
||||
moduleName: BLOG_MODULE,
|
||||
moduleModels: [MyCustom],
|
||||
resolve: "./src/modules/hello",
|
||||
resolve: "./src/modules/blog",
|
||||
testSuite: ({ service }) => {
|
||||
describe("HelloModuleService", () => {
|
||||
describe("BlogModuleService", () => {
|
||||
it("says hello world", () => {
|
||||
const message = service.getMessage()
|
||||
|
||||
@@ -62,7 +62,7 @@ moduleIntegrationTestRunner<HelloModuleService>({
|
||||
jest.setTimeout(60 * 1000)
|
||||
```
|
||||
|
||||
You use the `moduleIntegrationTestRunner` function to add tests for the `hello` module. You have one test that passes if the `getMessage` method returns the `"Hello, World!"` string.
|
||||
You use the `moduleIntegrationTestRunner` function to add tests for the `blog` module. You have one test that passes if the `getMessage` method returns the `"Hello, World!"` string.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -21,18 +21,18 @@ In this chapter, you'll learn about `moduleIntegrationTestRunner` from Medusa's
|
||||
|
||||
`moduleIntegrationTestRunner` creates integration tests for a module. The integration tests run on a test Medusa application with only the specified module enabled.
|
||||
|
||||
For example, assuming you have a `hello` module, create a test file at `src/modules/hello/__tests__/service.spec.ts`:
|
||||
For example, assuming you have a `blog` module, create a test file at `src/modules/blog/__tests__/service.spec.ts`:
|
||||
|
||||
```ts title="src/modules/hello/__tests__/service.spec.ts"
|
||||
```ts title="src/modules/blog/__tests__/service.spec.ts"
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { HELLO_MODULE } from ".."
|
||||
import HelloModuleService from "../service"
|
||||
import MyCustom from "../models/my-custom"
|
||||
import { BLOG_MODULE } from ".."
|
||||
import BlogModuleService from "../service"
|
||||
import Post from "../models/post"
|
||||
|
||||
moduleIntegrationTestRunner<HelloModuleService>({
|
||||
moduleName: HELLO_MODULE,
|
||||
moduleModels: [MyCustom],
|
||||
resolve: "./src/modules/hello",
|
||||
moduleIntegrationTestRunner<BlogModuleService>({
|
||||
moduleName: BLOG_MODULE,
|
||||
moduleModels: [Post],
|
||||
resolve: "./src/modules/blog",
|
||||
testSuite: ({ service }) => {
|
||||
// TODO write tests
|
||||
},
|
||||
@@ -86,9 +86,9 @@ For example:
|
||||
|
||||
```ts
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import HelloModuleService from "../service"
|
||||
import BlogModuleService from "../service"
|
||||
|
||||
moduleIntegrationTestRunner<HelloModuleService>({
|
||||
moduleIntegrationTestRunner<BlogModuleService>({
|
||||
moduleOptions: {
|
||||
apiKey: "123",
|
||||
},
|
||||
@@ -106,14 +106,14 @@ For example:
|
||||
|
||||
```ts
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import HelloModuleService from "../service"
|
||||
import BlogModuleService from "../service"
|
||||
import { model } from "@medusajs/framework/utils"
|
||||
|
||||
const DummyModel = model.define("dummy_model", {
|
||||
id: model.id().primaryKey(),
|
||||
})
|
||||
|
||||
moduleIntegrationTestRunner<HelloModuleService>({
|
||||
moduleIntegrationTestRunner<BlogModuleService>({
|
||||
moduleModels: [DummyModel],
|
||||
// ...
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user