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: allow unmocked when providing literal search params. #1614

Merged
merged 2 commits into from Jul 15, 2019

Conversation

mastermatt
Copy link
Member

fixes: #1421

There was inconsistent behavior around how search params were handled
when they were provided as part of a URI string to new Interceptors.
The issue happen to come to light when allowUnmocked was set.

The fix normalizes the behavior by refactoring the constructor of
Interceptor to look for literal search params. If present, they're
stripped from the path attribute and set via the query method.

As part of the work, Interceptor.query was modified to accept
URLSearchParams instances as valid input.

fixes: nock#1421

There was inconsistent behavior around how search params were handled
when they were provided as part of a URI string to new Interceptors.
The issue happen to come to light when `allowUnmocked` was set.

The fix normalizes the behavior by refactoring the constructor of
Interceptor to look for literal search params. If present, they're
stripped from the `path` attribute and set via the `query` method.

As part of the work, `Interceptor.query` was modified to accept
`URLSearchParams` instances as valid input.
@mastermatt mastermatt force-pushed the fix/literal-search-allow-mocked branch from faf417d to a953db4 Compare July 15, 2019 14:15
Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Tests look great and code changes look good too.

I'd prefer to throw when the querystring is specified more than once, though perhaps adding a TODO comment alongsside the test of the current behavior is fine. Changing the behavior of multiple calls to query() is probably better accomplished in a follow-on PR.

scope.done()
})

test('multiple set query keys use the first occurrence', async t => {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like using the last occurrence might make more sense… or perhaps it would be better to throw an error?

I've noticed that when there are multiple calls to reply(), one of them takes preference… and come to think of it, I forget which. Throwing an error seems nicer to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking the same thing. Since any change would be a breaking change, I thought it best to just add coverage of current expected functionality. I'll create an issue to add a breaking change and throw instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

For what it's worth, I'm not sure if people are ever deliberately using the library that way. It's not a documented behavior. So I'm not sure if it's a breaking change or a feature.

If we can ship it in 11.0, so much the better!

@mastermatt mastermatt merged commit f8d6cbb into nock:beta Jul 15, 2019
@mastermatt mastermatt deleted the fix/literal-search-allow-mocked branch July 15, 2019 14:58
@nockbot
Copy link
Collaborator

nockbot commented Jul 15, 2019

🎉 This PR is included in version 11.0.0-beta.25 🎉

The release is available on:

Your semantic-release bot 📦🚀

@paulmelnikow
Copy link
Member

Just want to say that I so appreciate the great work that you're doing on the library, @mastermatt! It's really great to have someone to dig through this with! Your contributions have been careful and thoughtful and they're having a big impact on the library. Many thanks! 🙌

@nockbot
Copy link
Collaborator

nockbot commented Aug 12, 2019

🎉 This PR is included in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this pull request Sep 4, 2019
fixes: #1421

There was inconsistent behavior around how search params were handled
when they were provided as part of a URI string to new Interceptors.
The issue happen to come to light when `allowUnmocked` was set.

The fix normalizes the behavior by refactoring the constructor of
Interceptor to look for literal search params. If present, they're
stripped from the `path` attribute and set via the `query` method.

As part of the work, `Interceptor.query` was modified to accept
`URLSearchParams` instances as valid input.
gr2m pushed a commit that referenced this pull request Sep 4, 2019
fixes: #1421

There was inconsistent behavior around how search params were handled
when they were provided as part of a URI string to new Interceptors.
The issue happen to come to light when `allowUnmocked` was set.

The fix normalizes the behavior by refactoring the constructor of
Interceptor to look for literal search params. If present, they're
stripped from the `path` attribute and set via the `query` method.

As part of the work, `Interceptor.query` was modified to accept
`URLSearchParams` instances as valid input.
gr2m pushed a commit that referenced this pull request Sep 5, 2019
fixes: #1421

There was inconsistent behavior around how search params were handled
when they were provided as part of a URI string to new Interceptors.
The issue happen to come to light when `allowUnmocked` was set.

The fix normalizes the behavior by refactoring the constructor of
Interceptor to look for literal search params. If present, they're
stripped from the `path` attribute and set via the `query` method.

As part of the work, `Interceptor.query` was modified to accept
`URLSearchParams` instances as valid input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants