feat(core-flows): support ad hoc returns (#13598)

* feat(core-flows): support ad hoc returns

* fix: missing transform

* handle edge case

* refactor

* replace gte for gt

* cleanup

* weird bug fix

* add test

* Create quick-nails-kick.md

* stop sending empty strings

* add code to refund reason

* fix build

* fix tests

* handle code in dashboard

* fix tests

* more tests failing

* add reference and reference id to credit lieng

* rework create refund form
This commit is contained in:
William Bouchard
2025-09-30 07:38:50 -04:00
committed by GitHub
parent bd9ecd5e66
commit 087887fefb
24 changed files with 278 additions and 255 deletions
@@ -218,7 +218,7 @@ medusaIntegrationTestRunner({
const refundReason = (
await api.post(
`/admin/refund-reasons`,
{ label: "test" },
{ label: "test", code: "test" },
adminHeaders
)
).data.refund_reason
@@ -254,6 +254,7 @@ medusaIntegrationTestRunner({
refund_reason_id: refundReason.id,
refund_reason: expect.objectContaining({
label: "test",
code: "test"
}),
}),
],
@@ -274,7 +275,7 @@ medusaIntegrationTestRunner({
const refundReason = (
await api.post(
`/admin/refund-reasons`,
{ label: "test" },
{ label: "test", code: "test" },
adminHeaders
)
).data.refund_reason
@@ -330,57 +331,44 @@ medusaIntegrationTestRunner({
)
})
it("should throw if refund exceeds captured total", async () => {
it("should create credit lines if issuing a refund when outstanding amount if >= 0", async () => {
const payment = order.payment_collections[0].payments[0]
const refundReason = (
await api.post(
`/admin/refund-reasons`,
{ label: "Test", code: "test" },
adminHeaders
)
).data.refund_reason
await api.post(
`/admin/payments/${payment.id}/capture`,
undefined,
adminHeaders
)
await createClaim({ order })
await api.post(
`/admin/payments/${payment.id}/refund`,
{ amount: 25 },
{
amount: 50,
refund_reason_id: refundReason.id,
},
adminHeaders
)
const e = await api
.post(
`/admin/payments/${payment.id}/refund`,
{ amount: 1000 },
adminHeaders
)
.catch((e) => e)
const updatedOrder = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
expect(e.response.data.message).toEqual(
"Cannot refund more than pending difference - 75"
)
expect(updatedOrder.credit_line_total).toEqual(50)
expect(updatedOrder.credit_lines).toEqual([
expect.objectContaining({
reference: "Test",
reference_id: "test",
}),
])
})
})
it("should throw if outstanding amount is not present", async () => {
const payment = order.payment_collections[0].payments[0]
await api.post(
`/admin/payments/${payment.id}/capture`,
undefined,
adminHeaders
)
const e = await api
.post(
`/admin/payments/${payment.id}/refund`,
{ amount: 10 },
adminHeaders
)
.catch((e) => e)
expect(e.response.data.message).toEqual(
"Order does not have an outstanding balance to refund"
)
})
},
})