-
Notifications
You must be signed in to change notification settings - Fork 41
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
Using query parameters in response data generation #151
Comments
Also, it could be really helpful for non- This works: test(
"test post mock",
() async {
final dio = Dio();
final dioAdapter = DioAdapter(dio: dio);
dio.httpClientAdapter = dioAdapter;
const path = 'https://example.com/';
dioAdapter.onPost(
path,
(request) => request.reply(
200,
{'message': 'Successfully mocked POST!'},
),
data: {"test": true},
);
final getResponse = await dio.post(
path,
data: {"test": true},
);
expect({'message': 'Successfully mocked POST!'}, getResponse.data);
},
); But this does not: test(
"test post mock",
() async {
final dio = Dio();
final dioAdapter = DioAdapter(dio: dio);
dio.httpClientAdapter = dioAdapter;
const path = 'https://example.com/';
dioAdapter.onPost(
path,
(request) => request.reply(
200,
{'message': 'Successfully mocked POST!'},
),
);
final getResponse = await dio.post(
path,
data: {"test": true},
);
expect({'message': 'Successfully mocked POST!'}, getResponse.data);
},
); Other mocking libraries I've seen allow for setting something like an |
This can already be done easily with the proper use of the (RequestOptions request) {
final queryParameters = request.queryParameters;
final statusQueryParameter =
queryParameters["status"] as String;
return statusQueryParameter;
);
} |
Description
I have an endpoint that responds with a list of objects that exhibit a timestamp. Because there are potentially a lot of these objects in the list I use to filter them with the help of two query parameters
startDate
andendDate
. I can mock it using this nice package, but the response is always the same. Is it possible to access thequeryParams
object in the callback for the request so that my data generation function can take the query parameters into account and filter the list before it returns?So something like this (either through an additional parameter or the existing
server
object):When I print out the
server
parameter I can see that it's an instance ofRequestMatcher
. In the code I can see that this actually has the request object already in there:Could we make the private
request
field (or add getters for thequeryParameters
/headers
) public so that the generated mock can depend on them?The text was updated successfully, but these errors were encountered: