fix(core-flows): fixes case where inventory attempts delete when input is empty (#9156)
what: - when an empty array is passed to the workflow, it attempts to delete all inventory locations. This PR adds a conditional to prevent it from happening. RESOLVES CC-477 Fixes https://github.com/medusajs/medusa/issues/9154
This commit is contained in:
1 parent
175ca30f4f
commit
987d007ba8
2 files changed
+48
-5
No files matched your search
@@ -175,6 +175,38 @@ medusaIntegrationTestRunner({
|
|||||||
message: `Cannot remove Inventory Levels for ${stockLocation1.id} because there are stocked or reserved items at the locations`,
|
message: `Cannot remove Inventory Levels for ${stockLocation1.id} because there are stocked or reserved items at the locations`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should successfully add an inventory location", async () => {
|
||||||
|
await api.post(
|
||||||
|
`/admin/inventory-items/${inventoryItem1.id}/location-levels/${stockLocation1.id}`,
|
||||||
|
{ stocked_quantity: 10 },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/inventory-items/${inventoryItem1.id}/location-levels/batch`,
|
||||||
|
{ create: [{ location_id: stockLocation2.id }] },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { inventory_levels: inventoryLevels },
|
||||||
|
} = await api.get(
|
||||||
|
`/admin/inventory-items/${inventoryItem1.id}/location-levels`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(inventoryLevels).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
location_id: stockLocation1.id,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
location_id: stockLocation2.id,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("DELETE /admin/inventory-items/:id/location-levels/:id", () => {
|
describe("DELETE /admin/inventory-items/:id/location-levels/:id", () => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { InventoryLevelDTO, InventoryTypes } from "@medusajs/types"
|
import { InventoryLevelDTO, InventoryTypes } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
|
when,
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
@@ -22,12 +23,22 @@ export const bulkCreateDeleteLevelsWorkflow = createWorkflow(
|
|||||||
(
|
(
|
||||||
input: WorkflowData<BulkCreateDeleteLevelsWorkflowInput>
|
input: WorkflowData<BulkCreateDeleteLevelsWorkflowInput>
|
||||||
): WorkflowResponse<InventoryLevelDTO[]> => {
|
): WorkflowResponse<InventoryLevelDTO[]> => {
|
||||||
deleteInventoryLevelsWorkflow.runAsStep({
|
when({ input }, ({ input }) => {
|
||||||
input: {
|
return !!input.deletes?.length
|
||||||
$or: input.deletes,
|
}).then(() => {
|
||||||
},
|
deleteInventoryLevelsWorkflow.runAsStep({
|
||||||
|
input: {
|
||||||
|
$or: input.deletes,
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return new WorkflowResponse(createInventoryLevelsStep(input.creates))
|
const created = when({ input }, ({ input }) => {
|
||||||
|
return !!input.creates?.length
|
||||||
|
}).then(() => {
|
||||||
|
return createInventoryLevelsStep(input.creates)
|
||||||
|
})
|
||||||
|
|
||||||
|
return new WorkflowResponse(created || [])
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Reference in new issue
Block a user