Files
medusa-store/integration-tests/modules/__tests__/link-modules/region-payment-provider.spec.ts
Adrien de Peretti 51bb6f1e89 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
2024-03-06 10:03:07 +00:00

93 lines
2.5 KiB
TypeScript

import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Region and Payment Providers", () => {
let appContainer
let regionModule: IRegionModuleService
let paymentModule: IPaymentModuleService
let remoteQuery
let remoteLink
beforeAll(async () => {
appContainer = getContainer()
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
remoteQuery = appContainer.resolve("remoteQuery")
remoteLink = appContainer.resolve("remoteLink")
})
it("should query region and payment provider link with remote query", async () => {
const region = await regionModule.create({
name: "North America",
currency_code: "usd",
})
await remoteLink.create([
{
[Modules.REGION]: {
region_id: region.id,
},
[Modules.PAYMENT]: {
payment_provider_id: "pp_system_default",
},
},
])
const links = await remoteQuery({
region: {
fields: ["id"],
payment_providers: {
fields: ["id"],
},
},
})
const otherLink = await remoteQuery({
payment_providers: {
fields: ["id"],
regions: {
fields: ["id"],
},
},
})
expect(links).toHaveLength(1)
expect(links).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: region.id,
payment_providers: expect.arrayContaining([
expect.objectContaining({
id: "pp_system_default",
}),
]),
}),
])
)
expect(otherLink).toHaveLength(1)
expect(otherLink).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "pp_system_default",
regions: expect.arrayContaining([
expect.objectContaining({
id: region.id,
}),
]),
}),
])
)
})
})
},
})