client property
MockClient
get
client
Create a client to use with RestProvider that responds to endpoints with predefined responses.
Implementation
MockClient get client => MockClient((req) async {
final statusCode = _statusCodeForMethod(req.method);
final reqMethodToEnum = _stubHttpEnumFromMethod(req.method);
final response = responses.firstWhereOrNull((e) {
final methodMatches = e.method == reqMethodToEnum || e.method == StubHttpMethod.any;
final urlMatches = req.url == Uri.parse('$baseEndpoint/${e.endpoint}');
return methodMatches && urlMatches;
});
if (response != null) {
return http.Response(response.response, statusCode);
}
return http.Response('endpoint ${req.method} ${req.url} is not stubbed', 422);
});