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

Mocking route with query params #316

Open
cmjio opened this issue Apr 14, 2021 · 3 comments
Open

Mocking route with query params #316

cmjio opened this issue Apr 14, 2021 · 3 comments

Comments

@cmjio
Copy link

cmjio commented Apr 14, 2021

I am using MirageJS which uses pretender but the issue I think lies in pretender.

Trying to mock an API that uses RSQL as a query language. Requests look like the following /api/films?filter=genres=in=(comedy);actor=="Ryan Reynolds" with fairly complex query params. Is there any way to mock this exact URL?

I would have thought I could have done this.get('/films?filter=genres=in=(comedy);actor=="Ryan Reynolds"', () => {...}) but looks like the only route the will catch is mocking /films though currently using the request.queryParams it returns {filter: "genres"} and omits the rest of the query.

How might I, if at all mock API endpoints with specific queries appended to return different responses.

@xg-wang
Copy link
Member

xg-wang commented Apr 24, 2021

https:/pretenderjs/pretender/tree/54ea79ede7bbbf5bcebaac507f2ec9db6875f4a5#query-parameters
You can access from the request object:

const server = new Pretender(function() {
  this.get('/api/songs', request => request.queryParams.sortOrder);
});

Does this suffice the need?

@cmjio
Copy link
Author

cmjio commented May 3, 2021

For a simple query param yes, but when using the RSQL format it does not. From my example /films?filter=genres=in=(comedy);actor=="Ryan Reynolds" the queryParams object does not return the complex query in parts or even the full string.

As a simple approach even if it returned { filter: 'genres=in=(comedy);actor=="Ryan Reynolds"'} I would be happy, seems it ignores the = after genres

@xg-wang
Copy link
Member

xg-wang commented May 10, 2021

Looks like route-recognizer does not support the standard searchParams parsing, I just filed an issue there

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