Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core-flows): fixes case where inventory attempts delete when input is empty #9156

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,38 @@ medusaIntegrationTestRunner({
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", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InventoryLevelDTO, InventoryTypes } from "@medusajs/types"
import {
createWorkflow,
when,
WorkflowData,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
Expand All @@ -22,12 +23,22 @@ export const bulkCreateDeleteLevelsWorkflow = createWorkflow(
(
input: WorkflowData<BulkCreateDeleteLevelsWorkflowInput>
): WorkflowResponse<InventoryLevelDTO[]> => {
deleteInventoryLevelsWorkflow.runAsStep({
input: {
$or: input.deletes,
},
when({ input }, ({ input }) => {
return !!input.deletes?.length
}).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 || [])
}
)
Loading