ccarruitero / ccarruitero/makemehapi

the "validation using joi" assignment does not test for the first criterium

Open
#132 4 comments 1 reaction 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.