diff --git a/pkgs/http_profile/lib/src/http_profile_response_data.dart b/pkgs/http_profile/lib/src/http_profile_response_data.dart index 920b97d601..7aead9e068 100644 --- a/pkgs/http_profile/lib/src/http_profile_response_data.dart +++ b/pkgs/http_profile/lib/src/http_profile_response_data.dart @@ -36,6 +36,21 @@ class HttpProfileRedirectData { 'method': _method, 'location': _location, }; + + @override + bool operator ==(Object other) => + (other is HttpProfileRedirectData) && + (statusCode == other.statusCode && + method == other.method && + location == other.location); + + @override + int get hashCode => Object.hashAll([statusCode, method, location]); + + @override + String toString() => + 'HttpProfileRedirectData(statusCode: $statusCode, method: $method, ' + 'location: $location)'; } /// Describes details about a response to an HTTP request. diff --git a/pkgs/http_profile/test/http_profile_response_data_test.dart b/pkgs/http_profile/test/http_profile_response_data_test.dart index a9bc9a827c..0cf2439854 100644 --- a/pkgs/http_profile/test/http_profile_response_data_test.dart +++ b/pkgs/http_profile/test/http_profile_response_data_test.dart @@ -26,6 +26,48 @@ void main() { backingMap = profileBackingMaps.lastOrNull!; }); + group('HttpProfileRedirectData', () { + test('equal', () { + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere'), + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere')); + }); + + test('equal', () { + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere'), + isNot(Object())); + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere'), + isNot(HttpProfileRedirectData( + statusCode: 303, method: 'GET', location: 'http://somewhere'))); + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere'), + isNot(HttpProfileRedirectData( + statusCode: 302, method: 'POST', location: 'http://somewhere'))); + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere'), + isNot(HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://notthere'))); + }); + + test('hash', () { + expect( + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere') + .hashCode, + HttpProfileRedirectData( + statusCode: 302, method: 'GET', location: 'http://somewhere') + .hashCode); + }); + }); + test('calling HttpClientRequestProfile.responseData.addRedirect', () async { final responseData = backingMap['responseData'] as Map; final redirectsFromBackingMap = @@ -45,11 +87,13 @@ void main() { expect(redirectFromBackingMap['method'], 'GET'); expect(redirectFromBackingMap['location'], 'https://images.example.com/1'); - expect(profile.responseData.redirects.length, 1); - final redirectFromGetter = profile.responseData.redirects.first; - expect(redirectFromGetter.statusCode, 301); - expect(redirectFromGetter.method, 'GET'); - expect(redirectFromGetter.location, 'https://images.example.com/1'); + expect( + profile.responseData.redirects, + HttpProfileRedirectData( + statusCode: 301, + method: 'GET', + location: 'https://images.example.com/1', + )); }); test('populating HttpClientRequestProfile.responseData.headersListValues',