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 authored and GitHub committed 2024-03-06 10:03:07 +00:00
1 parent a6736c7ee0
commit 51bb6f1e89
99 files changed
+10164 -10303

No files matched your search

@@ -1,11 +1,5 @@
import { initDb, useDb } from "../../../environment-helpers/use-db"
import path from "path"
import { startBootstrapApp } from "../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../environment-helpers/use-api"
import adminSeeder from "../../../helpers/admin-seeder"
import { AxiosInstance } from "axios"
import { createAdminUser } from "../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
@@ -14,43 +8,26 @@ const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
describe("POST /admin/invites", () => {
let dbConnection
let shutdownServer
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("POST /admin/invites", () => {
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, getContainer())
})
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
})
it("create an invite", async () => {
const body = {
email: "test_member@test.com",
}
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders)
})
const response = await api.post(`/admin/invites`, body, adminHeaders)
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("create an invite", async () => {
const api = useApi()! as AxiosInstance
const body = {
email: "test_member@test.com",
}
const response = await api.post(`/admin/invites`, body, adminHeaders)
expect(response.status).toEqual(200)
expect(response.data).toEqual({
invite: expect.objectContaining(body),
expect(response.status).toEqual(200)
expect(response.data).toEqual({
invite: expect.objectContaining(body),
})
})
})
})
},
})