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

js dynamic mocks ignored when request header set #28

Open
mr-miles opened this issue Jun 21, 2023 · 1 comment
Open

js dynamic mocks ignored when request header set #28

mr-miles opened this issue Jun 21, 2023 · 1 comment
Labels
bug Something isn't working PR-welcome PR is gladly appreciated

Comments

@mr-miles
Copy link

Hi,

We have noticed that this line

const accept = req.accepts(mock.type);
and L161
means that dynamic mocks are ignored if the accept header is set.

I think the correct behaviour should be to add "accepts" into the score, rather than to filter out completely.

Are you open to a PR for this?

@sinedied
Copy link
Owner

Hello,
Yes in the case of dynamic mocks you're right it should not be filtered out (that behavior is still valid in the case of static mocks though).
Something like this should work:

const accept = req.accepts(mock.type) || typeof mock.data === 'function'; 

In addition to the bypassing the filter for dynamic mocks, adding the "accept" to the score (1 if accepted, 0 otherwise) at all time would then be useful so that static mocks are matched first if the route is the same, and dynamic mocks can be used as a fallbacks.

If you have time for a PR, that would be gladly appreciated 🙏

@sinedied sinedied added bug Something isn't working PR-welcome PR is gladly appreciated labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR-welcome PR is gladly appreciated
Projects
None yet
Development

No branches or pull requests

2 participants