Skip to content

Commit

Permalink
Add eq, toString and hash methods to HttpProfileRedirectData (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Mar 28, 2024
1 parent 70cf298 commit a283716
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
15 changes: 15 additions & 0 deletions pkgs/http_profile/lib/src/http_profile_response_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 49 additions & 5 deletions pkgs/http_profile/test/http_profile_response_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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('not 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<String, dynamic>;
final redirectsFromBackingMap =
Expand All @@ -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',
Expand Down

0 comments on commit a283716

Please sign in to comment.