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

fix(msw): return mock as array of enums if array is the correct type #1272

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

AllieJonsson
Copy link
Contributor

@AllieJonsson AllieJonsson commented Mar 19, 2024

Status

READY

Fix #1262

Description

Proposed fix for issue #1262
Other ideas, should the map method be typed? E.g.

export const getGetApiDogResponseMock = (overrideResponse: any = {}): Dog => ({
  petsRequested: faker.helpers.arrayElement([
    Array.from(
      { length: faker.number.int({ min: 1, max: 10 }) },
      (_, i) => i + 1,
    ).map<Bulldog>(() => ({
      //     ^ change here
      colour: faker.helpers.arrayElement([
        faker.helpers.arrayElement(['BLACK', 'BROWN'] as const),
        undefined,
      ]),
      ...overrideResponse,
    })),
    undefined,
  ]),
  ...overrideResponse,
});

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

  1. yarn build
  2. cd tests
  3. yarn generate:swr
  4. check in generated/swr/enums/endpoints, mocks of Cat should be ("BLACK" | "BROWN" | "WHITE" | "GREY")[] | undefined or ("BLACK" | "BROWN" | "WHITE" | "GREY")[], while mocks of Dog should be "BLACK" | "BROWN" | undefined or "BLACK" | "BROWN"

@melloware melloware added the mock Related to mock generation label Mar 19, 2024
@melloware melloware added this to the 6.26.0 milestone Mar 19, 2024
Copy link
Collaborator

@melloware melloware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@melloware melloware merged commit 150f49e into orval-labs:master Mar 19, 2024
2 checks passed
@AllieJonsson AllieJonsson deleted the fix/msw-array-of-enums branch March 19, 2024 14:58
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.

Required arrays of enums are returned as a single string in mocks
2 participants