fix: allow backorder variants to be added to cart even if no locations (#12083)
* fix: allow backorder variants to be added to cart even if no locations * document and unit test prepareConfirmInventoryInput
This commit is contained in:
@@ -151,7 +151,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
it("should succesffully create a cart", async () => {
|
||||
it("should successfully create a cart", async () => {
|
||||
const response = await api.post(
|
||||
`/store/carts`,
|
||||
{
|
||||
@@ -255,10 +255,10 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/line-items", () => {
|
||||
let shippingOption, shippingOptionExpensive
|
||||
let shippingOption, shippingOptionExpensive, stockLocation
|
||||
|
||||
beforeEach(async () => {
|
||||
const stockLocation = (
|
||||
stockLocation = (
|
||||
await api.post(
|
||||
`/admin/stock-locations`,
|
||||
{ name: "test location" },
|
||||
@@ -894,6 +894,67 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with manage_inventory true", () => {
|
||||
let inventoryItem
|
||||
beforeEach(async () => {
|
||||
await api.post(
|
||||
`/admin/products/${product.id}/variants/${product.variants[0].id}`,
|
||||
{ manage_inventory: true },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
inventoryItem = (
|
||||
await api.post(
|
||||
`/admin/inventory-items`,
|
||||
{ sku: "bottle" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.inventory_item
|
||||
})
|
||||
|
||||
describe("with allow_backorder true", () => {
|
||||
beforeEach(async () => {
|
||||
await api.post(
|
||||
`/admin/products/${product.id}/variants/${product.variants[0].id}`,
|
||||
{ allow_backorder: true },
|
||||
adminHeaders
|
||||
)
|
||||
})
|
||||
|
||||
it("should add item to cart even if no inventory locations", async () => {
|
||||
let response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("should add item to cart even if inventory is empty", async () => {
|
||||
await api.post(
|
||||
`/admin/inventory-items/${inventoryItem.id}/location-levels/batch`,
|
||||
{ create: [{ location_id: stockLocation.id }] },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
let response = await api.post(
|
||||
`/store/carts/${cart.id}/line-items`,
|
||||
{
|
||||
variant_id: product.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/line-items/:id", () => {
|
||||
|
||||
@@ -80,7 +80,7 @@ async function populateData(api: any) {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
await setTimeout(2000)
|
||||
await setTimeout(10000)
|
||||
}
|
||||
|
||||
process.env.ENABLE_INDEX_MODULE = "true"
|
||||
|
||||
@@ -153,7 +153,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
// Timeout to allow indexing to finish
|
||||
await setTimeout(4000)
|
||||
await setTimeout(10000)
|
||||
|
||||
const { data: results } = await fetchAndRetry(
|
||||
async () =>
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "../../../helpers/create-admin-user"
|
||||
import { setupTaxStructure } from "../fixtures"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
jest.setTimeout(100000)
|
||||
|
||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
||||
|
||||
@@ -165,6 +165,14 @@ medusaIntegrationTestRunner({
|
||||
inventory_item_id: inventoryItem.id,
|
||||
},
|
||||
},
|
||||
{
|
||||
[Modules.PRODUCT]: {
|
||||
variant_id: product_2.variants[0].id,
|
||||
},
|
||||
[Modules.INVENTORY]: {
|
||||
inventory_item_id: inventoryItem.id,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
await setupTaxStructure(taxModule)
|
||||
|
||||
Reference in New Issue
Block a user