fix(medusa): Decorate order with totals in store domain (#2747)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Decorate orders returned by /store/orders/:id with totals.
|
||||||
@@ -106,6 +106,55 @@ describe("/store/carts", () => {
|
|||||||
await db.teardown()
|
await db.teardown()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("retrieves an order by id, with totals", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const region = await simpleRegionFactory(dbConnection)
|
||||||
|
const product = await simpleProductFactory(dbConnection)
|
||||||
|
|
||||||
|
const cartRes = await api.post("/store/carts", {
|
||||||
|
region_id: region.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
const cartId = cartRes.data.cart.id
|
||||||
|
|
||||||
|
await api.post(`/store/carts/${cartId}/line-items`, {
|
||||||
|
variant_id: product.variants[0].id,
|
||||||
|
quantity: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
await api.post(`/store/carts/${cartId}`, {
|
||||||
|
email: "testmailer@medusajs.com",
|
||||||
|
})
|
||||||
|
|
||||||
|
await api.post(`/store/carts/${cartId}/payment-sessions`).catch((err) => {
|
||||||
|
console.error("Error creating payment session: ", err.response.data)
|
||||||
|
return err.response
|
||||||
|
})
|
||||||
|
|
||||||
|
const responseSuccess = await api.post(`/store/carts/${cartId}/complete`)
|
||||||
|
|
||||||
|
const orderId = responseSuccess.data.data.id
|
||||||
|
|
||||||
|
const response = await api.get("/store/orders/" + orderId)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.order).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: orderId,
|
||||||
|
total: 100,
|
||||||
|
gift_card_total: 0,
|
||||||
|
gift_card_tax_total: 0,
|
||||||
|
tax_total: 0,
|
||||||
|
subtotal: 100,
|
||||||
|
discount_total: 0,
|
||||||
|
shipping_total: 0,
|
||||||
|
refunded_total: 0,
|
||||||
|
paid_total: 100,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("looks up order", async () => {
|
it("looks up order", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ describe("GET /store/orders", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("calls orderService retrieve", () => {
|
it("calls orderService retrieve", () => {
|
||||||
expect(OrderServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
expect(OrderServiceMock.retrieveWithTotals).toHaveBeenCalledTimes(1)
|
||||||
expect(OrderServiceMock.retrieve).toHaveBeenCalledWith(
|
expect(OrderServiceMock.retrieveWithTotals).toHaveBeenCalledWith(
|
||||||
IdMap.getId("test-order"),
|
IdMap.getId("test-order"),
|
||||||
{
|
{
|
||||||
select: defaultStoreOrdersFields,
|
select: defaultStoreOrdersFields,
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export default async (req, res) => {
|
|||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const orderService: OrderService = req.scope.resolve("orderService")
|
const orderService: OrderService = req.scope.resolve("orderService")
|
||||||
const order = await orderService.retrieve(id, {
|
const order = await orderService.retrieveWithTotals(id, {
|
||||||
select: defaultStoreOrdersFields,
|
select: defaultStoreOrdersFields,
|
||||||
relations: defaultStoreOrdersRelations,
|
relations: defaultStoreOrdersRelations,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user