-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_utils.dart
69 lines (60 loc) · 1.67 KB
/
test_utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
Matcher matchHttpRequest({
required String method,
String path = '',
Map<String, String> queryParameters = const {},
}) {
return MatchRequest(
method: method,
path: path,
queryParameters: queryParameters,
);
}
class MatchRequest extends Matcher {
const MatchRequest({
required this.method,
required this.path,
required this.queryParameters,
});
static const DeepCollectionEquality queryParametersEquality =
DeepCollectionEquality.unordered();
final String method;
final String path;
final Map<String, String> queryParameters;
@override
Description describe(Description description) {
return description
.add('Method: $method\n')
.add('Path: $path\n')
.add('Query Parameters: ')
.addDescriptionOf(queryParameters);
}
@override
Description describeMismatch(
dynamic item,
Description mismatchDescription,
Map<dynamic, dynamic> matchState,
bool verbose,
) {
assert(item is http.Request);
final req = item as http.Request;
return mismatchDescription
.add('Method: ${req.method}\n')
.add('Path: ${req.url.path}\n')
.add('Query Parameters: ')
.addDescriptionOf(req.url.queryParameters);
}
@override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
assert(item is http.Request);
final req = item as http.Request;
return req.method == method &&
req.url.path == path &&
queryParametersEquality.equals(
req.url.queryParameters,
queryParameters,
);
}
}