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
@@ -202,27 +202,17 @@ medusaIntegrationTestRunner({
adminHeaders
)
await api.post(
`/admin/stock-locations/${location.id}/fulfillment-providers`,
{ add: ["manual_test-provider"] },
adminHeaders
)
const remoteLink = container.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: fulfillmentSet.id,
},
},
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: "test",
@@ -1,8 +1,4 @@
import {
ContainerRegistrationKeys,
Modules,
RuleOperator,
} from "@medusajs/utils"
import { RuleOperator } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
@@ -65,6 +61,12 @@ medusaIntegrationTestRunner({
)
).data.stock_location
await api.post(
`/admin/stock-locations/${location.id}/fulfillment-providers`,
{ add: ["manual_test-provider"] },
adminHeaders
)
fulfillmentSet = (
await api.post(
`/admin/fulfillment-sets/${location.fulfillment_sets[0].id}/service-zones`,
@@ -111,22 +113,6 @@ medusaIntegrationTestRunner({
})
it("should create a shipping option successfully", async () => {
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
// TODO: move this to an endpoint when available
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const shippingOptionPayload = {
name: "Test shipping option",
service_zone_id: fulfillmentSet.service_zones[0].id,
@@ -271,22 +257,6 @@ medusaIntegrationTestRunner({
],
}
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
// TODO: move this to an endpoint when available
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const response = await api.post(
`/admin/shipping-options`,
shippingOptionPayload,
@@ -432,22 +402,6 @@ medusaIntegrationTestRunner({
rules: [shippingOptionRule],
}
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
// TODO: move this to an endpoint when available
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const response = await api.post(
`/admin/shipping-options`,
shippingOptionPayload,
@@ -501,22 +455,6 @@ medusaIntegrationTestRunner({
rules: [shippingOptionRule],
}
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
// TODO: move this to an endpoint when available
await remoteLink.create([
{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
},
},
])
const response = await api.post(
`/admin/shipping-options`,
shippingOptionPayload,
@@ -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
)
})
})
},
})