Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is there a posibility to pass Joi options that override Joi default options to .expect() method? #484

Open
terradek opened this issue Aug 4, 2018 · 5 comments
Labels

Comments

@terradek
Copy link

terradek commented Aug 4, 2018

I'm using this method to pass it but I wonder if it's optimal enough?:

const joiOptions = { convert: false, presence: "required" };

frisby.timeout(2500)
    .post(baseUrl + '/auth/register' + urlOptions, user)
    .expect('jsonTypes', {
        meta: Joi.object({  status: Joi.string().valid('ok'),  error: Joi.equal(null)
        }).options(joiOptions),
        response: Joi.object({
            user: Joi.object({
                id: Joi.string().regex(/^[1-9]\d+/).min(1)
            }).options(joiOptions)
        }).options(joiOptions)

Thank you in advance

@H1Gdev
Copy link
Collaborator

H1Gdev commented Aug 5, 2018

@terradek

Yes.

Small sample code

const frisby = require('frisby');
const Joi = frisby.Joi;

const options = { convert: true };

it('Test', () => {
  return frisby.fromJSON({
    number: '1',
  })
    .expect('jsonTypes', Joi.object({
      number: Joi.number(),
    }).options(options));
});
const options = { convert: false };

Result

ValidationError: child "number" fails because ["number" must be a number]

@H1Gdev H1Gdev added the Question label Aug 5, 2018
@H1Gdev
Copy link
Collaborator

H1Gdev commented Aug 20, 2018

@terradek

Did you solve this issue?

@terradek
Copy link
Author

terradek commented Sep 5, 2018

@H1Gdev I thought there is a simpler method with passing defaults to .expect().
But this one works too.
Thank you!
PS It would be great to implement in future releases.

@terradek
Copy link
Author

terradek commented Oct 6, 2018

Voting this to be implemented in the next release as an optional parameter for expect().
Thank you.

@H1Gdev
Copy link
Collaborator

H1Gdev commented Oct 16, 2018

@vlucas

I think that proposal from @terradek is better.

path json options
data type string or array any object
optional mandatory optional

But if impletemt this, then need to change order of parameters.

.expect('jsonTypes', path, json)

to

.expect('jsonTypes', json, path, options)

And should also change order of json and jsonStrict, too.

I think that change of interface is very affected.

Do you have any good ideas?

@H1Gdev H1Gdev mentioned this issue Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants