feat(core-flows,types,medusa): validate deleting location level when quantities exist (#9086)

what:

- adds validation in workflow to prevent deleting a location level when reserved or stocked quantity exists
- disabled delete button when quantities exist
- consolidate delete workflows

<img width="1079" alt="Screenshot 2024-09-10 at 16 39 02" src="https://github.com/user-attachments/assets/cf1f4b2e-75ea-4f7c-9b97-24622396c632">

RESOLVES CC-120
This commit is contained in:
Riqwan Thamir
2024-09-10 17:59:03 +00:00
committed by GitHub
parent 4bf42f7889
commit c097931469
8 changed files with 108 additions and 87 deletions
@@ -128,7 +128,7 @@ medusaIntegrationTestRunner({
`/admin/inventory-items/${inventoryItem1.id}/location-levels`,
{
location_id: stockLocation1.id,
stocked_quantity: 10,
stocked_quantity: 0,
},
adminHeaders
)
@@ -138,11 +138,7 @@ medusaIntegrationTestRunner({
const result = await api.post(
`/admin/inventory-items/${inventoryItem1.id}/location-levels/batch`,
{
create: [
{
location_id: "location_2",
},
],
create: [{ location_id: "location_2" }],
delete: [stockLocation1.id],
},
adminHeaders
@@ -157,6 +153,28 @@ medusaIntegrationTestRunner({
expect(levelsListResult.status).toEqual(200)
expect(levelsListResult.data.inventory_levels).toHaveLength(1)
})
it("should not delete an inventory location level when there is stocked items", async () => {
await api.post(
`/admin/inventory-items/${inventoryItem1.id}/location-levels/${stockLocation1.id}`,
{ stocked_quantity: 10 },
adminHeaders
)
const { response } = await api
.post(
`/admin/inventory-items/${inventoryItem1.id}/location-levels/batch`,
{ delete: [stockLocation1.id] },
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(400)
expect(response.data).toEqual({
type: "not_allowed",
message: `Cannot remove Inventory Levels for ${stockLocation1.id} because there are stocked or reserved items at the locations`,
})
})
})
describe("DELETE /admin/inventory-items/:id/location-levels/:id", () => {
@@ -165,7 +183,7 @@ medusaIntegrationTestRunner({
`/admin/inventory-items/${inventoryItem1.id}/location-levels`,
{
location_id: stockLocation1.id,
stocked_quantity: 10,
stocked_quantity: 0,
},
adminHeaders
)
@@ -187,6 +205,12 @@ medusaIntegrationTestRunner({
})
it("should fail delete an inventory location level with reservations", async () => {
await api.post(
`/admin/inventory-items/${inventoryItem1.id}/location-levels/${stockLocation1.id}`,
{ stocked_quantity: 10 },
adminHeaders
)
await api.post(
`/admin/reservations`,
{
@@ -621,11 +645,6 @@ medusaIntegrationTestRunner({
)
).data.reservation
await api.delete(
`/admin/inventory-items/${inventoryItem1.id}/location-levels/${item.location_levels[0].id}`,
adminHeaders
)
await api.delete(
`/admin/reservations/${reservation.id}`,
adminHeaders
@@ -639,7 +658,7 @@ medusaIntegrationTestRunner({
expect(response.data.inventory_item).toEqual(
expect.objectContaining({
id: inventoryItem1.id,
stocked_quantity: 10,
stocked_quantity: 20,
reserved_quantity: 1,
})
)