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

query_params option for assert_path/3 does not handle array values correctly #168

Open
idlehands opened this issue Jan 14, 2025 · 2 comments

Comments

@idlehands
Copy link

When calling assert_path as like this on working code:

assert_path(~p"/my-path/", query_params: %{"my_key" => ["1", "2"]}

the assertion is erroring with the following error:

Expected query params to be "my_key=12" but got "my_key[]=1&my_key[]=2"

Looking further into it, it looks like PhoenixTest.Utils.stringify_keys_and_values/1 is the culprit.

I propose a fix where when the value of the query params is a list, it returns the params in the url array style.

After connecting with German over this, I plan to put in a PR to address this.

@idlehands
Copy link
Author

Ha! I was being optimistic. While that Utils function is part of the problem, the assert_query_params/2 function in PhoenixTest.Assertions will need some work as well. It's leveraging URI, which does not handle query params arrays, at all, let alone how Phoenix creates them.

@germsvel
Copy link
Owner

Thanks @idlehands! Yes, I think both the stringify_keys_and_values/1 and the usage of URI in assert_query_params/2 will have issues with lists in queries. But I agree this is something we should fix (honestly surprised we didn't think of it the first time around).

Thanks for planning on opening a PR! Let me know if I can help with anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants