feat(medusa): add list location levels endpoint in api v2 (#6741)

This commit is contained in:
Philip Korsholm
2024-03-27 18:59:38 +01:00
committed by GitHub
parent cf3c9b13b5
commit ff84f749d5
4 changed files with 122 additions and 0 deletions
@@ -206,6 +206,80 @@ medusaIntegrationTestRunner({
)
})
describe("List inventory levels", () => {
let inventoryItemId
let stockLocation1Id
let stockLocation2Id
beforeEach(async () => {
const inventoryItem = await api.post(
`/admin/inventory-items`,
{ sku: "test-sku" },
adminHeaders
)
inventoryItemId = inventoryItem.data.inventory_item.id
const locationService = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const stockLocation1 = await locationService.create({
name: "loc-1",
})
stockLocation1Id = stockLocation1.id
const stockLocation2 = await locationService.create({
name: "loc-2",
})
stockLocation2Id = stockLocation2.id
await api.post(
`/admin/inventory-items/${inventoryItemId}/location-levels`,
{
location_id: stockLocation1Id,
stocked_quantity: 10,
},
adminHeaders
)
await api.post(
`/admin/inventory-items/${inventoryItemId}/location-levels`,
{
location_id: stockLocation2Id,
stocked_quantity: 15,
},
adminHeaders
)
})
it("should list the inventory levels", async () => {
const response = await api.get(
`/admin/inventory-items/${inventoryItemId}/location-levels`,
adminHeaders
)
expect(response.data).toEqual(
expect.objectContaining({
count: 2,
offset: 0,
limit: 50,
})
)
expect(response.data.inventory_levels).toHaveLength(2)
expect(response.data.inventory_levels).toEqual(
expect.arrayContaining([
expect.objectContaining({
location_id: stockLocation1Id,
stocked_quantity: 10,
}),
expect.objectContaining({
location_id: stockLocation2Id,
stocked_quantity: 15,
}),
])
)
})
})
describe("Update inventory item", () => {
let inventoryItemId
beforeEach(async () => {