chore(core-flows,inventory,types,medusa): add fixes to inventory module + location levels api (#7629)
what: - santizes inputs to prevent reserved_quantity from being updated directly - inventory items create api can create location levels - add validation to update quantity of reservation items - general cleanup RESOLVES CORE-2254
This commit is contained in:
@@ -612,6 +612,38 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create inventory items along with location levels", async () => {
|
||||
const response = await api.post(
|
||||
`/admin/inventory-items?fields=*location_levels`,
|
||||
{
|
||||
sku: "test-sku",
|
||||
location_levels: [
|
||||
{
|
||||
location_id: stockLocation1.id,
|
||||
stocked_quantity: 20,
|
||||
incoming_quantity: 40,
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
sku: "test-sku",
|
||||
location_levels: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
inventory_item_id: expect.any(String),
|
||||
stocked_quantity: 20,
|
||||
incoming_quantity: 40,
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/inventory-items/:id", () => {
|
||||
|
||||
@@ -88,16 +88,25 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should throw if available quantity is less than reservation quantity", async () => {
|
||||
const payload = {
|
||||
quantity: 100000,
|
||||
quantity: 10000,
|
||||
inventory_item_id: inventoryItem1.id,
|
||||
line_item_id: "line-item-id",
|
||||
location_id: stockLocation1.id,
|
||||
}
|
||||
|
||||
const res = await api
|
||||
.post(`/admin/reservations`, payload, adminHeaders)
|
||||
.post(
|
||||
`/admin/reservations?fields=*inventory_item.location_levels`,
|
||||
payload,
|
||||
adminHeaders
|
||||
)
|
||||
.catch((err) => err)
|
||||
|
||||
const res1 = await api.get(
|
||||
`/admin/inventory-items/${inventoryItem1.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(res.response.status).toBe(400)
|
||||
expect(res.response.data).toEqual({
|
||||
type: "not_allowed",
|
||||
@@ -133,8 +142,7 @@ medusaIntegrationTestRunner({
|
||||
reservationId = reservationResponse.data.reservation.id
|
||||
})
|
||||
|
||||
// TODO: Implement this on the module
|
||||
it.skip("should throw if available quantity is less than reservation quantity", async () => {
|
||||
it("should throw if available quantity is less than reservation quantity", async () => {
|
||||
const payload = { quantity: 100000 }
|
||||
const res = await api
|
||||
.post(`/admin/reservations/${reservationId}`, payload, adminHeaders)
|
||||
|
||||
Reference in New Issue
Block a user