**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
|
import { IRegionModuleService } from "@medusajs/types"
|
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
|
import { ContainerRegistrationKeys } from "@medusajs/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 remoteQuery
|
|
let remoteLink
|
|
|
|
beforeAll(async () => {
|
|
appContainer = getContainer()
|
|
regionModule = appContainer.resolve(ModuleRegistrationName.REGION)
|
|
remoteQuery = appContainer.resolve(
|
|
ContainerRegistrationKeys.REMOTE_QUERY
|
|
)
|
|
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
|
})
|
|
|
|
it("should query region and payment provider link with remote query", async () => {
|
|
const region = await regionModule.createRegions({
|
|
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(2)
|
|
expect(otherLink).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: "pp_system_default",
|
|
regions: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: region.id,
|
|
}),
|
|
]),
|
|
}),
|
|
expect.objectContaining({
|
|
id: "pp_system_default_2",
|
|
regions: [],
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
})
|
|
},
|
|
})
|