* use initModules instead of initialize when runnning auth module integration tests * rm unused module-config * correct db schema fix * update authentication integration tests w/ initModule * update cart integration tests w/ initModule * update customer integration tests w/ initModule * update payment integration tests w/ initModule * update pricing integration tests w/ initModule * update product integration tests w/ initModule * update promotion integration tests w/ initModule * add initModule to more product tests and return medusaApp from initModule * align moduleOptions naming * update dependencies
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { knex } from "knex"
|
|
import {
|
|
MedusaApp,
|
|
MedusaModule,
|
|
MedusaModuleConfig,
|
|
ModuleJoinerConfig,
|
|
} from "@medusajs/modules-sdk"
|
|
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
|
|
|
interface InitModulesOptions {
|
|
injectedDependencies?: Record<string, unknown>
|
|
databaseConfig: {
|
|
clientUrl: string
|
|
schema?: string
|
|
}
|
|
modulesConfig: MedusaModuleConfig
|
|
joinerConfig?: ModuleJoinerConfig[]
|
|
}
|
|
|
|
export async function initModules({
|
|
injectedDependencies,
|
|
databaseConfig,
|
|
modulesConfig,
|
|
joinerConfig,
|
|
}: InitModulesOptions) {
|
|
injectedDependencies ??= {}
|
|
|
|
let sharedPgConnection =
|
|
injectedDependencies?.[ContainerRegistrationKeys.PG_CONNECTION]
|
|
|
|
if (!sharedPgConnection) {
|
|
sharedPgConnection = knex<any, any>({
|
|
client: "pg",
|
|
searchPath: databaseConfig.schema,
|
|
connection: {
|
|
connectionString: databaseConfig.clientUrl,
|
|
},
|
|
})
|
|
|
|
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION] =
|
|
sharedPgConnection
|
|
}
|
|
|
|
const medusaApp = await MedusaApp({
|
|
modulesConfig,
|
|
servicesConfig: joinerConfig,
|
|
injectedDependencies,
|
|
})
|
|
|
|
async function shutdown() {
|
|
await (sharedPgConnection as any).context?.destroy()
|
|
MedusaModule.clearInstances()
|
|
}
|
|
|
|
return {
|
|
medusaApp,
|
|
shutdown,
|
|
}
|
|
}
|