Chore/integration tests modules utils (#6581)
new wrapper for medusa integration tests. for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
This commit is contained in:
@@ -1,74 +1,60 @@
|
||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||
import { IRegionModuleService } from "@medusajs/types"
|
||||
import path from "path"
|
||||
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
|
||||
import { useApi } from "../../../environment-helpers/use-api"
|
||||
import { getContainer } from "../../../environment-helpers/use-container"
|
||||
import { initDb, useDb } from "../../../environment-helpers/use-db"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
describe("Payments", () => {
|
||||
let dbConnection
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let regionService: IRegionModuleService
|
||||
let remoteLink
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Payments", () => {
|
||||
let appContainer
|
||||
let regionService: IRegionModuleService
|
||||
let remoteLink
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
dbConnection = await initDb({ cwd, env } as any)
|
||||
shutdownServer = await startBootstrapApp({ cwd, env })
|
||||
appContainer = getContainer()
|
||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
remoteLink = appContainer.resolve("remoteLink")
|
||||
})
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
|
||||
remoteLink = appContainer.resolve("remoteLink")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
it("should list payment providers", async () => {
|
||||
const region = await regionService.create({
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
let response = await api.get(
|
||||
`/store/regions/${region.id}/payment-providers`
|
||||
)
|
||||
|
||||
it("should list payment providers", async () => {
|
||||
const region = await regionService.create({
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_providers).toEqual([])
|
||||
|
||||
await remoteLink.create([
|
||||
{
|
||||
[Modules.REGION]: {
|
||||
region_id: region.id,
|
||||
},
|
||||
[Modules.PAYMENT]: {
|
||||
payment_provider_id: "pp_system_default",
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
response = await api.get(
|
||||
`/store/regions/${region.id}/payment-providers`
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_providers).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "pp_system_default",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
const api = useApi() as any
|
||||
let response = await api.get(
|
||||
`/store/regions/${region.id}/payment-providers`
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_providers).toEqual([])
|
||||
|
||||
await remoteLink.create([
|
||||
{
|
||||
[Modules.REGION]: {
|
||||
region_id: region.id,
|
||||
},
|
||||
[Modules.PAYMENT]: {
|
||||
payment_provider_id: "pp_system_default",
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
response = await api.get(`/store/regions/${region.id}/payment-providers`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.payment_providers).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "pp_system_default",
|
||||
}),
|
||||
])
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user