From 0bf9f2c289ae12b5a152117532dec01897014e6f Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 28 Mar 2024 11:26:02 -0700 Subject: [PATCH 1/3] Add eq, toString and hash methods to HttpProfileRedirectData --- .../lib/src/http_profile_response_data.dart | 15 ++++++ .../test/http_profile_response_data_test.dart | 54 +++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) 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', From b7c8b2eb933252445c8b1be810c2c51b3c991516 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 28 Mar 2024 11:27:18 -0700 Subject: [PATCH 2/3] Update http_profile_response_data_test.dart --- .../test/http_profile_response_data_test.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 0cf2439854..177eac5ce8 100644 --- a/pkgs/http_profile/test/http_profile_response_data_test.dart +++ b/pkgs/http_profile/test/http_profile_response_data_test.dart @@ -87,13 +87,13 @@ void main() { expect(redirectFromBackingMap['method'], 'GET'); expect(redirectFromBackingMap['location'], 'https://images.example.com/1'); - expect( - profile.responseData.redirects, - HttpProfileRedirectData( - statusCode: 301, - method: 'GET', - 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', From 2434dee3f5f1e4484b642a73b91881220368f90a Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 28 Mar 2024 12:43:42 -0700 Subject: [PATCH 3/3] Update http_profile_response_data_test.dart --- pkgs/http_profile/test/http_profile_response_data_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 177eac5ce8..646c3e6729 100644 --- a/pkgs/http_profile/test/http_profile_response_data_test.dart +++ b/pkgs/http_profile/test/http_profile_response_data_test.dart @@ -35,7 +35,7 @@ void main() { statusCode: 302, method: 'GET', location: 'http://somewhere')); }); - test('equal', () { + test('not equal', () { expect( HttpProfileRedirectData( statusCode: 302, method: 'GET', location: 'http://somewhere'),