feat(modules-sdk, types, user, utils):init user module events (#6431)
* init user module events * refactor utils * undo test script update * fix feedback * add eventbus service to module test-runner * add injected dependencies * move events to utils * use const eventname in tests * rm withTransaction
This commit is contained in:
1 parent
36a61658f9
commit
3fc2aea752
19 files changed
+289
-11
No files matched your search
@@ -4,4 +4,5 @@ export * as JestUtils from "./jest"
|
||||
export { default as MockManager } from "./mock-manager"
|
||||
export { default as MockRepository } from "./mock-repository"
|
||||
export * from "./init-modules"
|
||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||
export * from "./module-test-runner"
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
EmitData,
|
||||
EventBusTypes,
|
||||
IEventBusModuleService,
|
||||
Message,
|
||||
Subscriber,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export default class EventBusService implements IEventBusModuleService {
|
||||
emit<T>(
|
||||
eventName: string,
|
||||
data: T,
|
||||
options?: Record<string, unknown>
|
||||
): Promise<void>
|
||||
emit<T>(data: EmitData<T>[]): Promise<void>
|
||||
emit<T>(data: Message<T>[]): Promise<void>
|
||||
|
||||
async emit<
|
||||
T,
|
||||
TInput extends
|
||||
| string
|
||||
| EventBusTypes.EmitData<T>[]
|
||||
| EventBusTypes.Message<T>[] = string
|
||||
>(
|
||||
eventOrData: TInput,
|
||||
data?: T,
|
||||
options: Record<string, unknown> = {}
|
||||
): Promise<void> {}
|
||||
|
||||
subscribe(event: string | symbol, subscriber: Subscriber): this {
|
||||
return this
|
||||
}
|
||||
|
||||
unsubscribe(
|
||||
event: string | symbol,
|
||||
subscriber: Subscriber,
|
||||
context?: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
return this
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { getDatabaseURL, getMikroOrmWrapper, TestDatabase } from "./database"
|
||||
import { MedusaAppOutput, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
import { initModules, InitModulesOptions } from "./init-modules"
|
||||
import { ContainerRegistrationKeys, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { InitModulesOptions, initModules } from "./init-modules"
|
||||
import { MedusaAppOutput, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
import { TestDatabase, getDatabaseURL, getMikroOrmWrapper } from "./database"
|
||||
|
||||
import { MockEventBusService } from "."
|
||||
|
||||
export interface SuiteOptions<TService = unknown> {
|
||||
MikroOrmWrapper: TestDatabase
|
||||
@@ -20,12 +22,14 @@ export function moduleIntegrationTestRunner({
|
||||
schema = "public",
|
||||
debug = false,
|
||||
testSuite,
|
||||
injectedDependencies = {},
|
||||
}: {
|
||||
moduleName: string
|
||||
moduleModels?: any[]
|
||||
joinerConfig?: any[]
|
||||
schema?: string
|
||||
dbName?: string
|
||||
injectedDependencies?: Record<string, any>
|
||||
debug?: boolean
|
||||
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
|
||||
}) {
|
||||
@@ -65,6 +69,8 @@ export function moduleIntegrationTestRunner({
|
||||
const moduleOptions: InitModulesOptions = {
|
||||
injectedDependencies: {
|
||||
[ContainerRegistrationKeys.PG_CONNECTION]: connection,
|
||||
eventBusService: new MockEventBusService(),
|
||||
...injectedDependencies,
|
||||
},
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: dbConfig,
|
||||
|
||||
Reference in new issue
Block a user