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

feat(mock): infer type from enum values for string and number #1491

Merged
merged 2 commits into from
Jun 30, 2024

Conversation

lnkarma
Copy link
Contributor

@lnkarma lnkarma commented Jun 29, 2024

Status

READY

Description

Fixes #1490 by infering type of enum if all enum values have same type and they are string or number

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

> cd tests
> yarn generate:mock
  1. Should generate a file at tests/generated/mock/typelessEnum/typelessEnums.ts with the following variable
export const getGetApiColorsResponseMock = (overrideResponse: Partial< ColorObject > = {}): ColorObject => ({color: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(Colors1)),faker.helpers.arrayElement(Object.values(Colors2))]), undefined]), ...overrideResponse})

formatted

export const getGetApiColorsResponseMock = (
  overrideResponse: Partial<ColorObject> = {},
): ColorObject => ({
  color: faker.helpers.arrayElement([
    faker.helpers.arrayElement([
      faker.helpers.arrayElement(Object.values(Colors1)),
      faker.helpers.arrayElement(Object.values(Colors2)),
    ]),
    undefined,
  ]),
  ...overrideResponse,
});
  1. The said variable should correctly have faker value for Colors2 for the color property

@melloware melloware added the mock Related to mock generation label Jun 30, 2024
@melloware melloware added this to the 6.32.0 milestone Jun 30, 2024
@melloware melloware merged commit 833faeb into orval-labs:master Jun 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mock Related to mock generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Referencing enums without types results in wrong faker value
2 participants