1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import {
3 adminHeaders,
4 createAdminUser,
5 } from "../../../../helpers/create-admin-user"
6
7 jest.setTimeout(50000)
8
9 medusaIntegrationTestRunner({
10 testSuite: ({ dbConnection, getContainer, api, dbUtils }) => {
11 describe("Admin: Fulfillment Provider API", () => {
12 let location
13
14 beforeAll(async () => {
15 await createAdminUser(dbConnection, adminHeaders, getContainer())
16
17 location = (
18 await api.post(
19 `/admin/stock-locations`,
20 { name: "Test location" },
21 adminHeaders
22 )
23 ).data.stock_location
24
25 await dbUtils.snapshot()
26 })
27
28 describe("GET /admin/fulfillment-providers", () => {
29 it("should list all fulfillment providers successfully", async () => {
30 const response = await api.get(
31 `/admin/fulfillment-providers`,
32 adminHeaders
33 )
34
35 expect(response.status).toEqual(200)
36 expect(response.data.fulfillment_providers).toEqual(
37 expect.arrayContaining([
38 expect.objectContaining({
39 id: "manual_test-provider",
40 is_enabled: true,
41 }),
42 expect.objectContaining({
43 id: "manual-calculated_test-provider-calculated",
44 is_enabled: true,
45 }),
46 ])
47 )
48 })
49
50 it("should list all fulfillment providers scoped by stock location", async () => {
51 let response = await api.get(
52 `/admin/fulfillment-providers?stock_location_id=${location.id}`,
53 adminHeaders
54 )
55
56 expect(response.status).toEqual(200)
57 expect(response.data.fulfillment_providers).toEqual([])
58
59 await api.post(
60 `/admin/stock-locations/${location.id}/fulfillment-providers`,
61 { add: ["manual_test-provider"] },
62 adminHeaders
63 )
64
65 response = await api.get(
66 `/admin/fulfillment-providers?stock_location_id=${location.id}`,
67 adminHeaders
68 )
69
70 expect(response.data.fulfillment_providers).toEqual([
71 expect.objectContaining({
72 id: "manual_test-provider",
73 is_enabled: true,
74 }),
75 ])
76 })
77 })
78 })
79 },
80 })