feat: medusa-react admin hooks (#978)
* 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>
This commit is contained in:
209 files changed
+27917
-2727
No files matched your search
@@ -13,7 +13,7 @@ describe("useBag hook", () => {
|
||||
const { setCart } = result.current
|
||||
|
||||
act(() => {
|
||||
setCart(fixtures.get("cart") as unknown as Cart)
|
||||
setCart((fixtures.get("cart") as unknown) as Cart)
|
||||
})
|
||||
|
||||
const { cart, totalItems } = result.current
|
||||
@@ -48,10 +48,10 @@ describe("useBag hook", () => {
|
||||
const { result, waitFor } = renderHook(() => useCart(), {
|
||||
wrapper: createCartWrapper(),
|
||||
initialProps: {
|
||||
initialCartState: {
|
||||
initialCartState: ({
|
||||
...fixtures.get("cart"),
|
||||
id: "test-cart",
|
||||
} as unknown as Cart,
|
||||
} as unknown) as Cart,
|
||||
},
|
||||
})
|
||||
const { startCheckout } = result.current
|
||||
@@ -77,10 +77,10 @@ describe("useBag hook", () => {
|
||||
const { result, waitFor } = renderHook(() => useCart(), {
|
||||
wrapper: createCartWrapper(),
|
||||
initialProps: {
|
||||
initialCartState: {
|
||||
initialCartState: ({
|
||||
...fixtures.get("cart"),
|
||||
id: "test-cart",
|
||||
} as unknown as Cart,
|
||||
} as unknown) as Cart,
|
||||
},
|
||||
})
|
||||
const { updateCart } = result.current
|
||||
@@ -109,10 +109,10 @@ describe("useBag hook", () => {
|
||||
const { result, waitFor } = renderHook(() => useCart(), {
|
||||
wrapper: createCartWrapper(),
|
||||
initialProps: {
|
||||
initialCartState: {
|
||||
initialCartState: ({
|
||||
...fixtures.get("cart"),
|
||||
id: "test-cart",
|
||||
} as unknown as Cart,
|
||||
} as unknown) as Cart,
|
||||
},
|
||||
})
|
||||
const { addShippingMethod } = result.current
|
||||
@@ -140,10 +140,10 @@ describe("useBag hook", () => {
|
||||
const { result, waitFor } = renderHook(() => useCart(), {
|
||||
wrapper: createCartWrapper(),
|
||||
initialProps: {
|
||||
initialCartState: {
|
||||
initialCartState: ({
|
||||
...fixtures.get("cart"),
|
||||
id: "test-cart",
|
||||
} as unknown as Cart,
|
||||
} as unknown) as Cart,
|
||||
},
|
||||
})
|
||||
const { pay } = result.current
|
||||
@@ -171,7 +171,7 @@ describe("useBag hook", () => {
|
||||
const { result, waitFor } = renderHook(() => useCart(), {
|
||||
wrapper: createCartWrapper(),
|
||||
initialProps: {
|
||||
initialCartState: fixtures.get("cart") as unknown as Cart,
|
||||
initialCartState: (fixtures.get("cart") as unknown) as Cart,
|
||||
},
|
||||
})
|
||||
const { completeCheckout } = result.current
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useAdminDeleteSession, useAdminLogin } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminLogin hook", () => {
|
||||
test("logs in a user", async () => {
|
||||
const payload = {
|
||||
email: "lebron@james.com",
|
||||
password: "supersecure",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminLogin(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.user).toEqual(fixtures.get("user"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteSession hook", () => {
|
||||
test("deletes a collection", async () => {
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteSession(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useAdminGetSession } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminGetSession hook", () => {
|
||||
test("returns the authenticated user", async () => {
|
||||
const user = fixtures.get("user")
|
||||
const { result, waitFor } = renderHook(() => useAdminGetSession(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.user).toEqual(user)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,162 @@
|
||||
import {
|
||||
useAdminCancelClaimFulfillment,
|
||||
useAdminCreateClaim,
|
||||
useAdminCancelClaim,
|
||||
useAdminUpdateClaim,
|
||||
useAdminFulfillClaim,
|
||||
useAdminCreateClaimShipment,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateClaim hook", () => {
|
||||
test("creates a claim for an order", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
|
||||
const claim = {
|
||||
type: "refund" as const,
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateClaim(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(claim)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateClaim hook", () => {
|
||||
test("updates a claim for an order", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const claimId = "test-claim"
|
||||
const claim = {
|
||||
shipping_method: [
|
||||
{
|
||||
option_id: "test-so",
|
||||
price: 1000,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateClaim(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate({
|
||||
claim_id: claimId,
|
||||
...claim,
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminFulfillClaim hook", () => {
|
||||
test("fulfills a claim", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const claimId = "test-claim"
|
||||
const payload = {
|
||||
no_notification: true,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminFulfillClaim(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
claim_id: claimId,
|
||||
...payload,
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateClaimShipment hook", () => {
|
||||
test("creates a claim shipment", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const claimId = "test-claim"
|
||||
const payload = {
|
||||
fulfillment_id: "test-id",
|
||||
tracking_numbers: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateClaimShipment(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
claim_id: claimId,
|
||||
...payload,
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelClaim hook", () => {
|
||||
test("cancels a claim for an order", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const claimId = "test-claim"
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCancelClaim(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(claimId)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelClaimFulfillment hook", () => {
|
||||
test("cancels a claim's fulfillment", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const claimId = "test-claim"
|
||||
const fulfillmentId = "test-ful"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCancelClaimFulfillment(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ claim_id: claimId, fulfillment_id: fulfillmentId })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
useAdminCreateCollection,
|
||||
useAdminUpdateCollection,
|
||||
useAdminDeleteCollection,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateCollection hook", () => {
|
||||
test("creates a collection and returns it", async () => {
|
||||
const collection = {
|
||||
title: "test_collection",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateCollection(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(collection)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.collection).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("product_collection"),
|
||||
...collection,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateCollection hook", () => {
|
||||
test("updates a collection and returns it", async () => {
|
||||
const collection = {
|
||||
title: "update_collection",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateCollection(fixtures.get("product_collection").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(collection)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.collection).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("product_collection"),
|
||||
...collection,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteCollection hook", () => {
|
||||
test("deletes a collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteCollection(fixtures.get("product_collection").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("product_collection").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminCollection, useAdminCollections } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCollections hook", () => {
|
||||
test("returns a list of collections", async () => {
|
||||
const collections = fixtures.list("product_collection")
|
||||
const { result, waitFor } = renderHook(() => useAdminCollections(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.collections).toEqual(collections)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCollection hook", () => {
|
||||
test("returns a collection", async () => {
|
||||
const collection = fixtures.get("product_collection")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCollection(collection.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.collection).toEqual(collection)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import {
|
||||
useAdminCreateCustomer,
|
||||
useAdminUpdateCustomer,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateCustomer hook", () => {
|
||||
test("creates a customer and returns it", async () => {
|
||||
const customer = {
|
||||
email: "lebron@james.com",
|
||||
first_name: "Lebron",
|
||||
last_name: "James",
|
||||
password: "password",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateCustomer(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(customer)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.customer).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("customer"),
|
||||
...customer,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateCustomer hook", () => {
|
||||
test("updates a customer and returns it", async () => {
|
||||
const customer = {
|
||||
email: "lebron@james.com",
|
||||
first_name: "Lebron",
|
||||
last_name: "James",
|
||||
password: "password",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateCustomer(fixtures.get("customer").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(customer)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.customer).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("customer"),
|
||||
...customer,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminCustomer, useAdminCustomers } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCustomers hook", () => {
|
||||
test("returns a list of customers", async () => {
|
||||
const customers = fixtures.list("customer")
|
||||
const { result, waitFor } = renderHook(() => useAdminCustomers(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.customers).toEqual(customers)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCustomer hook", () => {
|
||||
test("returns a customer", async () => {
|
||||
const customer = fixtures.get("customer")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCustomer(customer.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.customer).toEqual(customer)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,232 @@
|
||||
import {
|
||||
useAdminCreateDiscount,
|
||||
useAdminUpdateDiscount,
|
||||
useAdminDeleteDiscount,
|
||||
useAdminDiscountAddRegion,
|
||||
useAdminDiscountAddValidProduct,
|
||||
useAdminDiscountRemoveRegion,
|
||||
useAdminDiscountRemoveValidProduct,
|
||||
useAdminCreateDynamicDiscountCode,
|
||||
useAdminDeleteDynamicDiscountCode,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateDiscount hook", () => {
|
||||
test("creates a discount and returns it", async () => {
|
||||
const discount = {
|
||||
code: "DISC",
|
||||
rule: {
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateDiscount(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(discount)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("discount"),
|
||||
...discount,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateDiscount hook", () => {
|
||||
test("updates a discount and returns it", async () => {
|
||||
const discount = {
|
||||
code: "SUMMER10",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateDiscount(fixtures.get("discount").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(discount)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("discount"),
|
||||
...discount,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteDiscount hook", () => {
|
||||
test("updates a discount and returns it", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteDiscount(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,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountAddRegion hook", () => {
|
||||
test("adds a region to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountAddRegion(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-region")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountAddValidProduct hook", () => {
|
||||
test("adds a product to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountAddValidProduct(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-product")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateDynamicDiscountCode hook", () => {
|
||||
test("creates a dynamic discount code", async () => {
|
||||
const discount = {
|
||||
code: "LUCKY10",
|
||||
usage_limit: 10,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateDynamicDiscountCode(fixtures.get("discount").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(discount)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("discount"),
|
||||
...discount,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountRemoveRegion hook", () => {
|
||||
test("adds a region to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountRemoveRegion(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-region")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountRemoveValidProduct hook", () => {
|
||||
test("adds a product to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountRemoveValidProduct(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-product")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteDynamicDiscountCode hook", () => {
|
||||
test("creates a dynamic discount code", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteDynamicDiscountCode(fixtures.get("discount").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("LUCKY10")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
useAdminDiscount,
|
||||
useAdminDiscounts,
|
||||
useAdminGetDiscountByCode,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminDiscounts hook", () => {
|
||||
test("returns a list of discounts", async () => {
|
||||
const discounts = fixtures.list("discount")
|
||||
const { result, waitFor } = renderHook(() => useAdminDiscounts(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.discounts).toEqual(discounts)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminGetDiscountByCode hook", () => {
|
||||
test("retrieves a discount by discount code", async () => {
|
||||
const discount = fixtures.get("discount")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminGetDiscountByCode("10DISC"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.discount).toEqual(discount)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscount hook", () => {
|
||||
test("returns a discount", async () => {
|
||||
const discount = fixtures.get("discount")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscount(discount.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.discount).toEqual(discount)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
useAdminCreateDraftOrder,
|
||||
useAdminUpdateDraftOrder,
|
||||
useAdminDeleteDraftOrder,
|
||||
useAdminDraftOrderAddLineItem,
|
||||
useAdminDraftOrderRegisterPayment,
|
||||
useAdminDraftOrderRemoveLineItem,
|
||||
useAdminDraftOrderUpdateLineItem,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateDraftOrder hook", () => {
|
||||
test("creates a draft order and returns it", async () => {
|
||||
const draftOrder = {
|
||||
email: "lebron@james.com",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateDraftOrder(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(draftOrder)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.draft_order).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("draft_order"),
|
||||
...draftOrder,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateDraftOrder hook", () => {
|
||||
test("updates a draft order and returns it", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
const draftOrder = {
|
||||
country_code: "dk",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateDraftOrder(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(draftOrder)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.draft_order).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("draft_order"),
|
||||
...draftOrder,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteDraftOrder hook", () => {
|
||||
test("deletes a draft order", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteDraftOrder(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,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDraftOrderAddLineItem hook", () => {
|
||||
test("adds a line item to a draft order", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
const lineItem = {
|
||||
quantity: 2,
|
||||
variant_id: "test-variant",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDraftOrderAddLineItem(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(lineItem)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDraftOrderUpdateLineItem hook", () => {
|
||||
test("updates a draft order's line item", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
const lineItemId = "test-li"
|
||||
const newLineItem = {
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDraftOrderUpdateLineItem(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
item_id: lineItemId,
|
||||
...newLineItem,
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDraftOrderRemoveLineItem hook", () => {
|
||||
test("delete a draft order's line item", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
const lineItemId = "test-li"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDraftOrderRemoveLineItem(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(lineItemId)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDraftOrderRegisterPayment hook", () => {
|
||||
test("marks a draft order as paid", async () => {
|
||||
const id = fixtures.get("draft_order").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDraftOrderRegisterPayment(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminDraftOrder, useAdminDraftOrders } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminDraftOrders hook", () => {
|
||||
test("returns a list of draft orders", async () => {
|
||||
const draftOrders = fixtures.list("draft_order")
|
||||
const { result, waitFor } = renderHook(() => useAdminDraftOrders(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.draft_orders).toEqual(draftOrders)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDraftOrder hook", () => {
|
||||
test("returns a draft order", async () => {
|
||||
const draftOrder = fixtures.get("draft_order")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDraftOrder(draftOrder.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.draft_order).toEqual(draftOrder)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
useAdminCreateGiftCard,
|
||||
useAdminUpdateGiftCard,
|
||||
useAdminDeleteGiftCard,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateGiftCard hook", () => {
|
||||
test("creates a gift card and returns it", async () => {
|
||||
const gc = {
|
||||
value: 1000,
|
||||
region_id: "test-id",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateGiftCard(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(gc)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.gift_card).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("gift_card"),
|
||||
...gc,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateGiftCard hook", () => {
|
||||
test("updates a gift card and returns it", async () => {
|
||||
const gc = {
|
||||
value: 2000,
|
||||
region_id: "test-region",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateGiftCard(fixtures.get("gift_card").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(gc)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.gift_card).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("gift_card"),
|
||||
...gc,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteGiftCard hook", () => {
|
||||
test("deletes a gift card", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteGiftCard(fixtures.get("gift_card").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("gift_card").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminGiftCard, useAdminGiftCards } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminGiftCards hook", () => {
|
||||
test("returns a list of giftCards", async () => {
|
||||
const giftCards = fixtures.list("gift_card")
|
||||
const { result, waitFor } = renderHook(() => useAdminGiftCards(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.gift_cards).toEqual(giftCards)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminGiftCard hook", () => {
|
||||
test("returns a giftCard", async () => {
|
||||
const giftCard = fixtures.get("gift_card")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminGiftCard(giftCard.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.gift_card).toEqual(giftCard)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,90 @@
|
||||
import {
|
||||
useAdminAcceptInvite,
|
||||
useAdminCreateInvite,
|
||||
useAdminDeleteInvite,
|
||||
useAdminResendInvite,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminAcceptInvite hook", () => {
|
||||
test("accepts an invite", async () => {
|
||||
const payload = {
|
||||
token: "test-token",
|
||||
user: {
|
||||
first_name: "zak",
|
||||
last_name: "medusa",
|
||||
password: "test-password",
|
||||
},
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminAcceptInvite(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateInvite hook", () => {
|
||||
test("creates an invite", async () => {
|
||||
const payload = {
|
||||
user: "test-id",
|
||||
role: "admin" as const,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateInvite(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteInvite hook", () => {
|
||||
test("deletes an invite", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteInvite("test-invite"),
|
||||
{
|
||||
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: "test-invite",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminResend hook", () => {
|
||||
test("resends an invite", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminResendInvite("test-invite"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useAdminInvites } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminInvites hook", () => {
|
||||
test("returns a list of invites", async () => {
|
||||
const invites = fixtures.list("invite")
|
||||
const { result, waitFor } = renderHook(() => useAdminInvites(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.invites).toEqual(invites)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
useAdminCreateNote,
|
||||
useAdminUpdateNote,
|
||||
useAdminDeleteNote,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateNote hook", () => {
|
||||
test("creates a note and returns it", async () => {
|
||||
const note = {
|
||||
value: "talked to customer",
|
||||
resource_id: "test-swap",
|
||||
resource_type: "swap",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateNote(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(note)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.note).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("note"),
|
||||
...note,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateNote hook", () => {
|
||||
test("updates a note and returns it", async () => {
|
||||
const note = {
|
||||
value: "problem with the supplier",
|
||||
resource_id: "test-return",
|
||||
resource_type: "return",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateNote(fixtures.get("note").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(note)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.note).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("note"),
|
||||
...note,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteNote hook", () => {
|
||||
test("deletes a note", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteNote(fixtures.get("note").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("note").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAdminNote, useAdminNotes } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminNotes hook", () => {
|
||||
test("returns a list of notes", async () => {
|
||||
const notes = fixtures.list("note")
|
||||
const { result, waitFor } = renderHook(() => useAdminNotes(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.notes).toEqual(notes)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminNote hook", () => {
|
||||
test("returns a note", async () => {
|
||||
const note = fixtures.get("note")
|
||||
const { result, waitFor } = renderHook(() => useAdminNote(note.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.note).toEqual(note)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAdminResendNotification } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminResendNotification hook", () => {
|
||||
test("resends a notification", async () => {
|
||||
const notif = {
|
||||
to: "me@me.me",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminResendNotification("test-notification"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(notif)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.notification).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("notification"),
|
||||
...notif,
|
||||
id: "test-notification",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { useAdminNotifications } from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminNotifications hook", () => {
|
||||
test("returns a list of notifications", async () => {
|
||||
const notifications = fixtures.list("notification")
|
||||
const { result, waitFor } = renderHook(() => useAdminNotifications(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.notifications).toEqual(notifications)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,312 @@
|
||||
import {
|
||||
useAdminCreateOrder,
|
||||
useAdminUpdateOrder,
|
||||
useAdminDeleteOrderMetadata,
|
||||
useAdminCompleteOrder,
|
||||
useAdminCapturePayment,
|
||||
useAdminRefundPayment,
|
||||
useAdminCreateShipment,
|
||||
useAdminCancelOrder,
|
||||
useAdminAddShippingMethod,
|
||||
useAdminArchiveOrder,
|
||||
useAdminCreateFulfillment,
|
||||
useAdminCancelFulfillment,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateOrder hook", () => {
|
||||
test("creates a order and returns it", async () => {
|
||||
const order = {
|
||||
email: "lebron@james.com",
|
||||
billing_address: {
|
||||
company: "medusa",
|
||||
first_name: "Jane",
|
||||
last_name: "Medusan",
|
||||
address_1: "jane street",
|
||||
address_2: "2nd floor",
|
||||
city: "copenhagen",
|
||||
country_code: "dk",
|
||||
province: "copenhagen",
|
||||
postal_code: "382793",
|
||||
phone: "4897394",
|
||||
metadata: null,
|
||||
},
|
||||
shipping_address: {
|
||||
company: "medusa",
|
||||
first_name: "Jane",
|
||||
last_name: "Medusan",
|
||||
address_1: "jane street",
|
||||
address_2: "2nd floor",
|
||||
city: "copenhagen",
|
||||
country_code: "dk",
|
||||
province: "copenhagen",
|
||||
postal_code: "382793",
|
||||
phone: "4897394",
|
||||
metadata: null,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
region: "test-region",
|
||||
customer_id: "cus_test",
|
||||
payment_method: {
|
||||
provider_id: "test-pay",
|
||||
},
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateOrder(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(order)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("order"),
|
||||
...order,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateOrder hook", () => {
|
||||
test("updates a order and returns it", async () => {
|
||||
const order = {
|
||||
email: "medusa@medusa.com",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateOrder(fixtures.get("order").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(order)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("order"),
|
||||
...order,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelOrder hook", () => {
|
||||
test("cancels an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCancelOrder(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminArchiveOrder hook", () => {
|
||||
test("archives an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminArchiveOrder(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCompleteOrder hook", () => {
|
||||
test("completes an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCompleteOrder(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCapturePayment hook", () => {
|
||||
test("captures an order's payment", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCapturePayment(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRefundPayment hook", () => {
|
||||
test("captures an order's payment", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const payload = {
|
||||
amount: 100,
|
||||
reason: "wrong item",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminRefundPayment(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateShipment hook", () => {
|
||||
test("creates a shipment for an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const payload = {
|
||||
fulfillment_id: "test-ful",
|
||||
tracking_numbers: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateShipment(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminAddShippingMethod hook", () => {
|
||||
test("adds a shipping method to an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const payload = {
|
||||
price: 1000,
|
||||
option_id: "test-so",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminAddShippingMethod(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateFulfillment hook", () => {
|
||||
test("creates a fulfillment for an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const fulfillment = {
|
||||
items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateFulfillment(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(fulfillment)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelFulfillment hook", () => {
|
||||
test("cancels a fulfillment for an order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
const fulfillmentId = "test-ful"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCancelFulfillment(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(fulfillmentId)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteOrderMetadata hook", () => {
|
||||
test("remove metadata field on order", async () => {
|
||||
const id = fixtures.get("order").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteOrderMetadata(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("some_key")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAdminOrder, useAdminOrders } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminOrders hook", () => {
|
||||
test("returns a list of orders", async () => {
|
||||
const orders = fixtures.list("order")
|
||||
const { result, waitFor } = renderHook(() => useAdminOrders(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.orders).toEqual(orders)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminOrder hook", () => {
|
||||
test("returns a order", async () => {
|
||||
const order = fixtures.get("order")
|
||||
const { result, waitFor } = renderHook(() => useAdminOrder(order.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.order).toEqual(order)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,155 @@
|
||||
import {
|
||||
useAdminCreateProduct,
|
||||
useAdminUpdateProduct,
|
||||
useAdminDeleteProduct,
|
||||
useAdminCreateProductOption,
|
||||
useAdminDeleteProductOption,
|
||||
useAdminUpdateProductOption,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateProduct hook", () => {
|
||||
test("creates a product and returns it", async () => {
|
||||
const product = {
|
||||
title: "test-product",
|
||||
is_giftcard: false,
|
||||
discountable: false,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateProduct(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(product)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("product"),
|
||||
...product,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateProduct hook", () => {
|
||||
test("updates a product and returns it", async () => {
|
||||
const id = fixtures.get("product").id
|
||||
const product = {
|
||||
title: "test-product-1",
|
||||
images: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateProduct(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(product)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("product"),
|
||||
...product,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteProduct hook", () => {
|
||||
test("deletes a product", async () => {
|
||||
const id = fixtures.get("product").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteProduct(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,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateProductOption hook", () => {
|
||||
test("creates a product option", async () => {
|
||||
const productId = fixtures.get("product").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateProductOption(productId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
title: "color",
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(fixtures.get("product"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateProductOption hook", () => {
|
||||
test("updates a product option", async () => {
|
||||
const productId = fixtures.get("product").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateProductOption(productId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
title: "size",
|
||||
option_id: "test-option",
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(fixtures.get("product"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteProductOption hook", () => {
|
||||
test("deletes a product option", async () => {
|
||||
const productId = fixtures.get("product").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteProductOption(productId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-option")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data).toEqual(
|
||||
expect.objectContaining({
|
||||
option_id: "test-option",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
useAdminProduct,
|
||||
useAdminProducts,
|
||||
useAdminProductTags,
|
||||
useAdminProductTypes,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminProducts hook", () => {
|
||||
test("returns a list of products", async () => {
|
||||
const products = fixtures.list("product")
|
||||
const { result, waitFor } = renderHook(() => useAdminProducts(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.products).toEqual(products)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminProductTypes hook", () => {
|
||||
test("returns a list of product types", async () => {
|
||||
const types = fixtures.list("product_type")
|
||||
const { result, waitFor } = renderHook(() => useAdminProductTypes(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.types).toEqual(types)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminProductTags hook", () => {
|
||||
test("returns a list of product tags", async () => {
|
||||
const tags = fixtures.list("product_tag")
|
||||
const { result, waitFor } = renderHook(() => useAdminProductTags(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.tags).toEqual(tags)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminProduct hook", () => {
|
||||
test("returns a product", async () => {
|
||||
const product = fixtures.get("product")
|
||||
const { result, waitFor } = renderHook(() => useAdminProduct(product.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.product).toEqual(product)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,220 @@
|
||||
import {
|
||||
useAdminCreateRegion,
|
||||
useAdminUpdateRegion,
|
||||
useAdminDeleteRegion,
|
||||
useAdminSetRegionMetadata,
|
||||
useAdminDeleteRegionMetadata,
|
||||
useAdminRegionAddFulfillmentProvider,
|
||||
useAdminRegionDeleteFulfillmentProvider,
|
||||
useAdminRegionAddPaymentProvider,
|
||||
useAdminRegionDeletePaymentProvider,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateRegion hook", () => {
|
||||
test("creates a region and returns it", async () => {
|
||||
const region = {
|
||||
name: "test region",
|
||||
currency_code: "eur",
|
||||
tax_rate: 10,
|
||||
payment_providers: [],
|
||||
fulfillment_providers: [],
|
||||
countries: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateRegion(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(region)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("region"),
|
||||
...region,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateRegion hook", () => {
|
||||
test("updates a region and returns it", async () => {
|
||||
const region = {
|
||||
name: "Africa",
|
||||
}
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateRegion(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(region)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("region"),
|
||||
...region,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteRegion hook", () => {
|
||||
test("deletes a region", async () => {
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteRegion(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,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminSetRegionMetadata hook", () => {
|
||||
test("updates a region's metadata", async () => {
|
||||
const metadata = {
|
||||
key: "some_key",
|
||||
value: "some_value",
|
||||
}
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminSetRegionMetadata(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(metadata)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteRegionMetadata hook", () => {
|
||||
test("deletes a region's metadata", async () => {
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteRegionMetadata(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("some_key")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegionAddFulfillmentProvider hook", () => {
|
||||
test("adds a fulfillment provider to a region", async () => {
|
||||
const payload = {
|
||||
provider_id: "test-ful",
|
||||
}
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRegionAddFulfillmentProvider(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegionDeleteFulfillmentProvider hook", () => {
|
||||
test("deletes a region's fulfillment provider", async () => {
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRegionDeleteFulfillmentProvider(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-ful")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegionAddPaymentProvider hook", () => {
|
||||
test("adds a payment provider to a region", async () => {
|
||||
const payload = {
|
||||
provider_id: "test-pay",
|
||||
}
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRegionAddPaymentProvider(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegionDeletePaymentProvider hook", () => {
|
||||
test("deletes a region's payment provider", async () => {
|
||||
const id = fixtures.get("region").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRegionDeletePaymentProvider(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-pay")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.region).toEqual(fixtures.get("region"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
useAdminRegion,
|
||||
useAdminRegions,
|
||||
useAdminRegionFulfillmentOptions,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminRegions hook", () => {
|
||||
test("returns a list of regions", async () => {
|
||||
const regions = fixtures.list("region")
|
||||
const { result, waitFor } = renderHook(() => useAdminRegions(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.regions).toEqual(regions)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegion hook", () => {
|
||||
test("returns a region", async () => {
|
||||
const region = fixtures.get("region")
|
||||
const { result, waitFor } = renderHook(() => useAdminRegion(region.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.region).toEqual(region)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminRegionFulfillmentOptions hook", () => {
|
||||
test("returns a region's fulfillment options", async () => {
|
||||
const region = fixtures.get("region")
|
||||
const options = fixtures.get("fulfillment_option")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminRegionFulfillmentOptions(region.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.fulfillment_options).toEqual(options)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
useAdminCreateReturnReason,
|
||||
useAdminUpdateReturnReason,
|
||||
useAdminDeleteReturnReason,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateReturnReason hook", () => {
|
||||
test("creates a return reason and returns it", async () => {
|
||||
const rr = {
|
||||
value: "too_big",
|
||||
label: "Too big",
|
||||
description: "Shirt is too big in length",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateReturnReason(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(rr)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.return_reason).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("return_reason"),
|
||||
...rr,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateReturnReason hook", () => {
|
||||
test("updates a return reason and returns it", async () => {
|
||||
const rr = {
|
||||
value: "too_small",
|
||||
label: "Too small",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateReturnReason(fixtures.get("return_reason").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(rr)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.return_reason).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("return_reason"),
|
||||
...rr,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteReturnReason hook", () => {
|
||||
test("deletes a return reason", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteReturnReason(fixtures.get("return_reason").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("return_reason").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminReturnReason, useAdminReturnReasons } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminReturnReasons hook", () => {
|
||||
test("returns a list of return reasons", async () => {
|
||||
const returnReasons = fixtures.list("return_reason")
|
||||
const { result, waitFor } = renderHook(() => useAdminReturnReasons(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.return_reasons).toEqual(returnReasons)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminReturnReason hook", () => {
|
||||
test("returns a return reason", async () => {
|
||||
const returnReason = fixtures.get("return_reason")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminReturnReason(returnReason.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.return_reason).toEqual(returnReason)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useAdminCancelReturn, useAdminReceiveReturn } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCancel hook", () => {
|
||||
test("cancels a return", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCancelReturn("test-return"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminReceiveReturn hook", () => {
|
||||
test("marks a return as received", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminReceiveReturn("test-return"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.return).toEqual(fixtures.get("return"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { useAdminReturns } from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminReturns hook", () => {
|
||||
test("returns a list of returns", async () => {
|
||||
const returns = fixtures.list("return")
|
||||
const { result, waitFor } = renderHook(() => useAdminReturns(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.returns).toEqual(returns)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,96 @@
|
||||
import {
|
||||
useAdminCreateShippingOption,
|
||||
useAdminUpdateShippingOption,
|
||||
useAdminDeleteShippingOption,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateShippingOption hook", () => {
|
||||
test("creates a shipping option and returns it", async () => {
|
||||
const so = {
|
||||
name: "test-so",
|
||||
region_id: "test-region",
|
||||
provider_id: "test-provider",
|
||||
data: {},
|
||||
price_type: "flat",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateShippingOption(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(so)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.shipping_option).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("shipping_option"),
|
||||
...so,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateShippingOption hook", () => {
|
||||
test("updates a shipping option and returns it", async () => {
|
||||
const so = {
|
||||
name: "test-so",
|
||||
requirements: [
|
||||
{
|
||||
id: "test-so-req",
|
||||
type: "thing",
|
||||
amount: 500,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateShippingOption(fixtures.get("shipping_option").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(so)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.shipping_option).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("shipping_option"),
|
||||
...so,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteShippingOption hook", () => {
|
||||
test("deletes a shipping option", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteShippingOption(fixtures.get("shipping_option").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("shipping_option").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
useAdminShippingOption,
|
||||
useAdminShippingOptions,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminShippingOptions hook", () => {
|
||||
test("returns a list of shipping options", async () => {
|
||||
const shippingOptions = fixtures.list("shipping_option")
|
||||
const { result, waitFor } = renderHook(() => useAdminShippingOptions(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.shipping_options).toEqual(shippingOptions)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminShippingOption hook", () => {
|
||||
test("returns a shipping option", async () => {
|
||||
const shippingOption = fixtures.get("shipping_option")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminShippingOption(shippingOption.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.shipping_option).toEqual(shippingOption)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
useAdminCreateShippingProfile,
|
||||
useAdminUpdateShippingProfile,
|
||||
useAdminDeleteShippingProfile,
|
||||
} 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 sp = {
|
||||
name: "test-sp",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateShippingProfile(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(sp)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.shipping_profile).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("shipping_profile"),
|
||||
...sp,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateShippingProfile hook", () => {
|
||||
test("updates a shipping profile and returns it", async () => {
|
||||
const sp = {
|
||||
name: "test-sp",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateShippingProfile(fixtures.get("shipping_profile").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(sp)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.shipping_profile).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("shipping_profile"),
|
||||
...sp,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteShippingProfile hook", () => {
|
||||
test("deletes a shipping profile", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteShippingProfile(fixtures.get("shipping_profile").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("shipping_profile").id,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
useAdminShippingProfile,
|
||||
useAdminShippingProfiles,
|
||||
} 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 shippingProfiles = fixtures.list("shipping_profile")
|
||||
const { result, waitFor } = renderHook(() => useAdminShippingProfiles(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.shipping_profiles).toEqual(shippingProfiles)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminShippingProfile hook", () => {
|
||||
test("returns a shipping profile", async () => {
|
||||
const shippingProfile = fixtures.get("shipping_profile")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminShippingProfile(shippingProfile.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.shipping_profile).toEqual(shippingProfile)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
useAdminUpdateStore,
|
||||
useAdminAddStoreCurrency,
|
||||
useAdminDeleteStoreCurrency,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminUpdateStore hook", () => {
|
||||
test("updates a store", async () => {
|
||||
const store = {
|
||||
name: "medusa-store",
|
||||
swap_link_template: "template",
|
||||
payment_link_template: "payment",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateStore(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(store)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.store).toEqual({
|
||||
...fixtures.get("store"),
|
||||
...store,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminAddStoreCurrency hook", () => {
|
||||
test("adds a currency to the store", async () => {
|
||||
const { result, waitFor } = renderHook(() => useAdminAddStoreCurrency(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate("eur")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.store).toEqual(fixtures.get("store"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteStoreCurrency hook", () => {
|
||||
test("deletes a currency from the store", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteStoreCurrency(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("eur")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.store).toEqual(fixtures.get("store"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAdminStore, useAdminStorePaymentProviders } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminStore hook", () => {
|
||||
test("returns the store", async () => {
|
||||
const store = fixtures.get("store")
|
||||
const { result, waitFor } = renderHook(() => useAdminStore(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.store).toEqual(store)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminListPaymentProviders hook", () => {
|
||||
test("returns a list of the store's payment providers", async () => {
|
||||
const store = fixtures.get("store")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminStorePaymentProviders(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.payment_providers).toEqual(store.payment_providers)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
useAdminCreateSwap,
|
||||
useAdminReceiveSwap,
|
||||
useAdminFulfillSwap,
|
||||
useAdminCancelSwap,
|
||||
useAdminCreateSwapShipment,
|
||||
useAdminProcessSwapPayment,
|
||||
useAdminCancelSwapFulfillment,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateSwap hook", () => {
|
||||
test("creates a swap and returns the order", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swap = {
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "another-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateSwap(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(swap)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminReceiveSwap hook", () => {
|
||||
test("receives a swap", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
const payload = {
|
||||
items: [
|
||||
{
|
||||
item_id: "test_id",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminReceiveSwap(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate({ swap_id: swapId, ...payload })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminFulfillSwap hook", () => {
|
||||
test("receives a swap", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
const payload = {
|
||||
no_notification: false,
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminFulfillSwap(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate({ swap_id: swapId, ...payload })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateSwapShipment hook", () => {
|
||||
test("creates a swap shipment", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
const payload = {
|
||||
fulfillment_id: "test-ful",
|
||||
tracking_numbers: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateSwapShipment(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ swap_id: swapId, ...payload })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminProcessSwapPayment hook", () => {
|
||||
test("process a swap's payment", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminProcessSwapPayment(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(swapId)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelSwap hook", () => {
|
||||
test("cancels a swap", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCancelSwap(orderId), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(swapId)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelSwapFulfillment hook", () => {
|
||||
test("cancels a swap", async () => {
|
||||
const orderId = fixtures.get("order").id
|
||||
const swapId = "test-swap"
|
||||
const fulfillmentId = "test-ful"
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCancelSwapFulfillment(orderId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ swap_id: swapId, fulfillment_id: fulfillmentId })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order).toEqual(fixtures.get("order"))
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAdminSwap, useAdminSwaps } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminSwaps hook", () => {
|
||||
test("returns a list of swaps", async () => {
|
||||
const swaps = fixtures.list("swap")
|
||||
const { result, waitFor } = renderHook(() => useAdminSwaps(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.swaps).toEqual(swaps)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminSwap hook", () => {
|
||||
test("returns a swap", async () => {
|
||||
const swap = fixtures.get("swap")
|
||||
const { result, waitFor } = renderHook(() => useAdminSwap(swap.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.swap).toEqual(swap)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,129 @@
|
||||
import {
|
||||
useAdminCreateUser,
|
||||
useAdminUpdateUser,
|
||||
useAdminDeleteUser,
|
||||
useAdminResetPassword,
|
||||
useAdminSendResetPasswordToken,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateUser hook", () => {
|
||||
test("creates a user and returns it", async () => {
|
||||
const user = {
|
||||
email: "lebron@james.com",
|
||||
first_name: "Lebron",
|
||||
last_name: "James",
|
||||
role: "admin" as const,
|
||||
password: "test-password",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateUser(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(user)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.user).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("user"),
|
||||
...user,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateUser hook", () => {
|
||||
test("updates a user and returns it", async () => {
|
||||
const id = fixtures.get("user").id
|
||||
const user = {
|
||||
first_name: "Zack",
|
||||
last_name: "Medusa",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminUpdateUser(id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(user)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.user).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("user"),
|
||||
...user,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteUser hook", () => {
|
||||
test("deletes a user", async () => {
|
||||
const id = fixtures.get("user").id
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminDeleteUser(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,
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminSendResetPasswordToken hook", () => {
|
||||
test("sends a token to reset the password", async () => {
|
||||
const payload = {
|
||||
email: "admin@user.com",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminSendResetPasswordToken(),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminResetPassword hook", () => {
|
||||
test("reset the password", async () => {
|
||||
const payload = {
|
||||
token: "test-token",
|
||||
password: "new-password",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminResetPassword(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate(payload)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.user).toEqual(
|
||||
expect.objectContaining(fixtures.get("user"))
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAdminUser, useAdminUsers } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminUsers hook", () => {
|
||||
test("returns a list of users", async () => {
|
||||
const users = fixtures.list("user")
|
||||
const { result, waitFor } = renderHook(() => useAdminUsers(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.users).toEqual(users)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUser hook", () => {
|
||||
test("returns a user", async () => {
|
||||
const user = fixtures.get("user")
|
||||
const { result, waitFor } = renderHook(() => useAdminUser(user.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.user).toEqual(user)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,88 @@
|
||||
import {
|
||||
useAdminCreateVariant,
|
||||
useAdminUpdateVariant,
|
||||
useAdminDeleteVariant,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateVariant hook", () => {
|
||||
test("creates a variant and returns it", async () => {
|
||||
const variant = {
|
||||
title: "Test variant",
|
||||
inventory_quantity: 10,
|
||||
prices: [
|
||||
{
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
options: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminCreateVariant("test-product"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(variant)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(fixtures.get("product"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateVariant hook", () => {
|
||||
test("updates a variant and returns it", async () => {
|
||||
const variant = {
|
||||
title: "Example variant",
|
||||
inventory_quantity: 5,
|
||||
prices: [],
|
||||
options: [],
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateVariant("test-product"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
...variant,
|
||||
variant_id: "test-variant",
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.product).toEqual(fixtures.get("product"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteVariant hook", () => {
|
||||
test("deletes a variant", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeleteVariant("test-product"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-variant")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data).toEqual(
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useAdminVariants } from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminVariants hook", () => {
|
||||
test("returns a list of variants", async () => {
|
||||
const variants = fixtures.list("product_variant")
|
||||
const { result, waitFor } = renderHook(() => useAdminVariants(), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.variants).toEqual(variants)
|
||||
})
|
||||
})
|
||||
+3
-3
@@ -8,10 +8,10 @@ import {
|
||||
useSetPaymentSession,
|
||||
useDeletePaymentSession,
|
||||
useAddShippingMethodToCart,
|
||||
} from "./../../../src/"
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateCart hook", () => {
|
||||
test("creates a cart", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useGetCart } from "./../../../src/"
|
||||
import { useGetCart } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useGetCart hook", () => {
|
||||
test("returns a cart", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useCollections, useCollection } from "./../../../src/"
|
||||
import { useCollections, useCollection } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCollections hook", () => {
|
||||
test("returns a list of collections", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useCreateCustomer, useUpdateMe } from "./../../../src/"
|
||||
import { useCreateCustomer, useUpdateMe } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateCustomer hook", () => {
|
||||
test("creates a new customer", async () => {
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
import { rest } from "msw"
|
||||
import { server } from "./../../../mocks/server"
|
||||
import { useMeCustomer, useCustomerOrders } from "./../../../src/"
|
||||
import { server } from "../../../../mocks/server"
|
||||
import { useMeCustomer, useCustomerOrders } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useMeCustomer hook", () => {
|
||||
test("returns customer", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useGiftCard } from "./../../../src/"
|
||||
import { useGiftCard } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useGiftCard hook", () => {
|
||||
test("returns a gift card", async () => {
|
||||
+3
-3
@@ -2,10 +2,10 @@ import {
|
||||
useCreateLineItem,
|
||||
useUpdateLineItem,
|
||||
useDeleteLineItem,
|
||||
} from "./../../../src/"
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateLineItem hook", () => {
|
||||
test("creates a line item", async () => {
|
||||
+7
-7
@@ -1,10 +1,10 @@
|
||||
import { useOrderLookup } from "./../../../src/hooks/orders/queries"
|
||||
import { useOrders } from "../../../../src/hooks"
|
||||
import { rest } from "msw"
|
||||
import { server } from "./../../../mocks/server"
|
||||
import { useCartOrder, useOrder } from "./../../../src/"
|
||||
import { server } from "../../../../mocks/server"
|
||||
import { useCartOrder, useOrder } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useOrder hook", () => {
|
||||
test("returns an order", async () => {
|
||||
@@ -34,7 +34,7 @@ describe("useCartOrder hook", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("useOrderLookup hook", () => {
|
||||
describe("useOrders hook", () => {
|
||||
test("propagates the query params and returns an order", async () => {
|
||||
const order = fixtures.get("order")
|
||||
const displayId = 400,
|
||||
@@ -62,7 +62,7 @@ describe("useOrderLookup hook", () => {
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() =>
|
||||
useOrderLookup({
|
||||
useOrders({
|
||||
display_id: displayId,
|
||||
email: emailParam,
|
||||
}),
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { useProducts, useProduct } from "../../../src"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../mocks/data/index"
|
||||
import { useProducts, useProduct } from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { fixtures } from "../../../../mocks/data/index"
|
||||
|
||||
describe("useProducts hook", () => {
|
||||
test("gets a list of products", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { useRegion, useRegions } from "../../../src/"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { useRegion, useRegions } from "../../../../src/"
|
||||
|
||||
describe("useRegions hook", () => {
|
||||
test("success", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { useReturnReason, useReturnReasons } from "../../../src/"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { useReturnReason, useReturnReasons } from "../../../../src/"
|
||||
|
||||
describe("useReturnReasons hook", () => {
|
||||
test("returns a list of return reasons", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { useCreateReturn } from "../../../src"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { useCreateReturn } from "../../../../src"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateReturn hook", () => {
|
||||
test("creates a return", async () => {
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
import { rest } from "msw"
|
||||
import { server } from "./../../../mocks/server"
|
||||
import { useShippingOptions, useCartShippingOptions } from "../../../src/"
|
||||
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"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useShippingOptions hook", () => {
|
||||
test("returns a list of shipping options", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useCreateSwap } from "./../../../src/"
|
||||
import { useCreateSwap } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateSwap hook", () => {
|
||||
test("creates a return", async () => {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { useCartSwap } from "./../../../src/"
|
||||
import { useCartSwap } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../mocks/data"
|
||||
import { createWrapper } from "../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCartSwap hook", () => {
|
||||
test("returns a swap", async () => {
|
||||
@@ -45,7 +45,7 @@ describe("useSessionCart hook", () => {
|
||||
|
||||
act(() => {
|
||||
addItem({
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
})
|
||||
})
|
||||
@@ -70,14 +70,14 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant: {
|
||||
variant: ({
|
||||
...variant,
|
||||
id: "test-variant",
|
||||
} as unknown as ProductVariant,
|
||||
} as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
},
|
||||
]),
|
||||
@@ -120,14 +120,14 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 3,
|
||||
},
|
||||
{
|
||||
variant: {
|
||||
variant: ({
|
||||
...variant,
|
||||
id: "test-variant",
|
||||
} as unknown as ProductVariant,
|
||||
} as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
},
|
||||
]),
|
||||
@@ -163,7 +163,7 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 2,
|
||||
},
|
||||
]),
|
||||
@@ -196,7 +196,7 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 4,
|
||||
},
|
||||
]),
|
||||
@@ -229,7 +229,7 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 4,
|
||||
},
|
||||
]),
|
||||
@@ -241,10 +241,10 @@ describe("useSessionCart hook", () => {
|
||||
act(() => {
|
||||
setItems([
|
||||
{
|
||||
variant: {
|
||||
variant: ({
|
||||
...variant,
|
||||
id: "test-variant",
|
||||
} as unknown as ProductVariant,
|
||||
} as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
},
|
||||
])
|
||||
@@ -272,7 +272,7 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 1,
|
||||
},
|
||||
]),
|
||||
@@ -299,7 +299,7 @@ describe("useSessionCart hook", () => {
|
||||
initialProps: {
|
||||
initialState: generateCartState(initialSessionCartState, [
|
||||
{
|
||||
variant: variant as unknown as ProductVariant,
|
||||
variant: (variant as unknown) as ProductVariant,
|
||||
quantity: 4,
|
||||
},
|
||||
]),
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("getVariantPrice", () => {
|
||||
const variant = fixtures.get("product_variant")
|
||||
const region = fixtures.get("region")
|
||||
const amount = getVariantPrice(
|
||||
variant as unknown as ProductVariantInfo,
|
||||
(variant as unknown) as ProductVariantInfo,
|
||||
region
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("getVariantPrice", () => {
|
||||
test("when no region is provided, then it should return 0", () => {
|
||||
const variant = fixtures.get("product_variant")
|
||||
const amount = getVariantPrice(
|
||||
variant as unknown as ProductVariantInfo,
|
||||
(variant as unknown) as ProductVariantInfo,
|
||||
{} as RegionInfo
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("computeVariantPrice", () => {
|
||||
const variant = fixtures.get("product_variant")
|
||||
const region = fixtures.get("region")
|
||||
const price = computeVariantPrice({
|
||||
variant: variant as unknown as ProductVariantInfo,
|
||||
variant: (variant as unknown) as ProductVariantInfo,
|
||||
region,
|
||||
})
|
||||
|
||||
@@ -89,7 +89,7 @@ describe("computeVariantPrice", () => {
|
||||
const variant = fixtures.get("product_variant")
|
||||
const region = fixtures.get("region")
|
||||
const price = computeVariantPrice({
|
||||
variant: variant as unknown as ProductVariantInfo,
|
||||
variant: (variant as unknown) as ProductVariantInfo,
|
||||
region: {
|
||||
...region,
|
||||
tax_rate: 15,
|
||||
@@ -106,7 +106,7 @@ describe("formatVariantPrice", () => {
|
||||
const region = fixtures.get("region")
|
||||
const variant = fixtures.get("product_variant")
|
||||
const price = formatVariantPrice({
|
||||
variant: variant as unknown as ProductVariantInfo,
|
||||
variant: (variant as unknown) as ProductVariantInfo,
|
||||
region: {
|
||||
...region,
|
||||
tax_rate: 15,
|
||||
@@ -116,26 +116,11 @@ describe("formatVariantPrice", () => {
|
||||
expect(price).toEqual("$11.50")
|
||||
})
|
||||
|
||||
test("given a variant, region, and 1 digit, should return a decimal (1 fraction digit) localized amount including taxes and the region's currency code", () => {
|
||||
const region = fixtures.get("region")
|
||||
const variant = fixtures.get("product_variant")
|
||||
const price = formatVariantPrice({
|
||||
variant: variant as unknown as ProductVariantInfo,
|
||||
region: {
|
||||
...region,
|
||||
tax_rate: 15,
|
||||
},
|
||||
maximumFractionDigits: 1,
|
||||
})
|
||||
|
||||
expect(price).toEqual("$11.5")
|
||||
})
|
||||
|
||||
test("given a variant, region, and a custom locale, should return a decimal localized amount including taxes and the region's currency code", () => {
|
||||
const region = fixtures.get("region")
|
||||
const variant = fixtures.get("product_variant")
|
||||
const price = formatVariantPrice({
|
||||
variant: variant as unknown as ProductVariantInfo,
|
||||
variant: (variant as unknown) as ProductVariantInfo,
|
||||
region: {
|
||||
...region,
|
||||
tax_rate: 15,
|
||||
|
||||
Reference in new issue
Block a user