chore: Use new test runner in admin payments API (#6611)

No changes to the tests. Only replacing the test runner.

Awaiting #6610
This commit is contained in:
Oli Juhl authored and GitHub committed 2024-03-07 12:51:59 +00:00
1 parent e5cbe28d54
commit a516e7bcba
1 file changed
+22 -43
@@ -1,17 +1,5 @@
const path = require("path")
const startServerWithEnvironment =
require("../../../environment-helpers/start-server-with-environment").default
const { useApi } = require("../../../environment-helpers/use-api")
const { useDb } = require("../../../environment-helpers/use-db")
const adminSeeder = require("../../../helpers/admin-seeder")
const {
simplePaymentCollectionFactory,
} = require("../../../factories/simple-payment-collection-factory")
const {
simpleCustomerFactory,
} = require("../../../factories/simple-customer-factory")
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
const { createAdminUser } = require("../../../helpers/create-admin-user")
jest.setTimeout(30000)
@@ -21,30 +9,29 @@ const adminHeaders = {
},
}
describe("/admin/payment", () => {
let medusaProcess
let dbConnection
let { simpleCustomerFactory, simplePaymentCollectionFactory } = {}
let payCol = null
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
const [process, connection] = await startServerWithEnvironment({
cwd,
})
dbConnection = connection
medusaProcess = process
medusaIntegrationTestRunner({
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
testSuite: ({ dbConnection, getContainer, api }) => {
beforeAll(() => {
;({
simplePaymentCollectionFactory,
} = require("../../../factories/simple-payment-collection-factory"))
;({
simpleCustomerFactory,
} = require("../../../factories/simple-customer-factory"))
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
beforeEach(async () => {
const container = getContainer()
await createAdminUser(dbConnection, adminHeaders, container)
})
describe("POST /admin/payment-collections/:id", () => {
let payCol
beforeEach(async () => {
await adminSeeder(dbConnection)
await simpleCustomerFactory(dbConnection, {
id: "customer",
email: "test@customer.com",
@@ -56,14 +43,7 @@ describe("/admin/payment", () => {
})
})
afterEach(async () => {
const db = useDb()
return await db.teardown()
})
it("Captures an authorized payment", async () => {
const api = useApi()
// create payment session
const payColRes = await api.post(
`/store/payment-collections/${payCol.id}/sessions`,
@@ -85,9 +65,9 @@ describe("/admin/payment", () => {
adminHeaders
)
expect(paymentCollections.data.payment_collection.payments).toHaveLength(
1
)
expect(
paymentCollections.data.payment_collection.payments
).toHaveLength(1)
const payment = paymentCollections.data.payment_collection.payments[0]
@@ -110,8 +90,6 @@ describe("/admin/payment", () => {
})
it("Refunds an captured payment", async () => {
const api = useApi()
// create payment session
const payColRes = await api.post(
`/store/payment-collections/${payCol.id}/sessions`,
@@ -171,4 +149,5 @@ describe("/admin/payment", () => {
)
})
})
},
})