fix(core-flows, link-module): product <> inventory delete cascades (#9528)
**What** - remove cascade delete of inventory items on product delete - implement inventory deletion in product/variant delete workflows with checks: - product/variant cannot be deleted if there are reservations associated with their inventory items - inventory item will be cascade deleted if it's not used by other variants (that are not being deleted in the current flow) --- FIXES CC-581 CC-582
This commit is contained in:
@@ -782,7 +782,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("DELETE /admin/inventory-items/:id", () => {
|
||||
it("should remove associated levels and reservations when deleting an inventory item", async () => {
|
||||
it("should throw if inventory item with reservations is being removed", async () => {
|
||||
await api.post(
|
||||
`/admin/inventory-items/${inventoryItem1.id}/location-levels`,
|
||||
{
|
||||
@@ -821,30 +821,16 @@ medusaIntegrationTestRunner({
|
||||
).data
|
||||
expect(levelsResponse.count).toEqual(1)
|
||||
|
||||
const res = await api.delete(
|
||||
`/admin/inventory-items/${inventoryItem1.id}`,
|
||||
adminHeaders
|
||||
const res = await api
|
||||
.delete(`/admin/inventory-items/${inventoryItem1.id}`, adminHeaders)
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
|
||||
expect(res.status).toEqual(400)
|
||||
expect(res.data.message).toEqual(
|
||||
`Cannot remove following inventory item(s) since they have reservations: [${inventoryItem1.id}].`
|
||||
)
|
||||
|
||||
expect(res.status).toEqual(200)
|
||||
|
||||
const reservationsResponseAfterDelete = (
|
||||
await api.get(
|
||||
`/admin/reservations?location_id[]=${stockLocation1.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
).data
|
||||
|
||||
expect(reservationsResponseAfterDelete.count).toEqual(0)
|
||||
|
||||
const levelsResponseAfterDelete = (
|
||||
await api.get(
|
||||
`/admin/inventory-items/${inventoryItem1.id}/location-levels?location_id[]=${stockLocation1.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
).data
|
||||
|
||||
expect(levelsResponseAfterDelete.count).toEqual(0)
|
||||
})
|
||||
|
||||
it("should remove the product variant associations when deleting an inventory item", async () => {
|
||||
|
||||
Reference in New Issue
Block a user