feat: Make tags unique, clean up searchability of product entities (#7014)

This commit is contained in:
Stevche Radevski
2024-04-08 17:55:40 +02:00
committed by GitHub
parent 9b5e025863
commit db2f0ef53f
21 changed files with 105 additions and 299 deletions

View File

@@ -658,8 +658,7 @@ medusaIntegrationTestRunner({
}
})
// TODO: Enforce tag uniqueness in product module
it.skip("returns a list of products with tags", async () => {
it("returns a list of products with tags", async () => {
const response = await api.get(
`/admin/products?tags[]=${baseProduct.tags[0].id}`,
adminHeaders
@@ -668,26 +667,25 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual(
expect.arrayContaining(
[
expect.objectContaining({
id: baseProduct.id,
tags: [
expect.objectContaining({ id: baseProduct.tags[0].id }),
],
}),
],
expect.arrayContaining([
expect.objectContaining({
id: baseProduct.id,
tags: expect.arrayContaining([
expect.objectContaining({ id: baseProduct.tags[0].id }),
]),
}),
expect.objectContaining({
id: publishedProduct.id,
// It should be the same tag instance in both products
tags: [expect.objectContaining({ id: baseProduct.tags[0].id })],
})
)
tags: expect.arrayContaining([
expect.objectContaining({ id: baseProduct.tags[0].id }),
]),
}),
])
)
})
// TODO: Enforce tag uniqueness in product module
it.skip("returns a list of products with tags in a collection", async () => {
it("returns a list of products with tags in a collection", async () => {
const response = await api.get(
`/admin/products?collection_id[]=${baseCollection.id}&tags[]=${baseProduct.tags[0].id}`,
adminHeaders
@@ -700,7 +698,9 @@ medusaIntegrationTestRunner({
expect.objectContaining({
id: baseProduct.id,
collection_id: baseCollection.id,
tags: [expect.objectContaining({ id: baseProduct.tags[0].id })],
tags: expect.arrayContaining([
expect.objectContaining({ id: baseProduct.tags[0].id }),
]),
}),
])
)
@@ -2655,8 +2655,7 @@ medusaIntegrationTestRunner({
expect(response2.data.id).toEqual(res.data.product.id)
})
// TODO: We just need to return the correct error message
it.skip("should fail when creating a product with a handle that already exists", async () => {
it("should fail when creating a product with a handle that already exists", async () => {
// Lets try to create a product with same handle as deleted one
const payload = {
title: baseProduct.title,
@@ -2675,7 +2674,10 @@ medusaIntegrationTestRunner({
await api.post("/admin/products", payload, adminHeaders)
} catch (error) {
expect(error.response.data.message).toMatch(
"Product with handle test-product already exists."
breaking(
() => "Product with handle base-product already exists.",
() => "Product with handle: base-product already exists."
)
)
}
})