feat(core-flows,medusa): add endpoint to add/remove fulfillment providers to location (#8299)

what:

- add endpoint to add/remove fulfillment providers to location
- specs cleanup from previous PR

RESOLVES CC-259
This commit is contained in:
Riqwan Thamir
2024-07-26 14:35:19 +00:00
committed by GitHub
parent 4eb7abbae8
commit 71411463b1
11 changed files with 154 additions and 127 deletions
@@ -0,0 +1,66 @@
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
let location
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, getContainer())
location = (
await api.post(
`/admin/stock-locations`,
{
name: "Test Location 1",
address: {
address_1: "Test Address",
country_code: "US",
},
},
adminHeaders
)
).data.stock_location
})
describe("POST /admin/stock-locations/:id/fulfillment-providers", () => {
it("should add a fulfillment provider to a stock location successfully", async () => {
const response = await api.post(
`/admin/stock-locations/${location.id}/fulfillment-providers?fields=id,*fulfillment_providers`,
{ add: ["manual_test-provider"] },
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.stock_location.fulfillment_providers).toEqual([
{ id: "manual_test-provider", is_enabled: true },
])
})
it("should detach a fulfillment provider from a stock location successfully", async () => {
await api.post(
`/admin/stock-locations/${location.id}/fulfillment-providers`,
{ add: ["manual_test-provider"] },
adminHeaders
)
const response = await api.post(
`/admin/stock-locations/${location.id}/fulfillment-providers?fields=id,*fulfillment_providers`,
{ remove: ["manual_test-provider"] },
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.stock_location.fulfillment_providers).toHaveLength(
0
)
})
})
},
})