xogroup / felicity

Javascript object constructors and sample data based on Joi schema.
Other
111 stars 9 forks source link

specialRules can not be chained with min, max or length #132

Closed christophediprima closed 6 years ago

christophediprima commented 6 years ago

All is in the the title. I noticed that it was not working when trying to generate following schema:

const schema = Joi.string().trim().hex().min(128).max(128);
WesTyler commented 6 years ago

What was the output you were seeing? Where you using entityFor or example? Was this on one of those two base Felicity methods, or did you create an instance of an entityFor constructor and call its .validate or .example method?

What version of Felicity? What version of Joi? What version of Node?

christophediprima commented 6 years ago

Sorry not having followed the issue creation rules.

const schema = Joi.string().trim().hex().min(128).max(130);
const example = Felicity.example(schema);

Joi.validate(example, schema,
      (err, value) => {
        console.log(err, value);
      },
);

err => { ValidationError: "value" length must be at least 128 characters long
  isJoi: true,
  name: 'ValidationError',
  details:
   [ { message: '"value" length must be at least 128 characters long',
       path: [],
       type: 'string.min',
       context: [Object] } ],
  _object: '5D99159B65BB422AfaaFD8527ebCd1f0Bf2AaB1Db1',
  annotate: [Function] } 

value => 5D99159B65BB422AfaaFD8527ebCd1f0Bf2AaB1Db1
{ limit: 2.5774820181409206,
  offset: 3.5828981336592483,
  search: { text_search: '' } }
WesTyler commented 6 years ago

No worries! Thank you for the additional info, it is super helpful in diagnosing the issue! I'm looking at this later this afternoon.

christophediprima commented 6 years ago

Nice! I have been looking at the code and it looks like you are returning before passing in the "min max" when we have at least one special rule.

christophediprima commented 6 years ago

https://github.com/xogroup/felicity/blob/fa1abd3de9c9fc3f522d44180676a25918eee5cb/lib/valueGenerator.js#L205

WesTyler commented 6 years ago

Yep, sure enough. Not sure how this has gone this long without someone else running into this, haha.

WesTyler commented 6 years ago

This should be fixed in v2.4.1!

Thanks for reporting, and thank you for quickly getting back to me with the additional information!

christophediprima commented 6 years ago

Nice! Thanks for fixing it so quickly!