1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import { IRegionModuleService } from "@medusajs/types"
3 import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
4
5 jest.setTimeout(50000)
6
7 const env = {}
8
9 medusaIntegrationTestRunner({
10 env,
11 testSuite: ({ dbConnection, getContainer, api }) => {
12 describe("Region and Payment Providers", () => {
13 let appContainer
14 let regionModule: IRegionModuleService
15 let remoteQuery
16 let remoteLink
17
18 beforeAll(async () => {
19 appContainer = getContainer()
20 regionModule = appContainer.resolve(Modules.REGION)
21 remoteQuery = appContainer.resolve(
22 ContainerRegistrationKeys.REMOTE_QUERY
23 )
24 remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
25 })
26
27 it("should query region and payment provider link with remote query", async () => {
28 const region = await regionModule.createRegions({
29 name: "North America",
30 currency_code: "usd",
31 })
32
33 await remoteLink.create([
34 {
35 [Modules.REGION]: {
36 region_id: region.id,
37 },
38 [Modules.PAYMENT]: {
39 payment_provider_id: "pp_system_default",
40 },
41 },
42 ])
43
44 const links = await remoteQuery({
45 region: {
46 fields: ["id"],
47 payment_providers: {
48 fields: ["id"],
49 },
50 },
51 })
52
53 const otherLink = await remoteQuery({
54 payment_providers: {
55 fields: ["id"],
56 regions: {
57 fields: ["id"],
58 },
59 },
60 })
61
62 expect(links).toHaveLength(1)
63 expect(links).toEqual(
64 expect.arrayContaining([
65 expect.objectContaining({
66 id: region.id,
67 payment_providers: expect.arrayContaining([
68 expect.objectContaining({
69 id: "pp_system_default",
70 }),
71 ]),
72 }),
73 ])
74 )
75
76 expect(otherLink).toHaveLength(2)
77 expect(otherLink).toEqual(
78 expect.arrayContaining([
79 expect.objectContaining({
80 id: "pp_system_default",
81 regions: expect.arrayContaining([
82 expect.objectContaining({
83 id: region.id,
84 }),
85 ]),
86 }),
87 expect.objectContaining({
88 id: "pp_system_default_2",
89 regions: [],
90 }),
91 ])
92 )
93 })
94 })
95 },
96 })