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

Add ability to use function for status #101

Open
smackfu opened this issue Jan 22, 2021 · 3 comments
Open

Add ability to use function for status #101

smackfu opened this issue Jan 22, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@smackfu
Copy link
Member

smackfu commented Jan 22, 2021

For more complex mocks, parrot supports passing a function as the body, which can be matched against the request object to return different responses.

See: https://github.com/americanexpress/parrot/blob/main/packages/parrot-core/src/utils/resolveResponse.js#L31

There are use-cases where it would be convenient to return a different http status code for different requests to the same endpoint.

Currently the status field does not support being passed a function:

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: () => 200
    at ServerResponse.writeHead (_http_server.js:248:11)
    at ServerResponse._implicitHeader (_http_server.js:239:8)
    at write_ (_http_outgoing.js:654:9)
    at ServerResponse.end (_http_outgoing.js:766:5)
@github-actions
Copy link

Thanks for opening your first issue. Pull requests are always welcome!

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity.

@ghost
Copy link

ghost commented Mar 4, 2021

Sorry for the late response on this.

I think it would be good to support this but I'm not sure if having the response body and status both be function is the right way to do it. Should the response itself be a function from which you could return the body and status? I'm definitely open to suggestions.

@ghost ghost removed the stale-issue label Mar 4, 2021
@americanexpress americanexpress deleted a comment from github-actions bot Apr 9, 2021
@nellyk nellyk added enhancement New feature or request and removed stale-issue labels Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants