Skip to content

Commit

Permalink
chore: cleanup MockTransport, moving proper json handling to SentryRe…
Browse files Browse the repository at this point in the history
…quest
  • Loading branch information
vaind committed Nov 3, 2022
1 parent 4dc5a0e commit 110b200
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
6 changes: 3 additions & 3 deletions dart/lib/src/protocol/sentry_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class SentryRequest {
queryString: json['query_string'],
cookies: json['cookies'],
data: json['data'],
headers: json['headers'],
env: json['env'],
headers: json.containsKey('headers') ? Map.from(json['headers']) : null,
env: json.containsKey('env') ? Map.from(json['env']) : null,
// ignore: deprecated_member_use_from_same_package
other: json['other'],
other: json.containsKey('other') ? Map.from(json['other']) : null,
fragment: json['fragment'],
);
}
Expand Down
28 changes: 1 addition & 27 deletions dart/test/mocks/mock_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,7 @@ class MockTransport implements Transport {

final envelopeItem = utf8.decode(envelopeItemData);
final envelopeItemJson = jsonDecode(envelopeItem.split('\n').last);
final envelopeMap = envelopeItemJson as Map<String, dynamic>;
final requestJson = envelopeMap['request'] as Map<String, dynamic>?;

// TODO the following code should really be part of fromJson() that handle those keys.
// JSON being Map<String, dynamic> is nothing out of ordinary.
// See [SentryResponse.fromJson()] as an example.

// '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, String>'
final headersMap = requestJson?['headers'] as Map<String, dynamic>?;
final newHeadersMap = <String, String>{};
if (headersMap != null) {
for (final entry in headersMap.entries) {
newHeadersMap[entry.key] = entry.value as String;
}
envelopeMap['request']['headers'] = newHeadersMap;
}

final otherMap = requestJson?['other'] as Map<String, dynamic>?;
final newOtherMap = <String, String>{};
if (otherMap != null) {
for (final entry in otherMap.entries) {
newOtherMap[entry.key] = entry.value as String;
}
envelopeMap['request']['other'] = newOtherMap;
}

return SentryEvent.fromJson(envelopeMap);
return SentryEvent.fromJson(envelopeItemJson);
}

void reset() {
Expand Down

0 comments on commit 110b200

Please sign in to comment.