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 parent
a6736c7ee0
commit
51bb6f1e89
99 files changed
+10164
-10303
No files matched your search
@@ -1,11 +1,4 @@
|
||||
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 { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
@@ -14,49 +7,32 @@ const storeHeaders = {
|
||||
headers: {},
|
||||
}
|
||||
|
||||
describe("Currency - Store", () => {
|
||||
let dbConnection: DataSource
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: ICurrencyModuleService
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ api }) => {
|
||||
describe("Currency - Store", () => {
|
||||
it("should correctly retrieve and list currencies", async () => {
|
||||
const listResp = await api.get("/store/currencies", storeHeaders)
|
||||
|
||||
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)
|
||||
})
|
||||
expect(listResp.data.currencies).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "aud",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "cad",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
|
||||
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("/store/currencies", storeHeaders)
|
||||
|
||||
expect(listResp.data.currencies).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "aud",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "cad",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
const retrieveResp = await api.get(`/store/currencies/aud`, storeHeaders)
|
||||
expect(retrieveResp.data.currency).toEqual(
|
||||
listResp.data.currencies.find((c) => c.code === "aud")
|
||||
)
|
||||
})
|
||||
const retrieveResp = await api.get(
|
||||
`/store/currencies/aud`,
|
||||
storeHeaders
|
||||
)
|
||||
expect(retrieveResp.data.currency).toEqual(
|
||||
listResp.data.currencies.find((c) => c.code === "aud")
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user