-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathhttp_request_data_test.dart
More file actions
70 lines (59 loc) · 2.24 KB
/
http_request_data_test.dart
File metadata and controls
70 lines (59 loc) · 2.24 KB
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
70
import 'package:devtools_app/src/shared/http/http_request_data.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('responseBytes', () {
Map<String, dynamic> baseJson(Map<String, Object?> headers) {
return {
'method': 'GET',
'uri': 'https://example.com',
'status': 200,
'responseHeaders': headers,
};
}
// Verifies parsing when content-length is a string value.
test('parses content-length from string', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': '1234'}),
null, // requestPostData not used for this test
null, // responseContent not used for this test
);
expect(request.responseBytes, 1234);
});
// Verifies parsing when content-length is a list of strings.
test('parses content-length from list of strings', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': '5678'}),
null, // requestPostData not used for this test
null, // responseContent not used for this test
);
expect(request.responseBytes, 5678);
});
// Ensures integer values inside a list are handled correctly.
test('handles integer in list', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': '91011'}),
null, // requestPostData not used for this test
null, // responseContent not used for this test
);
expect(request.responseBytes, 91011);
});
// Returns null when header is missing.
test('returns null for missing header', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({}), // No content-length header
null, // requestPostData not used for this test
null, // responseContent not used for this test
);
expect(request.responseBytes, null);
});
// Returns null when parsing fails.
test('returns null for invalid value', () {
final request = DartIOHttpRequestData.fromJson(
baseJson({'content-length': 'invalid'}),
null, // requestPostData not used for this test
null, // responseContent not used for this test
);
expect(request.responseBytes, null);
});
});
}