1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import { ICartModuleService, IRegionModuleService } from "@medusajs/types"
3 import { 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("Link: Cart Region", () => {
13 let appContainer
14 let cartModuleService: ICartModuleService
15 let regionModule: IRegionModuleService
16 let remoteQuery
17
18 beforeAll(async () => {
19 appContainer = getContainer()
20 cartModuleService = appContainer.resolve(Modules.CART)
21 regionModule = appContainer.resolve(Modules.REGION)
22 remoteQuery = appContainer.resolve("remoteQuery")
23 })
24
25 it("should query carts and regions with remote query", async () => {
26 const region = await regionModule.createRegions({
27 name: "Region",
28 currency_code: "usd",
29 })
30
31 const cart = await cartModuleService.createCarts({
32 email: "tony@stark.com",
33 currency_code: "usd",
34 region_id: region.id,
35 })
36
37 const carts = await remoteQuery({
38 cart: {
39 fields: ["id"],
40 region: {
41 fields: ["id"],
42 },
43 },
44 })
45
46 const regions = await remoteQuery({
47 region: {
48 fields: ["id"],
49 carts: {
50 fields: ["id"],
51 },
52 },
53 })
54
55 expect(carts).toEqual(
56 expect.arrayContaining([
57 expect.objectContaining({
58 id: cart.id,
59 region: expect.objectContaining({ id: region.id }),
60 }),
61 ])
62 )
63
64 expect(regions).toEqual(
65 expect.arrayContaining([
66 expect.objectContaining({
67 id: region.id,
68 carts: expect.arrayContaining([
69 expect.objectContaining({ id: cart.id }),
70 ]),
71 }),
72 ])
73 )
74 })
75 })
76 },
77 })