fix(medusa): Received quantity on return lines (#3267)
This commit is contained in:
committed by
GitHub
parent
3a911091f1
commit
f88af0c28d
5
.changeset/nasty-parents-prove.md
Normal file
5
.changeset/nasty-parents-prove.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(medusa): Received quantity on return lines
|
||||
@@ -1,5 +1,6 @@
|
||||
const path = require("path")
|
||||
import { ReturnReason, ShippingMethod } from "@medusajs/medusa"
|
||||
import { createReturnableOrder } from "../claims"
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -10,6 +11,12 @@ const adminSeeder = require("../../helpers/admin-seeder")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const authHeader = {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
|
||||
describe("/admin/returns", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
@@ -51,26 +58,20 @@ describe("/admin/returns", () => {
|
||||
const api = useApi()
|
||||
|
||||
// create a swap
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
custom_shipping_options: [{ option_id: "test-option", price: 0 }],
|
||||
return_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const sid = response.data.order.swaps[0].id
|
||||
const manager = dbConnection.manager
|
||||
@@ -87,76 +88,52 @@ describe("/admin/returns", () => {
|
||||
await manager.save(sm)
|
||||
|
||||
// fulfill the swap
|
||||
const fulRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/fulfillments`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
const fulRes = await api.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/fulfillments`,
|
||||
{},
|
||||
authHeader
|
||||
)
|
||||
|
||||
// ship the swap
|
||||
await api
|
||||
.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/shipments`,
|
||||
{
|
||||
fulfillment_id: fulRes.data.order.swaps[0].fulfillments[0].id,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e))
|
||||
await api.post(
|
||||
`/admin/orders/test-order/swaps/${sid}/shipments`,
|
||||
{
|
||||
fulfillment_id: fulRes.data.order.swaps[0].fulfillments[0].id,
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const swapItemId = fulRes.data.order.swaps[0].additional_items[0].id
|
||||
|
||||
// request a return
|
||||
const returnRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const returnRes = await api.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = returnRes.data.order.returns[0].id
|
||||
|
||||
const receiveRes = await api
|
||||
.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: swapItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
expect(receiveRes.status).toEqual(200)
|
||||
})
|
||||
@@ -190,11 +167,7 @@ describe("/admin/returns", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
authHeader
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
@@ -214,52 +187,96 @@ describe("/admin/returns", () => {
|
||||
const claimItemId = fulRes.data.order.claims[0].additional_items[0].id
|
||||
|
||||
// request a return
|
||||
const returnRes = await api
|
||||
.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
option_id: "test-option",
|
||||
price: 0,
|
||||
const returnRes = await api.post(
|
||||
`/admin/orders/test-order/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
},
|
||||
],
|
||||
return_shipping: {
|
||||
option_id: "test-option",
|
||||
price: 0,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = returnRes.data.order.returns[0].id
|
||||
|
||||
const receiveRes = await api
|
||||
.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: claimItemId,
|
||||
quantity: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((e) => console.log(e.response))
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
expect(receiveRes.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/returns/:id/receive", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
return await db.teardown()
|
||||
})
|
||||
|
||||
it("should receive a return partially", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const order = await createReturnableOrder(dbConnection)
|
||||
const itemId = "test-item"
|
||||
|
||||
// create a return
|
||||
const response = await api.post(
|
||||
`/admin/orders/${order.id}/return`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: itemId,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const returnId = response.data.order.returns[0].id
|
||||
|
||||
// receive a return
|
||||
const receiveRes = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
item_id: itemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
authHeader
|
||||
)
|
||||
|
||||
const receivedReturn = receiveRes.data.return
|
||||
|
||||
expect(receivedReturn.items.length).toEqual(1)
|
||||
const receivedItem = receivedReturn.items[0]
|
||||
|
||||
expect(receivedItem.requested_quantity).toEqual(2)
|
||||
expect(receivedItem.received_quantity).toEqual(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -351,7 +351,7 @@ describe("Claims", () => {
|
||||
})
|
||||
})
|
||||
|
||||
const createReturnableOrder = async (dbConnection, options = {}) => {
|
||||
export const createReturnableOrder = async (dbConnection, options = {}) => {
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
|
||||
@@ -572,7 +572,7 @@ Object {
|
||||
"note": null,
|
||||
"quantity": 1,
|
||||
"reason_id": null,
|
||||
"received_quantity": null,
|
||||
"received_quantity": 1,
|
||||
"requested_quantity": 1,
|
||||
"return_id": Any<String>,
|
||||
},
|
||||
@@ -719,7 +719,7 @@ Object {
|
||||
"note": null,
|
||||
"quantity": 1,
|
||||
"reason_id": null,
|
||||
"received_quantity": null,
|
||||
"received_quantity": 1,
|
||||
"requested_quantity": 1,
|
||||
"return_id": Any<String>,
|
||||
},
|
||||
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
} from "class-validator"
|
||||
import { OrderService, ReturnService, SwapService } from "../../../../services"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { Type } from "class-transformer"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { isDefined } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
* @oas [post] /returns/{id}/receive
|
||||
|
||||
@@ -11,12 +11,12 @@ import {
|
||||
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
|
||||
|
||||
import { BaseEntity } from "../interfaces/models/base-entity"
|
||||
import { generateEntityId } from "../utils/generate-entity-id"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { Order } from "./order"
|
||||
import { ReturnItem } from "./return-item"
|
||||
import { ShippingMethod } from "./shipping-method"
|
||||
import { Swap } from "./swap"
|
||||
import { generateEntityId } from "../utils/generate-entity-id"
|
||||
|
||||
export enum ReturnStatus {
|
||||
REQUESTED = "requested",
|
||||
@@ -36,7 +36,7 @@ export class Return extends BaseEntity {
|
||||
|
||||
@OneToMany(() => ReturnItem, (item) => item.return_order, {
|
||||
eager: true,
|
||||
cascade: ["insert"],
|
||||
cascade: ["insert", "update"],
|
||||
})
|
||||
items: ReturnItem[]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user