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:
Adrien de Peretti
2024-03-06 10:03:07 +00:00
committed by GitHub
parent a6736c7ee0
commit 51bb6f1e89
99 changed files with 10164 additions and 10303 deletions
@@ -1,12 +1,5 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICurrencyModuleService } 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 { DataSource } from "typeorm"
import { createAdminUser } from "../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -15,53 +8,39 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
describe("Currency - Admin", () => {
let dbConnection: DataSource
let appContainer
let shutdownServer
let service: ICurrencyModuleService
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, api, getContainer }) => {
describe("Currency - Admin", () => {
let container
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.CURRENCY)
})
beforeEach(async () => {
container = getContainer()
await createAdminUser(dbConnection, adminHeaders, container)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
it("should correctly retrieve and list currencies", async () => {
const listResp = await api.get("/admin/currencies", adminHeaders)
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders)
})
expect(listResp.data.currencies).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: "aud",
}),
expect.objectContaining({
code: "cad",
}),
])
)
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should correctly retrieve and list currencies", async () => {
const api = useApi() as any
const listResp = await api.get("/admin/currencies", adminHeaders)
expect(listResp.data.currencies).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: "aud",
}),
expect.objectContaining({
code: "cad",
}),
])
)
const retrieveResp = await api.get(`/admin/currencies/aud`, adminHeaders)
expect(retrieveResp.data.currency).toEqual(
listResp.data.currencies.find((c) => c.code === "aud")
)
})
const retrieveResp = await api.get(
`/admin/currencies/aud`,
adminHeaders
)
expect(retrieveResp.data.currency).toEqual(
listResp.data.currencies.find((c) => c.code === "aud")
)
})
})
},
})