* add: medusa admin hooks + tests * fix: remove unneeded props * fix: deps * fix: deps * fix: deps * fix: failing tests * fix: failing tests * fix: query key * add: yarn workspaces * fix: linting medusa-react * fix: add prepare script * fix: buildOptions * fix: useAdminShippingOptions query * fix: use qs instead for query params (#1019) * fix: formatting * debug: ci pipeline * debug: log node_modules structure * debug: use lerna bootstrap * debug: update node version * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: add explicit build step * fix: jsdoc * debug: run build step * debug: fix build errors * debug: add build step to integration tests * fix: failing test * cleanup Co-authored-by: Sebastian Rindom <seb@medusajs.com> Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import { rest } from "msw"
|
|
import { server } from "../../../../mocks/server"
|
|
import { useShippingOptions, useCartShippingOptions } from "../../../../src/"
|
|
import { renderHook } from "@testing-library/react-hooks"
|
|
import { fixtures } from "../../../../mocks/data"
|
|
import { createWrapper } from "../../../utils"
|
|
|
|
describe("useShippingOptions hook", () => {
|
|
test("returns a list of shipping options", async () => {
|
|
const shippingOptions = fixtures.list("shipping_option", 5)
|
|
const { result, waitFor } = renderHook(() => useShippingOptions(), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.response.status).toEqual(200)
|
|
expect(result.current.shipping_options).toEqual(shippingOptions)
|
|
})
|
|
|
|
test("when shipping options params are provided, then they should be sent as query params", async () => {
|
|
const shippingOptions = fixtures.list("shipping_option")
|
|
|
|
server.use(
|
|
rest.get("/store/shipping-options/", (req, res, ctx) => {
|
|
const product_ids = req.url.searchParams.get("product_ids")
|
|
const is_return = req.url.searchParams.get("is_return")
|
|
const region_id = req.url.searchParams.get("region_id")
|
|
|
|
expect({
|
|
product_ids,
|
|
is_return,
|
|
region_id,
|
|
}).toEqual({
|
|
product_ids: "1,2,3",
|
|
is_return: "false",
|
|
region_id: "test-region",
|
|
})
|
|
|
|
return res(
|
|
ctx.status(200),
|
|
ctx.json({
|
|
shipping_options: fixtures.list("shipping_option"),
|
|
})
|
|
)
|
|
})
|
|
)
|
|
|
|
const { result, waitFor } = renderHook(
|
|
() =>
|
|
useShippingOptions({
|
|
product_ids: "1,2,3",
|
|
is_return: "false",
|
|
region_id: "test-region",
|
|
}),
|
|
{
|
|
wrapper: createWrapper(),
|
|
}
|
|
)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.response.status).toEqual(200)
|
|
expect(result.current.shipping_options).toEqual(shippingOptions)
|
|
})
|
|
})
|
|
|
|
describe("useCartShippingOptions hook", () => {
|
|
test("success", async () => {
|
|
const cartShippingOptions = fixtures.list("shipping_option")
|
|
const { result, waitFor } = renderHook(
|
|
() => useCartShippingOptions("cart_test"),
|
|
{
|
|
wrapper: createWrapper(),
|
|
}
|
|
)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.response.status).toEqual(200)
|
|
expect(result.current.shipping_options).toEqual(cartShippingOptions)
|
|
})
|
|
})
|