1 import {
2 adminHeaders,
3 createAdminUser,
4 } from "../../../../helpers/create-admin-user"
5
6 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
7
8 jest.setTimeout(30000)
9
10 medusaIntegrationTestRunner({
11 testSuite: ({ dbConnection, getContainer, api, dbUtils }) => {
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 {
21 name: "Test Location 1",
22 address: {
23 address_1: "Test Address",
24 country_code: "US",
25 },
26 },
27 adminHeaders
28 )
29 ).data.stock_location
30
31 await dbUtils.snapshot()
32 })
33
34 describe("POST /admin/stock-locations/:id/fulfillment-providers", () => {
35 it("should add a fulfillment provider to a stock location successfully", async () => {
36 const response = await api.post(
37 `/admin/stock-locations/${location.id}/fulfillment-providers?fields=id,*fulfillment_providers`,
38 { add: ["manual_test-provider"] },
39 adminHeaders
40 )
41
42 expect(response.status).toEqual(200)
43 expect(response.data.stock_location.fulfillment_providers).toEqual([
44 expect.objectContaining({
45 id: "manual_test-provider",
46 is_enabled: true,
47 }),
48 ])
49 })
50
51 it("should detach a fulfillment provider from a stock location successfully", async () => {
52 await api.post(
53 `/admin/stock-locations/${location.id}/fulfillment-providers`,
54 { add: ["manual_test-provider"] },
55 adminHeaders
56 )
57
58 const response = await api.post(
59 `/admin/stock-locations/${location.id}/fulfillment-providers?fields=id,*fulfillment_providers`,
60 { remove: ["manual_test-provider"] },
61 adminHeaders
62 )
63
64 expect(response.status).toEqual(200)
65 expect(response.data.stock_location.fulfillment_providers).toHaveLength(
66 0
67 )
68 })
69 })
70 },
71 })