send method
Executes the request.
When an expectation was set, the assertion runs before the response is returned — a forgotten status check shows up at the call site, not three assertions later.
Implementation
Future<TestResponse> send() async {
final allHeaders = Map<String, String>.of(_headers);
if (_cookies.isNotEmpty) {
allHeaders['cookie'] =
_cookies.entries.map((e) => '${e.key}=${e.value}').join('; ');
}
var path = _path;
if (_queryParams.isNotEmpty) {
final query = Uri(queryParameters: _queryParams).query;
path = path.contains('?') ? '$path&$query' : '$path?$query';
}
final response = await _execute(_method, path, allHeaders, _body);
switch (_expectSuccess) {
case true:
response.assertSuccess();
case false:
response.assertFailure();
case null:
break;
}
return response;
}