|
| 1 | +import 'package:devtools_app/src/shared/http/http_request_data.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('responseBytes', () { |
| 6 | + Map<String, dynamic> baseJson(Map<String, Object?> headers) { |
| 7 | + return { |
| 8 | + 'method': 'GET', |
| 9 | + 'uri': 'https://example.com', |
| 10 | + 'status': 200, |
| 11 | + 'responseHeaders': headers, |
| 12 | + }; |
| 13 | + } |
| 14 | + |
| 15 | + // Verifies parsing when content-length is a string value. |
| 16 | + test('parses content-length from string', () { |
| 17 | + final request = DartIOHttpRequestData.fromJson( |
| 18 | + baseJson({'content-length': '1234'}), |
| 19 | + null, // requestPostData not used for this test |
| 20 | + null, // responseContent not used for this test |
| 21 | + ); |
| 22 | + |
| 23 | + expect(request.responseBytes, 1234); |
| 24 | + }); |
| 25 | + |
| 26 | + // Verifies parsing when content-length is a list of strings. |
| 27 | + test('parses content-length from list of strings', () { |
| 28 | + final request = DartIOHttpRequestData.fromJson( |
| 29 | + baseJson({'content-length': '5678'}), |
| 30 | + null, // requestPostData not used for this test |
| 31 | + null, // responseContent not used for this test |
| 32 | + ); |
| 33 | + |
| 34 | + expect(request.responseBytes, 5678); |
| 35 | + }); |
| 36 | + |
| 37 | + // Ensures integer values inside a list are handled correctly. |
| 38 | + test('handles integer in list', () { |
| 39 | + final request = DartIOHttpRequestData.fromJson( |
| 40 | + baseJson({'content-length': '91011'}), |
| 41 | + null, // requestPostData not used for this test |
| 42 | + null, // responseContent not used for this test |
| 43 | + ); |
| 44 | + |
| 45 | + expect(request.responseBytes, 91011); |
| 46 | + }); |
| 47 | + |
| 48 | + // Returns null when header is missing. |
| 49 | + test('returns null for missing header', () { |
| 50 | + final request = DartIOHttpRequestData.fromJson( |
| 51 | + baseJson({}), // No content-length header |
| 52 | + null, // requestPostData not used for this test |
| 53 | + null, // responseContent not used for this test |
| 54 | + ); |
| 55 | + |
| 56 | + expect(request.responseBytes, null); |
| 57 | + }); |
| 58 | + |
| 59 | + // Returns null when parsing fails. |
| 60 | + test('returns null for invalid value', () { |
| 61 | + final request = DartIOHttpRequestData.fromJson( |
| 62 | + baseJson({'content-length': 'invalid'}), |
| 63 | + null, // requestPostData not used for this test |
| 64 | + null, // responseContent not used for this test |
| 65 | + ); |
| 66 | + |
| 67 | + expect(request.responseBytes, null); |
| 68 | + }); |
| 69 | + }); |
| 70 | +} |
0 commit comments