fix(order): order list payment and fulfillment status (#7934)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-04 06:37:25 -03:00
committed by GitHub
parent 41c4307fc7
commit 56394fe0d4
8 changed files with 143 additions and 23 deletions
@@ -1,6 +1,6 @@
import { CreateOrderDTO, IOrderModuleService } from "@medusajs/types"
import { ClaimType, Modules } from "@medusajs/utils"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(100000)
@@ -222,7 +222,7 @@ moduleIntegrationTestRunner({
}),
}),
],
shipping_methods: [
shipping_methods: expect.arrayContaining([
expect.objectContaining({
name: "return shipping method",
amount: 10,
@@ -231,7 +231,7 @@ moduleIntegrationTestRunner({
name: "Claim method",
amount: 35,
}),
],
]),
refund_amount: null,
})
)
@@ -282,11 +282,12 @@ moduleIntegrationTestRunner<IOrderModuleService>({
"items.detail.fulfilled_quantity",
"items.detail.return_requested_quantity",
],
relations: ["items", "items.detail"],
relations: ["items", "items.detail", "shipping_methods"],
})
serializedOrder = JSON.parse(JSON.stringify(getOrder))
expect(serializedOrder.shipping_methods).toHaveLength(3)
expect(serializedOrder).toEqual(
expect.objectContaining({
items: [
@@ -78,14 +78,19 @@ export function setFindMethods<T>(klass: Constructor<T>, entity: any) {
orderWhere.items ??= {}
orderWhere.items.version = version
orderWhere.items.deleted_at ??= null
popWhere.shipping_methods ??= {}
popWhere.shipping_methods.version = version
popWhere.shipping_methods.deleted_at ??= null
if (!config.options.orderBy) {
config.options.orderBy = { id: "ASC" }
}
config.where ??= {}
config.where.deleted_at ??= null
return await manager.find(entity, config.where, config.options)
}
@@ -152,9 +157,11 @@ export function setFindMethods<T>(klass: Constructor<T>, entity: any) {
orderWhere.items ??= {}
orderWhere.items.version = version
orderWhere.items.deleted_at ??= null
popWhere.shipping_methods ??= {}
popWhere.shipping_methods.version = version
popWhere.shipping_methods.deleted_at ??= null
if (!config.options.orderBy) {
config.options.orderBy = { id: "ASC" }
@@ -65,6 +65,8 @@ export function formatOrder(
const sm = { ...shippingMethod.shipping_method }
delete shippingMethod.shipping_method
cleanNestedRelations(shippingMethod)
return {
...sm,
order_id: shippingMethod.order_id,
@@ -87,6 +89,13 @@ export function formatOrder(
return isArray ? orders : orders[0]
}
function cleanNestedRelations(obj) {
delete obj.order
delete obj.return
delete obj.claim
delete obj.exchange
}
function formatOrderReturn(orderReturn, mainOrder) {
orderReturn.items.forEach((orderItem) => {
const item = mainOrder.items?.find((item) => item.id === orderItem.item_id)
@@ -105,7 +114,7 @@ function formatClaim(claim) {
const item = claim.order.items?.find(
(item) => item.id === orderItem.item_id
)
cleanNestedRelations(item)
orderItem.detail = item?.detail
})
}
@@ -122,6 +131,7 @@ function formatClaim(claim) {
(item) => item.id === orderItem.item_id
)
cleanNestedRelations(item)
orderItem.detail = item?.detail
})
}
@@ -136,6 +146,7 @@ function formatExchange(exchange) {
(item) => item.id === orderItem.item_id
)
cleanNestedRelations(item)
orderItem.detail = item?.detail
})
}
@@ -150,6 +161,7 @@ function formatReturn(returnOrder) {
(item) => item.id === orderItem.item_id
)
cleanNestedRelations(item)
orderItem.detail = item?.detail
})
}