Skip to content

Commit

Permalink
Merge pull request #194 from Instabug/fix/instabug_http_client
Browse files Browse the repository at this point in the history
[MOB-5620] Fix/Instabug http client
  • Loading branch information
ymabdallah authored Aug 25, 2021
2 parents cc208f1 + 2b0ba48 commit 77fce9d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v10.0.1 (2021-08-25)

* Fixes an issue with http client logger.

## v10.0.0 (2021-08-04)

* Bumps Instabug native SDKs to v10.8
Expand Down
2 changes: 1 addition & 1 deletion lib/models/network_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NetworkData {
NetworkData(
url: url ?? this.url,
method: method ?? this.method,
requestBody: requestBody ?? this.requestHeaders,
requestBody: requestBody ?? this.requestBody,
responseBody: responseBody ?? this.responseBody,
status: status ?? this.status,
requestHeaders: requestHeaders ?? this.requestHeaders,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/http_client_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HttpClientLogger {
return;
}

final responseHeaders = networkData.responseHeaders;
final responseHeaders = <String, dynamic>{};
request.headers.forEach((String header, dynamic value) {
responseHeaders[header] = value[0];
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: instabug_flutter
version: 10.0.0
version: 10.0.1
description: >-
Deliver the best user experience through a comprehensive platform that will
help you uncover, analyze and fix any app performance, quality or stability issues.
Expand Down
105 changes: 104 additions & 1 deletion test/instabug_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:instabug_flutter/InstabugLog.dart';
import 'package:instabug_flutter/NetworkLogger.dart';
import 'package:instabug_flutter/Replies.dart';
import 'package:instabug_flutter/Surveys.dart';
import 'package:instabug_flutter/instabug_custom_http_client.dart';
import 'package:instabug_flutter/models/crash_data.dart';
import 'package:instabug_flutter/models/exception_data.dart';
import 'package:instabug_flutter/models/network_data.dart';
Expand Down Expand Up @@ -44,6 +45,35 @@ void main() {
};
late MockPlatformManager mockPlatform;

const String url = 'https://jsonplaceholder.typicode.com';
const String method = 'POST';
final DateTime startDate = DateTime.now();
final DateTime endDate = DateTime.now().add(const Duration(hours: 1));
const dynamic requestBody = 'requestBody';
const dynamic responseBody = 'responseBody';
const int status = 200;
const Map<String, dynamic> requestHeaders = <String, dynamic>{
'request': 'request'
};
const Map<String, dynamic> responseHeaders = <String, dynamic>{
'response': 'response'
};
const int duration = 10;
const String contentType = 'contentType';
final NetworkData networkData = NetworkData(
url: url,
method: method,
startTime: startDate,
contentType: contentType,
duration: duration,
endTime: endDate,
requestBody: requestBody,
responseBody: responseBody,
requestHeaders: requestHeaders,
responseHeaders: responseHeaders,
status: status,
);

setUpAll(() async {
const MethodChannel('instabug_flutter')
.setMockMethodCallHandler((MethodCall methodCall) async {
Expand Down Expand Up @@ -823,7 +853,8 @@ void main() {
});

test('networkLog: Test', () async {
final data = NetworkData(method: 'method', url: 'url', startTime: DateTime.now());
final data =
NetworkData(method: 'method', url: 'url', startTime: DateTime.now());
final List<dynamic> args = <dynamic>[data.toMap()];
NetworkLogger.networkLog(data);
expect(log, <Matcher>[
Expand Down Expand Up @@ -873,4 +904,76 @@ void main() {
]);
}
});
test('Test NetworkData model ToMap', () async {
final newNetworkData = networkData.toMap();
expect(networkData.url, newNetworkData['url']);
expect(networkData.method, newNetworkData['method']);
expect(networkData.contentType, newNetworkData['contentType']);
expect(networkData.duration, newNetworkData['duration']);
expect(networkData.requestBody, newNetworkData['requestBody']);
expect(networkData.responseBody, newNetworkData['responseBody']);
expect(networkData.requestHeaders, newNetworkData['requestHeaders']);
expect(networkData.responseHeaders, newNetworkData['responseHeaders']);
});
test('Test NetworkData model CopyWith empty', () async {
final newNetworkData = networkData.copyWith();
final newNetworkDataMap = newNetworkData.toMap();
final networkDataMap = networkData.toMap();
networkDataMap.forEach((key, dynamic value) {
expect(value, newNetworkDataMap[key]);
});
});

test('Test NetworkData model CopyWith', () async {
const String urlCopy = 'https://jsonplaceholder.typicode.comCopy';
const String methodCopy = 'POSTCopy';
const dynamic requestBodyCopy = 'requestBodyCopy';
const dynamic responseBodyCopy = 'responseBodyCopy';
const Map<String, dynamic> requestHeadersCopy = <String, dynamic>{
'requestCopy': 'requestCopy'
};
const Map<String, dynamic> responseHeadersCopy = <String, dynamic>{
'responseCopy': 'responseCopy'
};
const int durationCopy = 20;
const String contentTypeCopy = 'contentTypeCopy';
final DateTime startDateCopy = DateTime.now().add(const Duration(days: 1));
final DateTime endDateCopy = DateTime.now().add(const Duration(days: 2));
const int statusCopy = 300;

final newNetworkData = networkData.copyWith(
url: urlCopy,
method: methodCopy,
requestBody: requestBodyCopy,
requestHeaders: requestHeadersCopy,
responseBody: responseBodyCopy,
responseHeaders: responseHeadersCopy,
duration: durationCopy,
contentType: contentTypeCopy,
startTime: startDateCopy,
endTime: endDateCopy,
status: statusCopy);

expect(newNetworkData.url, urlCopy);
expect(newNetworkData.method, methodCopy);
expect(newNetworkData.requestBody, requestBodyCopy);
expect(newNetworkData.requestHeaders, requestHeadersCopy);
expect(newNetworkData.responseBody, responseBodyCopy);
expect(newNetworkData.responseHeaders, responseHeadersCopy);
expect(newNetworkData.duration, durationCopy);
expect(newNetworkData.contentType, contentTypeCopy);
expect(newNetworkData.startTime, startDateCopy);
expect(newNetworkData.endTime, endDateCopy);
expect(newNetworkData.status, statusCopy);
});

test('Test Http client logger', () async {
final InstabugCustomHttpClient client = InstabugCustomHttpClient();
final HttpClientRequest request = await client
.getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts'));
client.logger.onRequest(request);
final HttpClientResponse response = await request.close();
client.logger.onResponse(response, request);
expect(client.requests.length, 0);
});
}

0 comments on commit 77fce9d

Please sign in to comment.