fix(core-flows): Allow adding shipping methods through order edits (#11504)

* fix(core-flows): Allow adding shipping methods through order edits

* fix(core-flows): Allow adding shipping methods through order edits

* update test description

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Kasper Fabricius Kristensen
2025-02-23 16:06:54 +01:00
committed by GitHub
co-authored by Oli Juhl
parent 215553792b
commit efd66c0d59
3 changed files with 90 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/core-flows": patch
---
fix(core-flows): Allow adding shipping methods through order edits
@@ -505,5 +505,78 @@ medusaIntegrationTestRunner({
expect(result[0].confirmed_by).toEqual(expect.stringContaining("user_")) expect(result[0].confirmed_by).toEqual(expect.stringContaining("user_"))
}) })
}) })
describe("Order Edit Shipping Methods", () => {
it("should add a shipping method through an order edit", async () => {
await api.post(
"/admin/order-edits",
{ order_id: order.id, description: "Test" },
adminHeaders
)
const orderId = order.id
const shippingMethodResponse = await api.post(
`/admin/order-edits/${orderId}/shipping-method`,
{ shipping_option_id: shippingOption.id, custom_amount: 5 },
adminHeaders
)
expect(
shippingMethodResponse.data.order_preview.shipping_methods.length
).toEqual(2)
expect(
shippingMethodResponse.data.order_preview.shipping_methods
).toEqual(
expect.arrayContaining([
expect.objectContaining({
amount: 10,
}),
expect.objectContaining({
amount: 5,
}),
])
)
const requestResult = await api.post(
`/admin/order-edits/${orderId}/request`,
{},
adminHeaders
)
expect(requestResult.data.order_preview.order_change.status).toEqual(
OrderChangeStatus.REQUESTED
)
await api.post(
`/admin/order-edits/${orderId}/confirm`,
{},
adminHeaders
)
const orderResult = await api.get(
`/admin/orders/${orderId}`,
adminHeaders
)
expect(orderResult.data.order.shipping_methods.length).toEqual(2)
expect(orderResult.data.order.shipping_methods).toEqual(
expect.arrayContaining([
expect.objectContaining({ amount: 10 }),
expect.objectContaining({ amount: 5 }),
])
)
const orderChangesResult = await api.get(
`/admin/orders/${orderId}/changes?change_type=edit`,
adminHeaders
)
expect(orderChangesResult.data.order_changes.length).toEqual(1)
expect(orderChangesResult.data.order_changes[0].status).toEqual(
OrderChangeStatus.CONFIRMED
)
})
})
}, },
}) })
@@ -113,7 +113,9 @@ export const createOrderEditShippingMethodWorkflowId =
*/ */
export const createOrderEditShippingMethodWorkflow = createWorkflow( export const createOrderEditShippingMethodWorkflow = createWorkflow(
createOrderEditShippingMethodWorkflowId, createOrderEditShippingMethodWorkflowId,
function (input: CreateOrderEditShippingMethodWorkflowInput): WorkflowResponse<OrderPreviewDTO> { function (
input: CreateOrderEditShippingMethodWorkflowInput
): WorkflowResponse<OrderPreviewDTO> {
const order: OrderDTO = useRemoteQueryStep({ const order: OrderDTO = useRemoteQueryStep({
entry_point: "orders", entry_point: "orders",
fields: ["id", "status", "currency_code", "canceled_at"], fields: ["id", "status", "currency_code", "canceled_at"],
@@ -152,6 +154,7 @@ export const createOrderEditShippingMethodWorkflow = createWorkflow(
const shippingMethodInput = transform( const shippingMethodInput = transform(
{ {
relatedEntity: { order_id: order.id },
shippingOptions, shippingOptions,
customPrice: input.custom_amount, customPrice: input.custom_amount,
orderChange, orderChange,