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,12 +1,7 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IStoreModuleService } 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,68 +10,56 @@ const adminHeaders = {
|
||||
headers: { "x-medusa-access-token": "test_token" },
|
||||
}
|
||||
|
||||
describe("Store - Admin", () => {
|
||||
let dbConnection: DataSource
|
||||
let appContainer
|
||||
let shutdownServer
|
||||
let service: IStoreModuleService
|
||||
medusaIntegrationTestRunner({
|
||||
env,
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
describe("Store - Admin", () => {
|
||||
let appContainer
|
||||
let service: IStoreModuleService
|
||||
|
||||
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.STORE)
|
||||
})
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
service = appContainer.resolve(ModuleRegistrationName.STORE)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
await shutdownServer()
|
||||
})
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders)
|
||||
})
|
||||
it("should correctly implement the entire lifecycle of a store", async () => {
|
||||
const createdStore = await service.create({
|
||||
name: "Test store",
|
||||
supported_currency_codes: ["usd"],
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
expect(createdStore).toEqual(
|
||||
expect.objectContaining({
|
||||
id: createdStore.id,
|
||||
supported_currency_codes: ["usd"],
|
||||
name: "Test store",
|
||||
})
|
||||
)
|
||||
|
||||
it("should correctly implement the entire lifecycle of a store", async () => {
|
||||
const api = useApi() as any
|
||||
const createdStore = await service.create({
|
||||
name: "Test store",
|
||||
supported_currency_codes: ["usd"],
|
||||
const updated = await api.post(
|
||||
`/admin/stores/${createdStore.id}`,
|
||||
{
|
||||
name: "Updated store",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: createdStore.id,
|
||||
name: "Updated store",
|
||||
})
|
||||
)
|
||||
|
||||
await service.delete(createdStore.id)
|
||||
const listedStores = await api.get(`/admin/stores`, adminHeaders)
|
||||
expect(listedStores.data.stores).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
expect(createdStore).toEqual(
|
||||
expect.objectContaining({
|
||||
id: createdStore.id,
|
||||
supported_currency_codes: ["usd"],
|
||||
name: "Test store",
|
||||
})
|
||||
)
|
||||
|
||||
const updated = await api.post(
|
||||
`/admin/stores/${createdStore.id}`,
|
||||
{
|
||||
name: "Updated store",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(updated.status).toEqual(200)
|
||||
expect(updated.data.store).toEqual(
|
||||
expect.objectContaining({
|
||||
id: createdStore.id,
|
||||
name: "Updated store",
|
||||
})
|
||||
)
|
||||
|
||||
await service.delete(createdStore.id)
|
||||
const listedStores = await api.get(`/admin/stores`, adminHeaders)
|
||||
expect(listedStores.data.stores).toHaveLength(0)
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user