Feat: Medusa react price list (#1258)

* export everything from price lists in core

* medusa-js price list

* feat: add product list for price lists

* feat: add product list for price lists

* add price list to admin module

* add price list hooks initial

* refactor: product list controller

* fix: add integration test for price list products

* update types

* add tests for price lists

* update medusa react tests

* update update request for price lists

* Apply suggestions from code review

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>

* rename methods

* pr feedback

* list products from price list

* fix errors after merge

* update medusa react with medusa-js method name changes

* redo changes

* update hook names

* fix: routes in msw handler

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
Co-authored-by: Zakaria El Asri <zakaria.elas@gmail.com>
This commit is contained in:
Philip Korsholm
2022-04-03 20:48:49 +02:00
committed by GitHub
co-authored by Sebastian Rindom Zakaria El Asri
parent fb33dbaca3
commit b164977a19
24 changed files with 838 additions and 276 deletions
@@ -0,0 +1,139 @@
import {
useAdminCreatePriceList,
useAdminCreatePriceListPrices,
useAdminDeletePriceList,
useAdminDeletePriceListPrices,
useAdminUpdatePriceList,
} from "../../../../src"
import { renderHook } from "@testing-library/react-hooks"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
import { PriceListType } from "@medusajs/medusa/dist/types/price-list"
describe("useAdminCreatePriceList hook", () => {
test("creates a price list and returns it", async () => {
const priceList = {
name: "talked to customer",
type: PriceListType.SALE,
description: "test",
prices: [],
}
const { result, waitFor } = renderHook(() => useAdminCreatePriceList(), {
wrapper: createWrapper(),
})
result.current.mutate(priceList)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.price_list).toEqual(
expect.objectContaining({
...fixtures.get("price_list"),
...priceList,
})
)
})
})
describe("useAdminUpdatePriceList hook", () => {
test("updates a price list and returns it", async () => {
const priceList = {
name: "talked to customer",
type: PriceListType.SALE,
prices: [],
customer_groups: [],
}
const { result, waitFor } = renderHook(
() => useAdminUpdatePriceList(fixtures.get("price_list").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(priceList)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.price_list).toEqual(
expect.objectContaining({
...fixtures.get("price_list"),
...priceList,
})
)
})
})
describe("useAdminDeletePriceList hook", () => {
test("deletes a price list", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeletePriceList(fixtures.get("price_list").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("price_list").id,
deleted: true,
})
)
})
})
describe("useAdminDeletePriceListBatch hook", () => {
test("deletes a money amounts from price list", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeletePriceListPrices(fixtures.get("price_list").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ price_ids: [fixtures.get("money_amount").id] })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
ids: [fixtures.get("money_amount").id],
deleted: true,
})
)
})
})
describe("useAdminDeletePriceList hook", () => {
test("Adds prices to price list", async () => {
const { result, waitFor } = renderHook(
() => useAdminCreatePriceListPrices(fixtures.get("price_list").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ prices: [] })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
price_list: {
...fixtures.get("price_list"),
},
})
)
})
})
@@ -0,0 +1,35 @@
import { useAdminPriceList, useAdminPriceLists } from "../../../../src"
import { renderHook } from "@testing-library/react-hooks"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
describe("useAdminPriceLists hook", () => {
test("returns a list of price lists", async () => {
const priceLists = fixtures.list("price_list")
const { result, waitFor } = renderHook(() => useAdminPriceLists(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.price_lists).toEqual(priceLists)
})
})
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)
})
})