fix(core-flows): fulfillment reservation check (#11735)
This commit is contained in:
@@ -331,6 +331,17 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
// create reservation for inventory item that is initially on the order
|
||||
const inventoryModule = container.resolve(Modules.INVENTORY)
|
||||
await inventoryModule.createReservationItems([
|
||||
{
|
||||
inventory_item_id: inventoryItem.id,
|
||||
location_id: location.id,
|
||||
quantity: 2,
|
||||
line_item_id: order.items[0].id,
|
||||
},
|
||||
])
|
||||
|
||||
const shippingOptionPayload = {
|
||||
name: "Return shipping",
|
||||
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||
|
||||
@@ -325,6 +325,17 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
// create reservation for inventory item that is initially on the order
|
||||
const inventoryModule = container.resolve(Modules.INVENTORY)
|
||||
await inventoryModule.createReservationItems([
|
||||
{
|
||||
inventory_item_id: inventoryItem.id,
|
||||
location_id: location.id,
|
||||
quantity: 2,
|
||||
line_item_id: order.items[0].id,
|
||||
},
|
||||
])
|
||||
|
||||
const shippingOptionPayload = {
|
||||
name: "Return shipping",
|
||||
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||
|
||||
@@ -17,6 +17,7 @@ medusaIntegrationTestRunner({
|
||||
let location
|
||||
let item
|
||||
let returnShippingOption
|
||||
let outboundShippingOption
|
||||
const shippingProviderId = "manual_test-provider"
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -135,7 +136,7 @@ medusaIntegrationTestRunner({
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 20,
|
||||
amount: 0, // Free shipping
|
||||
},
|
||||
],
|
||||
rules: [
|
||||
@@ -160,7 +161,7 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
).data.shipping_option
|
||||
|
||||
const outboundShippingOption = (
|
||||
outboundShippingOption = (
|
||||
await api.post(
|
||||
"/admin/shipping-options",
|
||||
outboundShippingOptionPayload,
|
||||
@@ -289,6 +290,15 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
// If claim has outbound items, we need to set the outbound shipping method for reservation to be created
|
||||
// TODO: change condition in confirm workfow to crate reservation depending on shipping since we can have
|
||||
// reservations for inventory items that don't require shipping
|
||||
await api.post(
|
||||
`/admin/claims/${singleOutboundClaim.id}/outbound/shipping-method`,
|
||||
{ shipping_option_id: outboundShippingOption.id },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
await api.post(
|
||||
`/admin/claims/${singleOutboundClaim.id}/request`,
|
||||
{},
|
||||
|
||||
@@ -239,6 +239,17 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
// create reservation for inventory item that is initially on the order
|
||||
const inventoryModule = container.resolve(Modules.INVENTORY)
|
||||
await inventoryModule.createReservationItems([
|
||||
{
|
||||
inventory_item_id: inventoryItem.id,
|
||||
location_id: location.id,
|
||||
quantity: 2,
|
||||
line_item_id: order.items[0].id,
|
||||
},
|
||||
])
|
||||
|
||||
const shippingOptionPayload = {
|
||||
name: "Return shipping",
|
||||
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||
@@ -866,7 +877,9 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
).data.inventory_levels
|
||||
expect(inventoryLevel[0].stocked_quantity).toEqual(2)
|
||||
|
||||
// we had 2 items in stock that were reserved for the order and then fulfilled
|
||||
expect(inventoryLevel[0].stocked_quantity).toEqual(0)
|
||||
|
||||
let result = await api.post(
|
||||
`/admin/returns/${returnId}/receive`,
|
||||
@@ -987,7 +1000,7 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
).data.inventory_levels
|
||||
expect(inventoryLevel[0].stocked_quantity).toEqual(3)
|
||||
expect(inventoryLevel[0].stocked_quantity).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -486,6 +486,9 @@ medusaIntegrationTestRunner({
|
||||
it("should revert an order fulfillment when it fails and recreate it when tried again", async () => {
|
||||
const order = await createOrderFixture({ container, product, location })
|
||||
|
||||
const itemId = order.items?.find((i) => i.title === "Custom Item 2")!
|
||||
.id as string
|
||||
|
||||
// Create a fulfillment
|
||||
const createOrderFulfillmentData: OrderWorkflow.CreateOrderFulfillmentWorkflowInput =
|
||||
{
|
||||
@@ -493,7 +496,7 @@ medusaIntegrationTestRunner({
|
||||
created_by: "user_1",
|
||||
items: [
|
||||
{
|
||||
id: order.items![0].id,
|
||||
id: itemId,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
@@ -540,12 +543,14 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const [orderFulfill] = await remoteQuery(remoteQueryObject)
|
||||
|
||||
const fulfilledItem = orderFulfill.items?.find((i) => i.id === itemId)
|
||||
|
||||
expect(orderFulfill.fulfillments).toHaveLength(1)
|
||||
expect(orderFulfill.items[0].detail.fulfilled_quantity).toEqual(1)
|
||||
expect(fulfilledItem?.detail.fulfilled_quantity).toEqual(1)
|
||||
|
||||
const inventoryModule = container.resolve(Modules.INVENTORY)
|
||||
const reservation = await inventoryModule.listReservationItems({
|
||||
line_item_id: order.items![0].id,
|
||||
line_item_id: itemId,
|
||||
})
|
||||
expect(reservation).toHaveLength(0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user