feat(types, medusa, core-flows): add delete-stock-location endpoint to api-v2 (#6801)

* initial create

* add changeset

* redo changes for stock locatino module'

* initial delete stock location

* add changeset

* pr prep

* propagate deletion with common step

* move integration tests

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Philip Korsholm
2024-03-25 16:29:36 +01:00
committed by GitHub
parent 71efa15088
commit deab12e27e
8 changed files with 163 additions and 1 deletions

View File

@@ -1,10 +1,11 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { IStockLocationServiceNext } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
@@ -54,5 +55,64 @@ medusaIntegrationTestRunner({
)
})
})
describe("Delete stock location", () => {
let stockLocationId
beforeEach(async () => {
const stockLocationCreateResponse = await api.post(
`/admin/stock-locations`,
{ name: "test location" },
adminHeaders
)
stockLocationId = stockLocationCreateResponse.data.stock_location.id
})
it("should successfully delete stock location", async () => {
const stockLocationDeleteResponse = await api.delete(
`/admin/stock-locations/${stockLocationId}`,
adminHeaders
)
expect(stockLocationDeleteResponse.status).toEqual(200)
expect(stockLocationDeleteResponse.data).toEqual({
id: stockLocationId,
object: "stock_location",
deleted: true,
})
})
it("should successfully delete stock location associations", async () => {
const remoteLink = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLink.create([
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: "default",
},
[Modules.STOCK_LOCATION]: {
stock_location_id: stockLocationId,
},
},
])
await api.delete(
`/admin/stock-locations/${stockLocationId}`,
adminHeaders
)
const linkService = remoteLink.getLinkModule(
Modules.SALES_CHANNEL,
"sales_channel_id",
Modules.STOCK_LOCATION,
"stock_location_id"
)
const stockLocationLinks = await linkService.list()
expect(stockLocationLinks).toHaveLength(0)
})
})
},
})