Add extra test
This commit is contained in:
parent
99b4aae7de
commit
50c8449f4b
|
@ -4,8 +4,9 @@ import { Ctx } from "@budibase/types"
|
|||
function validate(
|
||||
schema: Joi.ObjectSchema | Joi.ArraySchema,
|
||||
property: string,
|
||||
opts: { errorPrefix: string } = { errorPrefix: `Invalid ${property}` }
|
||||
opts?: { errorPrefix?: string; allowUnknown?: boolean }
|
||||
) {
|
||||
const errorPrefix = opts?.errorPrefix || `Invalid ${property}`
|
||||
// Return a Koa middleware function
|
||||
return (ctx: Ctx, next: any) => {
|
||||
if (!schema) {
|
||||
|
@ -28,10 +29,12 @@ function validate(
|
|||
})
|
||||
}
|
||||
|
||||
const { error } = schema.validate(params)
|
||||
const { error } = schema.validate(params, {
|
||||
allowUnknown: opts?.allowUnknown,
|
||||
})
|
||||
if (error) {
|
||||
let message = error.message
|
||||
if (opts.errorPrefix) {
|
||||
if (errorPrefix) {
|
||||
message = `Invalid ${property} - ${message}`
|
||||
}
|
||||
ctx.throw(400, message)
|
||||
|
@ -42,7 +45,7 @@ function validate(
|
|||
|
||||
export function body(
|
||||
schema: Joi.ObjectSchema | Joi.ArraySchema,
|
||||
opts?: { errorPrefix: string }
|
||||
opts?: { errorPrefix?: string; allowUnknown?: boolean }
|
||||
) {
|
||||
return validate(schema, "body", opts)
|
||||
}
|
||||
|
|
|
@ -11,9 +11,8 @@ export function rowActionValidator() {
|
|||
return middleware.joiValidator.body(
|
||||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
id: Joi.optional(),
|
||||
tableId: Joi.optional(),
|
||||
})
|
||||
}),
|
||||
{ allowUnknown: true }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,34 @@ describe("/rowsActions", () => {
|
|||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("ignores not valid row action data", async () => {
|
||||
const rowAction = createRowActionRequest()
|
||||
const dirtyRowAction = {
|
||||
...rowAction,
|
||||
id: generator.guid(),
|
||||
valueToIgnore: generator.word(),
|
||||
}
|
||||
const res = await createRowAction(tableId, dirtyRowAction, {
|
||||
status: 201,
|
||||
})
|
||||
|
||||
expect(res).toEqual({
|
||||
id: expect.any(String),
|
||||
tableId,
|
||||
...rowAction,
|
||||
})
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
actions: {
|
||||
[res.id]: {
|
||||
...rowAction,
|
||||
id: res.id,
|
||||
tableId: tableId,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("find", () => {
|
||||
|
|
Loading…
Reference in New Issue