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
2024-03-07 12:51:59 +00:00
committed by GitHub
parent e5cbe28d54
commit a516e7bcba
@@ -1,17 +1,5 @@
const path = require("path") const { medusaIntegrationTestRunner } = require("medusa-test-utils")
const { createAdminUser } = require("../../../helpers/create-admin-user")
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")
jest.setTimeout(30000) jest.setTimeout(30000)
@@ -21,30 +9,29 @@ const adminHeaders = {
}, },
} }
describe("/admin/payment", () => { let { simpleCustomerFactory, simplePaymentCollectionFactory } = {}
let medusaProcess
let dbConnection
let payCol = null medusaIntegrationTestRunner({
beforeAll(async () => { env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
const cwd = path.resolve(path.join(__dirname, "..", "..")) testSuite: ({ dbConnection, getContainer, api }) => {
const [process, connection] = await startServerWithEnvironment({ beforeAll(() => {
cwd, ;({
}) simplePaymentCollectionFactory,
dbConnection = connection } = require("../../../factories/simple-payment-collection-factory"))
medusaProcess = process ;({
simpleCustomerFactory,
} = require("../../../factories/simple-customer-factory"))
}) })
afterAll(async () => { beforeEach(async () => {
const db = useDb() const container = getContainer()
await db.shutdown() await createAdminUser(dbConnection, adminHeaders, container)
medusaProcess.kill()
}) })
describe("POST /admin/payment-collections/:id", () => { describe("POST /admin/payment-collections/:id", () => {
let payCol
beforeEach(async () => { beforeEach(async () => {
await adminSeeder(dbConnection)
await simpleCustomerFactory(dbConnection, { await simpleCustomerFactory(dbConnection, {
id: "customer", id: "customer",
email: "test@customer.com", 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 () => { it("Captures an authorized payment", async () => {
const api = useApi()
// create payment session // create payment session
const payColRes = await api.post( const payColRes = await api.post(
`/store/payment-collections/${payCol.id}/sessions`, `/store/payment-collections/${payCol.id}/sessions`,
@@ -85,9 +65,9 @@ describe("/admin/payment", () => {
adminHeaders adminHeaders
) )
expect(paymentCollections.data.payment_collection.payments).toHaveLength( expect(
1 paymentCollections.data.payment_collection.payments
) ).toHaveLength(1)
const payment = paymentCollections.data.payment_collection.payments[0] const payment = paymentCollections.data.payment_collection.payments[0]
@@ -110,8 +90,6 @@ describe("/admin/payment", () => {
}) })
it("Refunds an captured payment", async () => { it("Refunds an captured payment", async () => {
const api = useApi()
// create payment session // create payment session
const payColRes = await api.post( const payColRes = await api.post(
`/store/payment-collections/${payCol.id}/sessions`, `/store/payment-collections/${payCol.id}/sessions`,
@@ -171,4 +149,5 @@ describe("/admin/payment", () => {
) )
}) })
}) })
},
}) })