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): fix response http status code in handler function #1400

Conversation

soartec-lab
Copy link
Member

Status

READY

Description

Currently, the http status code of the response in the handler function is fixed to 200. So I fixed it to use the first success response.

When using the following OpenaAPI

paths:
  /pets:
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      requestBody:
        description: post body
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
      responses:
        '201':
          description: Null response

Before

status fixed 200 in msw definition.

export const getCreatePetsMockHandler = () => {
  return http.post('*/pets', async () => {
    await delay(1000);
    return new HttpResponse(null,
      {
        status: 200,
        headers: {
          'Content-Type': 'application/json',
        }
      }
    )
  })
}

After

use 201 from OpenAPI definition.

export const getCreatePetsMockHandler = () => {
  return http.post('*/pets', async () => {
    await delay(1000);
    return new HttpResponse(null,
      {
        status: 201,
        headers: {
          'Content-Type': 'application/json',
        }
      }
    )
  })
}

Related PRs

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

You can check it by automatically generating it using the yaml prepared in the "Description".

@soartec-lab soartec-lab added the mock Related to mock generation label May 25, 2024
@soartec-lab soartec-lab added this to the 6.30.0 milestone May 25, 2024
@melloware melloware merged commit a7e6a18 into orval-labs:master May 25, 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.

2 participants