1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import {
3 IFulfillmentModuleService,
4 IStockLocationService,
5 } from "@medusajs/types"
6 import {
7 ContainerRegistrationKeys,
8 Modules,
9 remoteQueryObjectFromString,
10 } from "@medusajs/utils"
11
12 jest.setTimeout(50000)
13
14 const env = {}
15
16 medusaIntegrationTestRunner({
17 env,
18 testSuite: ({ getContainer }) => {
19 describe("FulfillmentSet and Location", () => {
20 let appContainer
21 let fulfillmentModule: IFulfillmentModuleService
22 let locationModule: IStockLocationService
23 let remoteQuery
24 let remoteLink
25
26 beforeAll(async () => {
27 appContainer = getContainer()
28 fulfillmentModule = appContainer.resolve(Modules.FULFILLMENT)
29 locationModule = appContainer.resolve(Modules.STOCK_LOCATION)
30 remoteQuery = appContainer.resolve(
31 ContainerRegistrationKeys.REMOTE_QUERY
32 )
33 remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
34 })
35
36 it("should query fulfillment set and location link with remote query", async () => {
37 const fulfillmentSet = await fulfillmentModule.createFulfillmentSets({
38 name: "Test fulfillment set",
39 type: "delivery",
40 })
41
42 const euWarehouse = await locationModule.createStockLocations({
43 name: "EU Warehouse",
44 })
45
46 await remoteLink.create([
47 {
48 [Modules.STOCK_LOCATION]: {
49 stock_location_id: euWarehouse.id,
50 },
51 [Modules.FULFILLMENT]: {
52 fulfillment_set_id: fulfillmentSet.id,
53 },
54 },
55 ])
56
57 const linkQuery = remoteQueryObjectFromString({
58 entryPoint: "stock_locations",
59 fields: ["id", "fulfillment_sets.id"],
60 })
61
62 const link = await remoteQuery(linkQuery)
63
64 expect(link).toHaveLength(1)
65 expect(link).toEqual(
66 expect.arrayContaining([
67 expect.objectContaining({
68 id: euWarehouse.id,
69 fulfillment_sets: expect.arrayContaining([
70 expect.objectContaining({
71 id: fulfillmentSet.id,
72 }),
73 ]),
74 }),
75 ])
76 )
77 })
78 })
79 },
80 })