feat(core-flows, fulfillment): Add create return specific method and add more tests (#7357)
* feat(core-flows, fulfillment): Add create return specific method and add more tests * fix defautl providers in tests fixtures * more tests * wip fixes * fix flow and tests * cleanup
This commit is contained in:
committed by
GitHub
parent
35dc3c5cf7
commit
c4fde7ea5c
@@ -1,5 +1,10 @@
|
||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
RemoteLink,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FulfillmentSetDTO,
|
||||
FulfillmentWorkflow,
|
||||
IOrderModuleService,
|
||||
IRegionModuleService,
|
||||
@@ -208,6 +213,7 @@ async function prepareDataFixtures({ container }) {
|
||||
salesChannel,
|
||||
location,
|
||||
product,
|
||||
fulfillmentSet,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +318,17 @@ async function createOrderFixture({ container, product }) {
|
||||
},
|
||||
])
|
||||
|
||||
const returnReason = await orderService.createReturnReasons({
|
||||
value: "Test reason",
|
||||
label: "Test reason",
|
||||
})
|
||||
|
||||
await orderService.createReturnReasons({
|
||||
value: "Test child reason",
|
||||
label: "Test child reason",
|
||||
parent_return_reason_id: returnReason.id,
|
||||
})
|
||||
|
||||
await orderService.applyPendingOrderActions(order.id)
|
||||
|
||||
order = await orderService.retrieve(order.id, {
|
||||
@@ -335,6 +352,7 @@ medusaIntegrationTestRunner({
|
||||
let region: RegionDTO
|
||||
let location: StockLocationDTO
|
||||
let product: ProductDTO
|
||||
let fulfillmentSet: FulfillmentSetDTO
|
||||
|
||||
let orderService: IOrderModuleService
|
||||
|
||||
@@ -347,12 +365,18 @@ medusaIntegrationTestRunner({
|
||||
region = fixtures.region
|
||||
location = fixtures.location
|
||||
product = fixtures.product
|
||||
fulfillmentSet = fixtures.fulfillmentSet
|
||||
|
||||
orderService = container.resolve(ModuleRegistrationName.ORDER)
|
||||
})
|
||||
|
||||
it("should create a return order", async () => {
|
||||
const order = await createOrderFixture({ container, product })
|
||||
const reasons = await orderService.listReturnReasons({})
|
||||
const testReason = reasons.find(
|
||||
(r) => r.value.toLowerCase() === "test child reason"
|
||||
)!
|
||||
|
||||
const createReturnOrderData: OrderWorkflow.CreateOrderReturnWorkflowInput =
|
||||
{
|
||||
order_id: order.id,
|
||||
@@ -363,6 +387,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
id: order.items![0].id,
|
||||
quantity: 1,
|
||||
reason_id: testReason.id,
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -468,6 +493,80 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail when location is not linked", async () => {
|
||||
const order = await createOrderFixture({ container, product })
|
||||
const createReturnOrderData: OrderWorkflow.CreateOrderReturnWorkflowInput =
|
||||
{
|
||||
order_id: order.id,
|
||||
return_shipping: {
|
||||
option_id: shippingOption.id,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
id: order.items![0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// Remove the location link
|
||||
const remoteLink = container.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
) as RemoteLink
|
||||
|
||||
await remoteLink.dismiss([
|
||||
{
|
||||
[Modules.STOCK_LOCATION]: {
|
||||
stock_location_id: location.id,
|
||||
},
|
||||
[Modules.FULFILLMENT]: {
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
const { errors } = await createReturnOrderWorkflow(container).run({
|
||||
input: createReturnOrderData,
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
await expect(errors[0].error.message).toBe(
|
||||
`Cannot create return without stock location, either provide a location or you should link the shipping option ${shippingOption.id} to a stock location.`
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail when a reason with children is provided", async () => {
|
||||
const order = await createOrderFixture({ container, product })
|
||||
const reasons = await orderService.listReturnReasons({})
|
||||
const testReason = reasons.find(
|
||||
(r) => r.value.toLowerCase() === "test reason"
|
||||
)!
|
||||
|
||||
const createReturnOrderData: OrderWorkflow.CreateOrderReturnWorkflowInput =
|
||||
{
|
||||
order_id: order.id,
|
||||
return_shipping: {
|
||||
option_id: shippingOption.id,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
id: order.items![0].id,
|
||||
quantity: 1,
|
||||
reason_id: testReason.id,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const { errors } = await createReturnOrderWorkflow(container).run({
|
||||
input: createReturnOrderData,
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
expect(errors[0].error.message).toBe(
|
||||
`Cannot apply return reason with id ${testReason.id} to order with id ${order.id}. Return reason has nested reasons.`
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user