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,88 @@
|
||||
import {
|
||||
useAdminCreateShippingProfile,
|
||||
useAdminUpdateShippingProfile,
|
||||
useAdminDeleteShippingProfile,
|
||||
useAdminCreateReservation,
|
||||
useAdminUpdateReservation,
|
||||
useAdminDeleteReservation,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateShippingProfile hook", () => {
|
||||
test("creates a shipping profile and returns it", async () => {
|
||||
const reservationPayload = {
|
||||
location_id: "loc_1",
|
||||
inventory_item_id: "inv_1",
|
||||
quantity: 2,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateReservation(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(reservationPayload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.reservation).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("reservation"),
|
||||
...reservationPayload,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateShippingProfile hook", () => {
|
||||
test("updates a shipping profile and returns it", async () => {
|
||||
const reservationPayload = {
|
||||
quantity: 3,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateReservation(fixtures.get("reservation").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(reservationPayload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.reservation).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("reservation"),
|
||||
quantity: 3,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteShippingProfile hook", () => {
|
||||
test("deletes a shipping profile", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteReservation(fixtures.get("reservation").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: fixtures.get("reservation").id,
|
||||
object: "reservation",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminReservation, useAdminReservations } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminShippingProfiles hook", () => {
|
||||
test("returns a list of shipping profiles", async () => {
|
||||
const reservations = fixtures.list("reservation")
|
||||
const { result, waitFor } = renderHook(() => useAdminReservations(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.reservations).toEqual(reservations)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminShippingProfile hook", () => {
|
||||
test("returns a shipping profile", async () => {
|
||||
const reservation = fixtures.get("reservation")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminReservation(reservation.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.reservation).toEqual(reservation)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user