Skip to content

Invalid mock returned if schema uses any.when #157

Description

@JesKingDev

Context

  • node version: v14.21.2
  • felicity version: 6.0.0
  • environment (node, browser): MacBook M1
  • any relevant modules used with (hapi, hoek, etc.): link to package.json
  • any other relevant information:

To Reproduce
What are you trying to achieve or the steps to reproduce ?
Please include any relevant Joi schemas.

When the Joi schema uses the any.when(condition,options) API, an invalid mock is returned.
Example Schema

priceCents: Joi.number().when('.fundType', {
        is  : FUND_TYPES.FIXED,
        then: Joi.number()
            .min(1)
            .max(100000)
            .required(),
        otherwise: Joi.forbidden().default(100)
    }),

The conditional is not respected; when running tests against a schema containing the above snippet, the following fails on validation:

const instance = felicity.entityFor(schema);
const mock = entity.generateMock();
const result = instance.validate(mock);

Expected behavior
The generated mock should be valid for the Joi schema passed to the Felicity API.

Observed behavior
The generated mock fails validation.

Example Mock A - condition is satisfied, but the value is NaN
CleanShot 2023-01-14 at 08 37 28@2x

Example Mock B - condition is not satisfied, but the value is populated.
CleanShot 2023-01-14 at 23 12 42@2x

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions