fix(medusa): Remove updatePaymentMethod store cart route (#1382)
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
import { IdMap } from "medusa-test-utils"
|
|
||||||
import { request } from "../../../../../helpers/test-request"
|
|
||||||
import { CartServiceMock } from "../../../../../services/__mocks__/cart"
|
|
||||||
|
|
||||||
describe("POST /store/carts/:id/payment-method", () => {
|
|
||||||
describe("successfully sets the payment method", () => {
|
|
||||||
let subject
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
const cartId = IdMap.getId("cartWithPaySessions")
|
|
||||||
subject = await request("POST", `/store/carts/${cartId}/payment-method`, {
|
|
||||||
payload: {
|
|
||||||
provider_id: "default_provider",
|
|
||||||
data: {
|
|
||||||
money_id: "success",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
jest.clearAllMocks()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("calls CartService setPaymentMethod", () => {
|
|
||||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledTimes(1)
|
|
||||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledWith(
|
|
||||||
IdMap.getId("cartWithPaySessions"),
|
|
||||||
{
|
|
||||||
provider_id: "default_provider",
|
|
||||||
data: {
|
|
||||||
money_id: "success",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns 200", () => {
|
|
||||||
expect(subject.status).toEqual(200)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns the cart", () => {
|
|
||||||
expect(subject.body.cart.id).toEqual(IdMap.getId("cartWithPaySessions"))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -82,11 +82,6 @@ export default (app, container) => {
|
|||||||
middlewares.wrap(require("./set-payment-session").default)
|
middlewares.wrap(require("./set-payment-session").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
route.post(
|
|
||||||
"/:id/payment-method",
|
|
||||||
middlewares.wrap(require("./update-payment-method").default)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Shipping Options
|
// Shipping Options
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/shipping-methods",
|
"/:id/shipping-methods",
|
||||||
@@ -155,5 +150,4 @@ export * from "./create-payment-sessions"
|
|||||||
export * from "./set-payment-session"
|
export * from "./set-payment-session"
|
||||||
export * from "./update-cart"
|
export * from "./update-cart"
|
||||||
export * from "./update-line-item"
|
export * from "./update-line-item"
|
||||||
export * from "./update-payment-method"
|
|
||||||
export * from "./update-payment-session"
|
export * from "./update-payment-session"
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
import { IsOptional, IsString } from "class-validator"
|
|
||||||
import { defaultStoreCartFields, defaultStoreCartRelations } from "."
|
|
||||||
import { CartService } from "../../../../services"
|
|
||||||
import { validator } from "../../../../utils/validator"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @oas [post] /store/carts/{id}
|
|
||||||
* operationId: PostCartsCartPaymentMethodUpdate
|
|
||||||
* summary: Update a Cart"
|
|
||||||
* description: "Updates a Cart."
|
|
||||||
* parameters:
|
|
||||||
* - (path) id=* {string} The id of the Cart.
|
|
||||||
* requestBody:
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* required:
|
|
||||||
* - provider_id
|
|
||||||
* properties:
|
|
||||||
* provider_id:
|
|
||||||
* type: string
|
|
||||||
* description: The id of the Payment Provider.
|
|
||||||
* data:
|
|
||||||
* type: object
|
|
||||||
* description: ""
|
|
||||||
* tags:
|
|
||||||
* - Cart
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: OK
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* cart:
|
|
||||||
* $ref: "#/components/schemas/cart"
|
|
||||||
*/
|
|
||||||
export default async (req, res) => {
|
|
||||||
const { id } = req.params
|
|
||||||
|
|
||||||
const validated = await validator(
|
|
||||||
StorePostCartsCartPaymentMethodUpdateReq,
|
|
||||||
req.body
|
|
||||||
)
|
|
||||||
|
|
||||||
const cartService: CartService = req.scope.resolve("cartService")
|
|
||||||
|
|
||||||
let cart = await cartService.setPaymentMethod(id, validated)
|
|
||||||
cart = await cartService.retrieve(id, {
|
|
||||||
select: defaultStoreCartFields,
|
|
||||||
relations: defaultStoreCartRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.status(200).json({ cart })
|
|
||||||
}
|
|
||||||
|
|
||||||
export class StorePostCartsCartPaymentMethodUpdateReq {
|
|
||||||
@IsString()
|
|
||||||
provider_id: string
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
data?: object
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user