feat(core-flows,medusa): adds inventory kit creation to variants endpoint (#7599)

what:

When creating a variant, we can now create inventory as a part of the product and variants create endpoint.

This applies only to variants where `manage_inventory=true`. 2 cases present itself:

1. When inventory_items are present
  - Link an inventory item with required_quantity to the variant
  - the inventory item already needs to be present
2. When inventory_items are not present
  - A default inventory item will be created
  - links the created item to the variant with a default required_quantity
  
  
RESOLVES CORE-2220
This commit is contained in:
Riqwan Thamir
2024-06-04 15:49:31 +02:00
committed by GitHub
parent 6646a203df
commit e7005a0aac
9 changed files with 521 additions and 179 deletions

View File

@@ -96,7 +96,8 @@ medusaIntegrationTestRunner({
)
).data.variant
expect(updatedVariant.inventory_items).toHaveLength(0)
// The default inventory item remains that was created as a part of create product
expect(updatedVariant.inventory_items).toHaveLength(1)
})
})
})
@@ -159,11 +160,14 @@ medusaIntegrationTestRunner({
)
).data.variant
expect(updatedVariant.inventory_items).toEqual([
expect.objectContaining({
required_quantity: originalQuantity,
}),
])
expect(updatedVariant.inventory_items).toHaveLength(2)
expect(updatedVariant.inventory_items).toEqual(
expect.arrayContaining([
expect.objectContaining({
required_quantity: originalQuantity,
}),
])
)
})
it("should throw an error when a link is not found", async () => {
@@ -258,11 +262,14 @@ medusaIntegrationTestRunner({
)
).data.variant
expect(updatedVariant.inventory_items).toEqual([
expect.objectContaining({
required_quantity: originalQuantity,
}),
])
expect(updatedVariant.inventory_items).toHaveLength(2)
expect(updatedVariant.inventory_items).toEqual(
expect.arrayContaining([
expect.objectContaining({
required_quantity: originalQuantity,
}),
])
)
})
it("should pass dismiss step if link not found if next step throws error", async () => {
@@ -304,7 +311,7 @@ medusaIntegrationTestRunner({
)
).data.variant
expect(updatedVariant.inventory_items).toEqual([])
expect(updatedVariant.inventory_items).toHaveLength(1)
})
})
})