feat(medusa-js, medusa-react, medusa): Prepare API for admin implementations (#3110)
********What********
Add `joinSalesChannels util to stock locations
Add the following endpoints to medusa-react
- inventory items
- mutations
- update
- delete
- update location level
- delete location level
- create location level
- queries
- list inventory items
- get inventory item
- list location levels
- Stock locations
- mutations
- create stock location
- update stock location
- delete stock location
- queries
- list stock locations
- get stock locatoin
- Variants
- queries
- get inventory
- Reservations
- mutations
- create reservation
- update reservation
- delete reservation
- queries
- list reservations
- get reservation
- sales channels
- mutations
- associate location with sc
- remove location association
**Why**
- Update clients to reflect new api endpoints in the core with inventory modules
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
co-authored by
Philip Korsholm
parent
121b42acfe
commit
12d304307a
@@ -0,0 +1,144 @@
|
||||
import {
|
||||
useAdminUpdateInventoryItem,
|
||||
useAdminDeleteInventoryItem,
|
||||
useAdminUpdateLocationLevel,
|
||||
useAdminDeleteLocationLevel,
|
||||
useAdminCreateLocationLevel,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminUpdateInventoryItem hook", () => {
|
||||
test("updates an inventory item", async () => {
|
||||
const payload = {
|
||||
sku: "test-sku",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateInventoryItem("inventory-item-id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "inventory-item-id",
|
||||
sku: "test-sku",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteInventoryItem hook", () => {
|
||||
test("Deletes an inventory item", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteInventoryItem("inventory-item-id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "inventory-item-id",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateLocationLevel hook", () => {
|
||||
test("Updates a location level", async () => {
|
||||
const payload = {
|
||||
incoming_quantity: 10,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateLocationLevel("inventory-item-id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ ...payload, stockLocationId: "location_id"})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "inventory-item-id",
|
||||
location_levels: [
|
||||
expect.objectContaining({
|
||||
incoming_quantity: 10,
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteLocationLevel hook", () => {
|
||||
test("removes a location level", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteLocationLevel("inventory-item-id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("location_id")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "inventory-item-id",
|
||||
location_levels: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateLocationLevel hook", () => {
|
||||
test("creates a location level", async () => {
|
||||
const payload = {
|
||||
location_id: "loc_1",
|
||||
incoming_quantity: 10,
|
||||
stocked_quantity: 10,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateLocationLevel("inventory-item-id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "inventory-item-id",
|
||||
location_levels: expect.arrayContaining([
|
||||
expect.objectContaining({ ...payload }),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
useAdminInventoryItem,
|
||||
useAdminInventoryItemLocationLevels,
|
||||
useAdminInventoryItems,
|
||||
useAdminPriceList,
|
||||
useAdminPriceLists,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminInventoryItems hook", () => {
|
||||
test("returns a list of inventory items", async () => {
|
||||
const inventoryItems = fixtures.list("inventory_item")
|
||||
const { result, waitFor } = renderHook(() => useAdminInventoryItems(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.inventory_items).toEqual(inventoryItems)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminInventoryItem hook", () => {
|
||||
test("returns a single inventory item", async () => {
|
||||
const inventoryItem = fixtures.get("inventory_item")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminInventoryItem(inventoryItem.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.inventory_item).toEqual(inventoryItem)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminInventoryItem hook", () => {
|
||||
test("returns a location levels for an inventory item", async () => {
|
||||
const inventoryItem = fixtures.get("inventory_item")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminInventoryItemLocationLevels(inventoryItem.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.inventory_item).toEqual(inventoryItem)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminPriceList hook", () => {
|
||||
test("returns a price list", async () => {
|
||||
const priceList = fixtures.get("price_list")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminPriceList(priceList.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.price_list).toEqual(priceList)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user