fix: API validation management issues (#9693)

**What**
Currently, the API validation layer is broken in both responsibilities and validation itself.
This pr introduce the following fixes and patterns:
- Always create a `*Fields` schema that only takes care of defining the schema validation without `effect`
- Use the previous point into the API schema validator including `$and` and `$or` capabilities plus the recursive effects
- remove `normalizeArray` which does not have to exists since array are already treated as they should
- Add recursive transformation to take into account `$and` and `$or` as well or any other similar operators
- New util `applyAndAndOrOperators` to wrap the management of those operators and to be merged to an existing schema

Tasks
- [x] store domain
- [ ] admin domain
This commit is contained in:
Adrien de Peretti
2024-10-22 17:16:36 +02:00
committed by GitHub
parent 7b147aa651
commit 6b989353ac
12 changed files with 198 additions and 126 deletions

View File

@@ -8,6 +8,7 @@ import {
generateStoreHeaders,
} from "../../../../helpers/create-admin-user"
import { getProductFixture } from "../../../../helpers/fixtures"
import qs from "qs"
jest.setTimeout(30000)
@@ -639,6 +640,35 @@ medusaIntegrationTestRunner({
])
})
it("should list all products for a category using $and filters", async () => {
const category = await createCategory(
{ name: "test", is_internal: false, is_active: true },
[product.id]
)
const category2 = await createCategory(
{ name: "test2", is_internal: true, is_active: true },
[product4.id]
)
const searchParam = qs.stringify({
$and: [{ category_id: [category.id, category2.id] }],
})
const response = await api.get(
`/store/products?${searchParam}`,
storeHeaders
)
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: product.id,
}),
])
})
it("returns a list of ordered products by id ASC", async () => {
const response = await api.get("/store/products?order=id", storeHeaders)
expect(response.status).toEqual(200)