feat(medusa,medusa-react): PaymentCollection support (#2659)
* chore: medusa react, order edit complete fix and single payment session
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
useAdminDeletePaymentCollection,
|
||||
useAdminUpdatePaymentCollection,
|
||||
useAdminMarkPaymentCollectionAsAuthorized,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminDeletePaymentCollection hook", () => {
|
||||
test("Delete a payment collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDeletePaymentCollection("payment_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: "payment_collection_id",
|
||||
deleted: true,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdatePaymentCollection hook", () => {
|
||||
test("Update a Payment Collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdatePaymentCollection("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
description: "new description",
|
||||
metadata: { demo: "obj" },
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.payment_collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "payment_collection_id",
|
||||
description: "new description",
|
||||
metadata: { demo: "obj" },
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminMarkPaymentCollectionAsAuthorized hook", () => {
|
||||
test("Mark a Payment Collection as Authorized", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminMarkPaymentCollectionAsAuthorized("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.payment_collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "payment_collection_id",
|
||||
status: "authorized",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { useAdminPaymentCollection } from "../../../../src/hooks/admin/payment-collections"
|
||||
|
||||
describe("useAdminPaymentCollection hook", () => {
|
||||
test("returns a payment collection", async () => {
|
||||
const payment_collection = fixtures.get("payment_collection")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminPaymentCollection(payment_collection.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.payment_collection).toEqual(payment_collection)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
useAdminPaymentsCapturePayment,
|
||||
useAdminPaymentsRefundPayment,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { RefundReason } from "@medusajs/medusa"
|
||||
|
||||
describe("useAdminPaymentsCapturePayment hook", () => {
|
||||
test("Capture a payment", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminPaymentsCapturePayment("payment_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.payment).toEqual(
|
||||
expect.objectContaining({
|
||||
amount_captured: 900,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminPaymentsRefundPayment hook", () => {
|
||||
test("Update a Payment Collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminPaymentsRefundPayment("payment_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
amount: 500,
|
||||
reason: RefundReason.DISCOUNT,
|
||||
note: "note to refund",
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.refund).toEqual(
|
||||
expect.objectContaining({
|
||||
payment_id: "payment_id",
|
||||
amount: 500,
|
||||
reason: RefundReason.DISCOUNT,
|
||||
note: "note to refund",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { useAdminPayment } from "../../../../src/hooks/admin/payments"
|
||||
|
||||
describe("useAdminPayment hook", () => {
|
||||
test("returns a payment collection", async () => {
|
||||
const payment = fixtures.get("payment")
|
||||
const { result, waitFor } = renderHook(() => useAdminPayment(payment.id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.payment).toEqual(payment)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,138 @@
|
||||
import {
|
||||
useManageMultiplePaymentSessions,
|
||||
useManagePaymentSession,
|
||||
useAuthorizePaymentSession,
|
||||
useAuthorizePaymentSessionsBatch,
|
||||
usePaymentCollectionRefreshPaymentSession,
|
||||
} from "../../../../src"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useManageMultiplePaymentSessions hook", () => {
|
||||
test("Manage multiple payment sessions of a payment collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useManageMultiplePaymentSessions("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
sessions: {
|
||||
provider_id: "manual",
|
||||
amount: 900,
|
||||
},
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data?.payment_collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "payment_collection_id",
|
||||
amount: 900,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useManagePaymentSession hook", () => {
|
||||
test("Manage payment session of a payment collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useManagePaymentSession("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
provider_id: "manual",
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data?.payment_collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "payment_collection_id",
|
||||
amount: 900,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAuthorizePaymentSession hook", () => {
|
||||
test("Authorize a payment session of a Payment Collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAuthorizePaymentSession("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("123")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.payment_session).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "123",
|
||||
amount: 900,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("authorizePaymentSessionsBatch hook", () => {
|
||||
test("Authorize all payment sessions of a Payment Collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAuthorizePaymentSessionsBatch("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({
|
||||
session_ids: ["abc"],
|
||||
})
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(207)
|
||||
|
||||
expect(result.current.data.payment_collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "payment_collection_id",
|
||||
payment_sessions: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 900,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("usePaymentCollectionRefreshPaymentSession hook", () => {
|
||||
test("Refresh a payment sessions of a Payment Collection", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => usePaymentCollectionRefreshPaymentSession("payment_collection_id"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("session_id")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.payment_session).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "new_session_id",
|
||||
amount: 900,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { usePaymentCollection } from "../../../../src/hooks/store/payment-collections"
|
||||
|
||||
describe("usePaymentCollection hook", () => {
|
||||
test("returns a payment collection", async () => {
|
||||
const payment_collection = fixtures.get("payment_collection")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => usePaymentCollection(payment_collection.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.payment_collection).toEqual(payment_collection)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user