feat: Add batch method to collection and clean up some batch implementations (#7102)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-04-22 08:36:22 +00:00
1 parent 0f5b015df0
commit 89143e1032
26 files changed
+425 -123

No files matched your search

@@ -2844,7 +2844,7 @@ medusaIntegrationTestRunner({
}
const response = await api.post(
"/admin/products/op/batch",
"/admin/products/batch",
{
create: [createPayload],
update: [updatePayload],
@@ -2952,7 +2952,7 @@ medusaIntegrationTestRunner({
}
const response = await api.post(
`/admin/products/${createdProduct.id}/variants/op/batch`,
`/admin/products/${createdProduct.id}/variants/batch`,
{
create: [createPayload],
update: [updatePayload],
@@ -2983,6 +2983,40 @@ medusaIntegrationTestRunner({
}
)
})
it("successfully adds and removes products to a collection", async () => {
await breaking(
() => {},
async () => {
const response = await api.post(
`/admin/collections/${baseCollection.id}/products`,
{
add: [publishedProduct.id],
remove: [baseProduct.id],
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.added).toHaveLength(1)
expect(response.data.removed).toHaveLength(1)
const collection = (
await api.get(
`/admin/collections/${baseCollection.id}?fields=*products`,
adminHeaders
)
).data.collection
expect(collection.products).toHaveLength(1)
expect(collection.products[0]).toEqual(
expect.objectContaining({
id: publishedProduct.id,
})
)
}
)
})
})
// TODO: Discuss how this should be handled
@@ -334,7 +334,7 @@ medusaIntegrationTestRunner({
it("should delete an inventory location level and create a new one", async () => {
const result = await api.post(
`/admin/inventory-items/${inventoryItem.id}/location-levels/op/batch`,
`/admin/inventory-items/${inventoryItem.id}/location-levels/batch`,
{
create: [
{
@@ -618,23 +618,21 @@ medusaIntegrationTestRunner({
{ relations: ["prices"] }
)
const data = { product_id: [product.id] }
const data = { remove: [product.id] }
const response = await api.post(
`admin/price-lists/${priceList.id}/prices/batch`,
`admin/price-lists/${priceList.id}/products`,
data,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data).toEqual({
created: [],
updated: [],
deleted: {
ids: ["price-to-delete-1", "price-to-delete-2"],
object: "price",
deleted: true,
},
})
expect(response.data.price_list).toEqual(
expect.objectContaining({
id: expect.any(String),
title: "test price list",
description: "test",
})
)
})
})
})