Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eq, toString and hash methods to HttpProfileRedirectData #1165

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
});
Comment on lines +30 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another test case below called "equal". I think you meant to delete this one, because the one below subsumes this one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to call the one below "not equal", which I've done now. Would you prefer that I combine the two tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. No, this is good. I misread the case below and thought these exact same lines appeared again, but they don't.


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