Feat(core-flows, inventory-next, medusa, types): Add create inventory item endpoint (#6693)
* init create inventory item * fix integration tests * pr feedback * rename to validate * pr feedback * bulk delete * undo change w/ naming * update dto body * move integration test * pr fixes * fix for pr review * revert medusa-config changes * pr feedback * fix build
This commit is contained in:
@@ -417,32 +417,12 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip("Create inventory items", () => {
|
||||
describe("Create inventory items", () => {
|
||||
it("should create inventory items", async () => {
|
||||
const createResult = await api.post(
|
||||
`/admin/products`,
|
||||
{
|
||||
title: "Test Product",
|
||||
variants: [
|
||||
{
|
||||
title: "Test Variant w. inventory 2",
|
||||
sku: "MY_SKU1",
|
||||
material: "material",
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const inventoryItems = await service.list()
|
||||
|
||||
expect(inventoryItems).toHaveLength(0)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/inventory-items`,
|
||||
{
|
||||
sku: "test-sku",
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -454,143 +434,6 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should attach inventory items on creation", async () => {
|
||||
const createResult = await api.post(
|
||||
`/admin/products`,
|
||||
{
|
||||
title: "Test Product",
|
||||
variants: [
|
||||
{
|
||||
title: "Test Variant w. inventory 2",
|
||||
sku: "MY_SKU1",
|
||||
material: "material",
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const inventoryItems = await service.list()
|
||||
|
||||
expect(inventoryItems).toHaveLength(0)
|
||||
|
||||
await api.post(
|
||||
`/admin/inventory-items`,
|
||||
{
|
||||
sku: "test-sku",
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const remoteQuery = appContainer.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_QUERY
|
||||
)
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: "product_variant_inventory_item",
|
||||
variables: {
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
fields: ["inventory_item_id", "variant_id"],
|
||||
})
|
||||
|
||||
const existingItems = await remoteQuery(query)
|
||||
|
||||
expect(existingItems).toHaveLength(1)
|
||||
expect(existingItems[0].variant_id).toEqual(
|
||||
createResult.data.product.variants[0].id
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip("Create inventory items", () => {
|
||||
it("should create inventory items", async () => {
|
||||
const createResult = await api.post(
|
||||
`/admin/products`,
|
||||
{
|
||||
title: "Test Product",
|
||||
variants: [
|
||||
{
|
||||
title: "Test Variant w. inventory 2",
|
||||
sku: "MY_SKU1",
|
||||
material: "material",
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const inventoryItems = await service.list({})
|
||||
|
||||
expect(inventoryItems).toHaveLength(0)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/inventory-items`,
|
||||
{
|
||||
sku: "test-sku",
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.inventory_item).toEqual(
|
||||
expect.objectContaining({
|
||||
sku: "test-sku",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should attach inventory items on creation", async () => {
|
||||
const createResult = await api.post(
|
||||
`/admin/products`,
|
||||
{
|
||||
title: "Test Product",
|
||||
variants: [
|
||||
{
|
||||
title: "Test Variant w. inventory 2",
|
||||
sku: "MY_SKU1",
|
||||
material: "material",
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const inventoryItems = await service.list({})
|
||||
|
||||
expect(inventoryItems).toHaveLength(0)
|
||||
|
||||
await api.post(
|
||||
`/admin/inventory-items`,
|
||||
{
|
||||
sku: "test-sku",
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const remoteQuery = appContainer.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_QUERY
|
||||
)
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: "product_variant_inventory_item",
|
||||
variables: {
|
||||
variant_id: createResult.data.product.variants[0].id,
|
||||
},
|
||||
fields: ["inventory_item_id", "variant_id"],
|
||||
})
|
||||
|
||||
const existingItems = await remoteQuery(query)
|
||||
|
||||
expect(existingItems).toHaveLength(1)
|
||||
expect(existingItems[0].variant_id).toEqual(
|
||||
createResult.data.product.variants[0].id
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("List inventory items", () => {
|
||||
|
||||
Reference in New Issue
Block a user