chore(core-flows): adjust inventory when return is received (#8222)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-23 13:36:46 -03:00
committed by GitHub
parent f38f6d53b4
commit 7a5349c0ae
20 changed files with 579 additions and 286 deletions
@@ -27,6 +27,7 @@ jest.setTimeout(500000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const providerId = "manual_test-provider"
const variantSkuWithInventory = "test-variant"
let inventoryItem
async function prepareDataFixtures({ container }) {
@@ -97,7 +98,7 @@ async function prepareDataFixtures({ container }) {
variants: [
{
title: "Test variant",
sku: "test-variant",
sku: variantSkuWithInventory,
},
{
title: "Test variant no inventory management",
@@ -225,6 +226,7 @@ async function createOrderFixture({ container, product, location }) {
title: "Custom Item 2",
variant_sku: product.variants[0].sku,
variant_title: product.variants[0].title,
variant_id: product.variants[0].id,
quantity: 1,
unit_price: 50,
adjustments: [
@@ -351,6 +353,9 @@ medusaIntegrationTestRunner({
)
const order = await createOrderFixture({ container, product, location })
const itemWithInventory = order.items!.find(
(o) => o.variant_sku === variantSkuWithInventory
)!
// Create a fulfillment
const createOrderFulfillmentData: OrderWorkflow.CreateOrderFulfillmentWorkflowInput =
@@ -359,7 +364,7 @@ medusaIntegrationTestRunner({
created_by: "user_1",
items: [
{
id: order.items![0].id,
id: itemWithInventory.id,
quantity: 1,
},
],
@@ -391,11 +396,17 @@ medusaIntegrationTestRunner({
const [orderFulfill] = await remoteQuery(remoteQueryObject)
let orderFulfillItemWithInventory = orderFulfill.items!.find(
(o) => o.variant_sku === variantSkuWithInventory
)!
expect(orderFulfill.fulfillments).toHaveLength(1)
expect(orderFulfill.items[0].detail.fulfilled_quantity).toEqual(1)
expect(orderFulfillItemWithInventory.detail.fulfilled_quantity).toEqual(
1
)
const reservation = await inventoryModule.listReservationItems({
line_item_id: order.items![0].id,
line_item_id: itemWithInventory.id,
})
expect(reservation).toHaveLength(0)
@@ -436,10 +447,14 @@ medusaIntegrationTestRunner({
remoteQueryObjectFulfill
)
orderFulfillItemWithInventory = orderFulfillAfterCancelled.items!.find(
(o) => o.variant_sku === variantSkuWithInventory
)!
expect(orderFulfillAfterCancelled.fulfillments).toHaveLength(1)
expect(
orderFulfillAfterCancelled.items[0].detail.fulfilled_quantity
).toEqual(0)
expect(orderFulfillItemWithInventory.detail.fulfilled_quantity).toEqual(
0
)
const stockAvailabilityAfterCancelled =
await inventoryModule.retrieveStockedQuantity(inventoryItem.id, [