fix(medusa): Add totals when retrieving order by cart id (#3777)
* fix(medusa): Add totals when retrieving order by cart id * fix: Unit test * Create .changeset/stupid-rockets-smile.md
This commit is contained in:
@@ -19,6 +19,7 @@ const {
|
||||
simpleProductFactory,
|
||||
simpleCartFactory,
|
||||
simpleShippingOptionFactory,
|
||||
simpleOrderFactory,
|
||||
} = require("../../factories")
|
||||
const { MedusaError } = require("medusa-core-utils")
|
||||
|
||||
@@ -157,6 +158,56 @@ describe("/store/carts", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("retrieves an order by cart 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/cart/" + cartId)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.order).toEqual(
|
||||
expect.objectContaining({
|
||||
id: orderId,
|
||||
cart_id: cartId,
|
||||
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("lookup order response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import {
|
||||
Discount,
|
||||
FulfillmentStatus,
|
||||
@@ -7,31 +5,33 @@ import {
|
||||
PaymentStatus,
|
||||
Refund,
|
||||
} from "@medusajs/medusa"
|
||||
import {
|
||||
DiscountFactoryData,
|
||||
simpleDiscountFactory,
|
||||
} from "./simple-discount-factory"
|
||||
import { RegionFactoryData, simpleRegionFactory } from "./simple-region-factory"
|
||||
import {
|
||||
LineItemFactoryData,
|
||||
simpleLineItemFactory,
|
||||
} from "./simple-line-item-factory"
|
||||
import faker from "faker"
|
||||
import { DataSource } from "typeorm"
|
||||
import {
|
||||
AddressFactoryData,
|
||||
simpleAddressFactory,
|
||||
} from "./simple-address-factory"
|
||||
import {
|
||||
ShippingMethodFactoryData,
|
||||
simpleShippingMethodFactory,
|
||||
} from "./simple-shipping-method-factory"
|
||||
CustomerFactoryData,
|
||||
simpleCustomerFactory,
|
||||
} from "./simple-customer-factory"
|
||||
import {
|
||||
DiscountFactoryData,
|
||||
simpleDiscountFactory,
|
||||
} from "./simple-discount-factory"
|
||||
import {
|
||||
LineItemFactoryData,
|
||||
simpleLineItemFactory,
|
||||
} from "./simple-line-item-factory"
|
||||
import { RegionFactoryData, simpleRegionFactory } from "./simple-region-factory"
|
||||
import {
|
||||
SalesChannelFactoryData,
|
||||
simpleSalesChannelFactory,
|
||||
} from "./simple-sales-channel-factory"
|
||||
import {
|
||||
CustomerFactoryData,
|
||||
simpleCustomerFactory,
|
||||
} from "./simple-customer-factory"
|
||||
ShippingMethodFactoryData,
|
||||
simpleShippingMethodFactory,
|
||||
} from "./simple-shipping-method-factory"
|
||||
|
||||
export type OrderFactoryData = {
|
||||
id?: string
|
||||
|
||||
Reference in New Issue
Block a user