Feat(medusa-test-utils, authentication, customer, cart, payment, pricing, product, promotion): Add initModule util (#6200)

* 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
This commit is contained in:
Philip Korsholm
2024-01-25 10:37:38 +08:00
committed by GitHub
parent 134af77667
commit efd9204e26
40 changed files with 1042 additions and 486 deletions

View File

@@ -1,33 +1,41 @@
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { MikroOrmWrapper } from "../../../utils"
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
import { IAuthenticationModuleService } from "@medusajs/types"
import { initialize } from "../../../../src"
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
import { MikroOrmWrapper } from "../../../utils"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
import { createAuthUsers } from "../../../__fixtures__/auth-user"
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
import { initModules } from "medusa-test-utils/dist"
import { Modules } from "@medusajs/modules-sdk"
jest.setTimeout(30000)
describe("AuthenticationModuleService - AuthProvider", () => {
let service: IAuthenticationModuleService
let testManager: SqlEntityManager
let shutdownFunc: () => Promise<void>
beforeAll(async () => {
const initModulesConfig = getInitModuleConfig()
const { medusaApp, shutdown } = await initModules(initModulesConfig)
service = medusaApp.modules[Modules.AUTHENTICATION]
shutdownFunc = shutdown
})
beforeEach(async () => {
await MikroOrmWrapper.setupDatabase()
testManager = MikroOrmWrapper.forkManager()
service = await initialize({
database: {
clientUrl: DB_URL,
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
},
})
await createAuthProviders(testManager)
await createAuthUsers(testManager)
})
afterAll(async () => {
await shutdownFunc()
})
afterEach(async () => {
await MikroOrmWrapper.clearDatabase()
})

View File

@@ -3,27 +3,32 @@ import { SqlEntityManager } from "@mikro-orm/postgresql"
import { MikroOrmWrapper } from "../../../utils"
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
import { createAuthUsers } from "../../../__fixtures__/auth-user"
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
import { IAuthenticationModuleService } from "@medusajs/types"
import { initialize } from "../../../../src"
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
import { initModules } from "medusa-test-utils/dist"
import { Modules } from "@medusajs/modules-sdk"
jest.setTimeout(30000)
describe("AuthenticationModuleService - AuthUser", () => {
let service: IAuthenticationModuleService
let testManager: SqlEntityManager
let shutdownFunc: () => Promise<void>
beforeAll(async () => {
const initModulesConfig = getInitModuleConfig()
const { medusaApp, shutdown } = await initModules(initModulesConfig)
service = medusaApp.modules[Modules.AUTHENTICATION]
shutdownFunc = shutdown
})
beforeEach(async () => {
await MikroOrmWrapper.setupDatabase()
testManager = MikroOrmWrapper.forkManager()
service = await initialize({
database: {
clientUrl: DB_URL,
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
},
})
await createAuthProviders(testManager)
await createAuthUsers(testManager)
})
@@ -32,6 +37,10 @@ describe("AuthenticationModuleService - AuthUser", () => {
await MikroOrmWrapper.clearDatabase()
})
afterAll(async () => {
await shutdownFunc()
})
describe("listAuthUsers", () => {
it("should list authUsers", async () => {
const authUsers = await service.listAuthUsers()
@@ -237,7 +246,7 @@ describe("AuthenticationModuleService - AuthUser", () => {
{
id: "test",
provider_id: "manual",
entity_id: "test"
entity_id: "test",
},
])

View File

@@ -1,28 +1,32 @@
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
import { IAuthenticationModuleService } from "@medusajs/types"
import { MedusaModule } from "@medusajs/modules-sdk"
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
import { MikroOrmWrapper } from "../../../utils"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
import { initialize } from "../../../../src"
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
import { initModules } from "medusa-test-utils/dist"
jest.setTimeout(30000)
describe("AuthenticationModuleService - AuthProvider", () => {
let service: IAuthenticationModuleService
let testManager: SqlEntityManager
let shutdownFunc: () => Promise<void>
beforeAll(async () => {
const initModulesConfig = getInitModuleConfig()
const { medusaApp, shutdown } = await initModules(initModulesConfig)
service = medusaApp.modules[Modules.AUTHENTICATION]
shutdownFunc = shutdown
})
beforeEach(async () => {
await MikroOrmWrapper.setupDatabase()
testManager = MikroOrmWrapper.forkManager()
service = await initialize({
database: {
clientUrl: DB_URL,
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
},
})
if (service.__hooks?.onApplicationStart) {
await service.__hooks.onApplicationStart()
}
@@ -33,6 +37,10 @@ describe("AuthenticationModuleService - AuthProvider", () => {
MedusaModule.clearInstances()
})
afterAll(async () => {
await shutdownFunc()
})
describe("listAuthProviders", () => {
it("should list default AuthProviders registered by loaders", async () => {
const authProviders = await service.listAuthProviders()