fix(medusa): Refund amount on returns in claim flow (#3237)
This commit is contained in:
committed by
GitHub
parent
d48606d5dd
commit
968eb8fc6b
@@ -1441,6 +1441,57 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("Receives return with custom refund amount passed on receive", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const orderId = "test-order"
|
||||
const itemId = "test-item"
|
||||
|
||||
const returned = await api.post(
|
||||
`/admin/orders/${orderId}/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
// item has a unit_price of 8000 with a 800 adjustment
|
||||
item_id: itemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const returnOrder = returned.data.order.returns[0]
|
||||
|
||||
expect(returned.status).toEqual(200)
|
||||
expect(returnOrder.refund_amount).toEqual(7200)
|
||||
|
||||
const received = await api.post(
|
||||
`/admin/returns/${returnOrder.id}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: itemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
refund: 0,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const receivedReturn = received.data.return
|
||||
|
||||
expect(received.status).toEqual(200)
|
||||
expect(receivedReturn.refund_amount).toEqual(0)
|
||||
|
||||
const orderRes = await api.get(`/admin/orders/${orderId}`, adminReqConfig)
|
||||
|
||||
const order = orderRes.data.order
|
||||
|
||||
expect(order.refunds.length).toEqual(0)
|
||||
})
|
||||
|
||||
it("increases inventory_quantity when return is received", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -121,6 +121,83 @@ describe("Claims", () => {
|
||||
)
|
||||
})
|
||||
|
||||
test("creates a refund claim + return", async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
const order = await createReturnableOrder(dbConnection)
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/orders/${order.id}/claims`,
|
||||
{
|
||||
type: "refund",
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
reason: "missing_item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
price: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const claim = response.data.order.claims[0]
|
||||
const refund = response.data.order.refunds[0]
|
||||
const returnOrder = response.data.order.returns[0]
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(claim.refund_amount).toEqual(1200)
|
||||
expect(refund.amount).toEqual(1200)
|
||||
expect(returnOrder.refund_amount).toEqual(1200)
|
||||
})
|
||||
|
||||
test("creates a refund claim + return with a custom amount", async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
const order = await createReturnableOrder(dbConnection)
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/orders/${order.id}/claims`,
|
||||
{
|
||||
type: "refund",
|
||||
refund_amount: 500,
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
reason: "missing_item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
price: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const claim = response.data.order.claims[0]
|
||||
const refund = response.data.order.refunds[0]
|
||||
const returnOrder = response.data.order.returns[0]
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(claim.refund_amount).toEqual(500)
|
||||
expect(refund.amount).toEqual(500)
|
||||
expect(returnOrder.refund_amount).toEqual(500)
|
||||
})
|
||||
|
||||
test("creates a replace claim", async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user