test: Introduce V2 tests in Admin Payments API (#6621)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { capturePaymentWorkflow } from "@medusajs/core-flows"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -9,9 +8,10 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { defaultAdminPaymentFields } from "../../query-config"
|
||||
import { AdminPostPaymentsCapturesReq } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<AdminPostPaymentsCapturesReq>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
@@ -22,6 +22,7 @@ export const POST = async (
|
||||
input: {
|
||||
payment_id: id,
|
||||
captured_by: req.auth?.actor_id,
|
||||
amount: req.validatedBody.amount,
|
||||
},
|
||||
throwOnError: false,
|
||||
})
|
||||
@@ -31,7 +32,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: Modules.PAYMENT,
|
||||
entryPoint: "payments",
|
||||
variables: { id },
|
||||
fields: defaultAdminPaymentFields,
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { refundPaymentWorkflow } from "@medusajs/core-flows"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
@@ -9,9 +8,10 @@ import {
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
import { defaultAdminPaymentFields } from "../../query-config"
|
||||
import { AdminPostPaymentsRefundsReq } from "../../validators"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
req: AuthenticatedMedusaRequest<AdminPostPaymentsRefundsReq>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
@@ -22,6 +22,7 @@ export const POST = async (
|
||||
input: {
|
||||
payment_id: id,
|
||||
created_by: req.auth?.actor_id,
|
||||
amount: req.validatedBody.amount,
|
||||
},
|
||||
throwOnError: false,
|
||||
})
|
||||
@@ -31,7 +32,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: Modules.PAYMENT,
|
||||
entryPoint: "payments",
|
||||
variables: { id },
|
||||
fields: defaultAdminPaymentFields,
|
||||
})
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { transformQuery } from "../../../api/middlewares"
|
||||
import { transformBody, transformQuery } from "../../../api/middlewares"
|
||||
import { MiddlewareRoute } from "../../../types/middlewares"
|
||||
import { authenticate } from "../../../utils/authenticate-middleware"
|
||||
import * as queryConfig from "./query-config"
|
||||
import { AdminGetPaymentsParams } from "./validators"
|
||||
import {
|
||||
AdminGetPaymentsParams,
|
||||
AdminPostPaymentsCapturesReq,
|
||||
AdminPostPaymentsRefundsReq,
|
||||
} from "./validators"
|
||||
|
||||
export const adminPaymentRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
@@ -33,11 +37,11 @@ export const adminPaymentRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/payments/:id/capture",
|
||||
middlewares: [],
|
||||
middlewares: [transformBody(AdminPostPaymentsCapturesReq)],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/payments/:id/refund",
|
||||
middlewares: [],
|
||||
middlewares: [transformBody(AdminPostPaymentsRefundsReq)],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -2,8 +2,13 @@ export const defaultAdminPaymentFields = [
|
||||
"id",
|
||||
"currency_code",
|
||||
"amount",
|
||||
"captured_at",
|
||||
"payment_collection_id",
|
||||
"payment_session_id",
|
||||
"captures.id",
|
||||
"captures.amount",
|
||||
"refunds.id",
|
||||
"refunds.amount",
|
||||
]
|
||||
|
||||
export const defaultAdminPaymentRelations = ["captures", "refunds"]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Type } from "class-transformer"
|
||||
import { IsOptional, ValidateNested } from "class-validator"
|
||||
import { IsInt, IsOptional, ValidateNested } from "class-validator"
|
||||
import {
|
||||
DateComparisonOperator,
|
||||
FindParams,
|
||||
@@ -44,3 +44,15 @@ export class AdminGetPaymentsParams extends extendedFindParamsMixin({
|
||||
@Type(() => DateComparisonOperator)
|
||||
deleted_at?: DateComparisonOperator
|
||||
}
|
||||
|
||||
export class AdminPostPaymentsCapturesReq {
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
amount?: number
|
||||
}
|
||||
|
||||
export class AdminPostPaymentsRefundsReq {
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
amount?: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user