[v4] When running npm run test, hooks.before.httpServer not triggered? #1880
Answered
by
kempsteven
kempsteven
asked this question in
Help
-
In my hooks.before.httpServer(() => {
const Validator = use('Adonis/Addons/Validator')
const isUuid = require('uuid-validate')
Validator.extend('uuid', (data, field, message, args, get) => new Promise((resolve, reject) => {
const value = get(data, field)
if (!value) return
if (isUuid(value)) {
resolve('The field is a uuid')
return
}
reject(message)
}), 'The field is not a uuid')
}) So in my tests I created a test for updating orders: ...
const response = await client
.patch(`/orders/${order.id}`)
.loginVia(user, 'jwt')
.send(order)
.end()
.. Now in my controller I have a rule which validated if a property is a uuid: delivery_occurrence_id: 'required|uuid' and there is where I get the error: {
"message":"uuid is not defined as a validation rule",
"field":"delivery_occurrence_id",
"validation":"ENGINE_EXCEPTION"
}', |
Beta Was this translation helpful? Give feedback.
Answered by
kempsteven
Nov 9, 2020
Replies: 1 comment
-
The problem was that I extended the validator at the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kempsteven
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem was that I extended the validator at the
before.httpServer
hook event and I should have set it atbefore.providersBooted
.