ccarruitero / ccarruitero/makemehapi
the "validation using joi" assignment does not test for the first criterium
- Dominant language
- JavaScript
- Stars
- 480
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
The assignment states that if `isGuest` is false, a username is required, but it clearly does not test for this.
The solution shows the code you wanted to see was along the lines of
```
validate: {
payload: Joi.object({
isGuest: Joi.boolean().required(),
username: Joi.when('isGuest', { is: false, then: Joi.required() }),
password: Joi.string().alphanum(),
accessToken: Joi.string().alphanum()
}).options({ allowUnknown: true }).without('password', 'accessToken')
}
```
however, the following code passes just fine (which is just as well, the assignment taught me nothing about how to use Joi, I kind of tried stuff until this assignment passed so I could move on)
```
validate: {
payload: Joi.object({
isGuest: Joi.boolean(),
username: Joi.string(),
accessToken: Joi.string().alphanum(),
password: Joi.string().alphanum()
})
.options({allowUnknown: true})
.without('password', 'accessToken')
}
```
Even with this, the "official solution" looks like it doesn't even say what type `username` has to be. I don't dig Joi after these two assignments at all, it's been more revealed as quite a hassle and worth passing up in favour of a more user-friendly POST data validator
Contributor guide
Assessment
This issue has not been assessed yet.