fix(order): ignore reservation when manage_inventory is false (#7594)

This commit is contained in:
Carlos R. L. Rodrigues
2024-06-04 07:08:54 -03:00
committed by GitHub
parent 0929c4f457
commit 68fb04b849
2 changed files with 105 additions and 9 deletions
@@ -96,6 +96,11 @@ async function prepareDataFixtures({ container }) {
title: "Test variant",
sku: "test-variant",
},
{
title: "Test variant no inventory management",
sku: "test-variant-no-inventory",
manage_inventory: false,
},
],
},
])
@@ -228,7 +233,15 @@ async function createOrderFixture({ container, product, location }) {
provider_id: "coupon_kings",
},
],
} as any,
},
{
title: product.title,
variant_sku: product.variants[1].sku,
variant_title: product.variants[1].title,
variant_id: product.variants[1].id,
quantity: 1,
unit_price: 200,
},
],
transactions: [
{
@@ -282,6 +295,7 @@ async function createOrderFixture({ container, product, location }) {
})
const inventoryModule = container.resolve(ModuleRegistrationName.INVENTORY)
const reservation = await inventoryModule.createReservationItems([
{
line_item_id: order.items![0].id,
@@ -429,6 +443,81 @@ medusaIntegrationTestRunner({
])
expect(stockAvailabilityAfterCancelled).toEqual(2)
})
it("should revert an order fulfillment when it fails and recreate it when tried again", async () => {
const order = await createOrderFixture({ container, product, location })
// Create a fulfillment
const createOrderFulfillmentData: OrderWorkflow.CreateOrderFulfillmentWorkflowInput =
{
order_id: order.id,
created_by: "user_1",
items: [
{
id: order.items![0].id,
quantity: 1,
},
],
no_notification: false,
location_id: undefined,
}
const worflow = createOrderFulfillmentWorkflow(container)
worflow.addAction("fail", {
invoke: () => {
throw new Error("Fulfillment failed")
},
})
await worflow
.run({
input: createOrderFulfillmentData,
})
.catch(() => void 0)
worflow.deleteAction("fail")
await worflow.run({
input: createOrderFulfillmentData,
})
const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
const remoteQueryObject = remoteQueryObjectFromString({
entryPoint: "order",
variables: {
id: order.id,
},
fields: [
"*",
"items.*",
"shipping_methods.*",
"total",
"item_total",
"fulfillments.*",
],
})
const [orderFulfill] = await remoteQuery(remoteQueryObject)
expect(orderFulfill.fulfillments).toHaveLength(1)
expect(orderFulfill.items[0].detail.fulfilled_quantity).toEqual(1)
const inventoryModule = container.resolve(
ModuleRegistrationName.INVENTORY
)
const reservation = await inventoryModule.listReservationItems({
line_item_id: order.items![0].id,
})
expect(reservation).toHaveLength(0)
const stockAvailability = await inventoryModule.retrieveStockedQuantity(
inventoryItem.id,
[location.id]
)
expect(stockAvailability).toEqual(1)
})
})
},
})