feature: introduce additional_data to the product endpoints (#8405)

This commit is contained in:
Harminder Virk
2024-08-05 09:24:49 +05:30
committed by GitHub
parent bcad5052af
commit 0706bab663
30 changed files with 219 additions and 258 deletions
@@ -21,22 +21,20 @@ describe("defineMiddlewares", function () {
})
})
test("should wrap body extendedValidator to middleware", () => {
test("should wrap additionalDataValidator to middleware", () => {
const req = {
body: {},
} as MedusaRequest
const res = {} as MedusaResponse
const nextFn = jest.fn()
const schema = zod.object({
const schema = {
brand_id: zod.string(),
})
}
const config = defineMiddlewares([
{
matcher: "/admin/products",
extendedValidators: {
body: schema,
},
additionalDataValidator: schema,
},
])
@@ -50,42 +48,10 @@ describe("defineMiddlewares", function () {
})
config.routes?.[0].middlewares?.[0](req, res, nextFn)
expect(req.extendedValidators).toMatchObject({
body: schema,
})
})
test("should wrap queryParams extendedValidator to middleware", () => {
const req = {
body: {},
} as MedusaRequest
const res = {} as MedusaResponse
const nextFn = jest.fn()
const schema = zod.object({
brand_id: zod.string(),
})
const config = defineMiddlewares([
expect(req.additionalDataValidator!.parse({ brand_id: "1" })).toMatchObject(
{
matcher: "/admin/products",
extendedValidators: {
queryParams: schema,
},
},
])
expect(config).toMatchObject({
routes: [
{
matcher: "/admin/products",
middlewares: [expect.any(Function)],
},
],
})
config.routes?.[0].middlewares?.[0](req, res, nextFn)
expect(req.extendedValidators).toMatchObject({
queryParams: schema,
})
brand_id: "1",
}
)
})
})