Skip to content

Commit

Permalink
Update Dio 5.0.0 (#140)
Browse files Browse the repository at this point in the history
* Update Dio 5.0.0

* Rollback collection 1.15.0

* Pump dart min version 2.15.0
  • Loading branch information
SebastianKlaiber authored and LukaGiorgadze committed Feb 14, 2023
1 parent fdd0bbc commit ba8c544
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/src/adapters/dio_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http_mock_adapter/src/mixins/mixins.dart';
import 'package:http_mock_adapter/src/response.dart';

/// [HttpClientAdapter] extension with data mocking and recording functionality.
class DioAdapter extends HttpClientAdapter with Recording, RequestHandling {
class DioAdapter with Recording, RequestHandling implements HttpClientAdapter {
/// State of [DioAdapter] that can be closed to prohibit functionality.
bool _isClosed = false;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MockDioError extends DioError implements MockResponse {
MockDioError({
required RequestOptions requestOptions,
Response? response,
DioErrorType type = DioErrorType.other,
DioErrorType type = DioErrorType.unknown,
dynamic error,
this.delay,
}) : super(
Expand Down
2 changes: 0 additions & 2 deletions lib/src/matchers/list_param.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:collection/collection.dart';
import 'package:dio/dio.dart';
// ignore: implementation_imports
import 'package:dio/src/parameter.dart' show ListParam;
import 'package:http_mock_adapter/src/matchers/matcher.dart';

/// Matches [ListParam] instance by comparing
Expand Down
2 changes: 0 additions & 2 deletions lib/src/matchers/matchers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:dio/dio.dart';
// ignore: implementation_imports
import 'package:dio/src/parameter.dart' show ListParam;
import 'package:http_mock_adapter/src/matchers/any.dart';
import 'package:http_mock_adapter/src/matchers/boolean.dart';
import 'package:http_mock_adapter/src/matchers/decimal.dart';
Expand Down
7 changes: 3 additions & 4 deletions lib/src/mixins/request_handling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
import 'package:http_mock_adapter/src/exceptions.dart';
import 'package:http_mock_adapter/src/handlers/request_handler.dart';
import 'package:http_mock_adapter/src/mixins/mixins.dart';
import 'package:http_mock_adapter/src/request.dart';
Expand All @@ -27,12 +26,12 @@ mixin RequestHandling on Recording {
'multipart/form-data; boundary=${data.boundary}';
options.headers[Headers.contentLengthHeader] = data.length.toString();
} else {
final _data = await dio.transformer.transformRequest(options);
final data = await dio.transformer.transformRequest(options);
List<int> bytes;
if (options.requestEncoder != null) {
bytes = options.requestEncoder!(_data, options);
bytes = options.requestEncoder!(data, options);
} else {
bytes = utf8.encode(_data);
bytes = utf8.encode(data);
}
options.headers[Headers.contentLengthHeader] = bytes.length.toString();
}
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ repository: https://github.com/lomsa-dev/http-mock-adapter
issue_tracker: https://github.com/lomsa-dev/http-mock-adapter/issues

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.15.0 <3.0.0"

dependencies:
collection: ^1.15.0
dio: ^4.0.0
http_parser: ^4.0.0
dio: ^5.0.0
http_parser: ^4.0.2

dev_dependencies:
lints: ^1.0.1
test: ^1.16.8
fake_async: ^1.2.0
lints: ^2.0.1
test: ^1.23.1
fake_async: ^1.3.1
12 changes: 4 additions & 8 deletions test/adapters/dio_adapter_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dio/dio.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
import 'package:http_mock_adapter/src/exceptions.dart';
import 'package:test/test.dart';

import '../utils.dart';
Expand All @@ -24,13 +25,8 @@ void main() {

expect(
() async => await dio.get('/route'),
throwsA(
predicate(
(DioError dioError) => dioError.message.startsWith(
'ClosedException',
),
),
),
throwsA(predicate(
(DioError dioError) => dioError.error is ClosedException)),
);
});

Expand All @@ -52,7 +48,7 @@ void main() {
test('delays error', () async {
const delay = 5000;
final dioError = DioError(
type: DioErrorType.response,
type: DioErrorType.badResponse,
requestOptions: RequestOptions(path: 'path'),
);

Expand Down
4 changes: 2 additions & 2 deletions test/extensions/matches_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void main() {
late DioAdapter dioAdapter;

setUpAll(() {
dio = Dio();
dio = Dio(BaseOptions(contentType: Headers.jsonContentType));
dioAdapter = DioAdapter(dio: dio);
});

Expand Down Expand Up @@ -247,7 +247,7 @@ void main() {
() => dio.get(path),
throwsA(predicate((e) =>
e is DioError &&
e.type == DioErrorType.other &&
e.type == DioErrorType.unknown &&
e.error is AssertionError)));
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/handlers/request_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() {
final mockResponseBody =
statusHandler(RequestOptions(path: '')) as MockResponseBody;

final resolvedData = await DefaultTransformer().transformResponse(
final resolvedData = await BackgroundTransformer().transformResponse(
RequestOptions(path: ''),
mockResponseBody,
);
Expand Down Expand Up @@ -61,7 +61,7 @@ void main() {
final mockResponseBody =
statusHandler(RequestOptions(path: '')) as MockResponseBody;

final resolvedData = await DefaultTransformer()
final resolvedData = await BackgroundTransformer()
.transformResponse(RequestOptions(path: ''), mockResponseBody);

expect(resolvedData, data);
Expand Down Expand Up @@ -91,7 +91,7 @@ void main() {
final mockResponseBody =
statusHandler(RequestOptions(path: '')) as MockResponseBody;

final resolvedData = await DefaultTransformer().transformResponse(
final resolvedData = await BackgroundTransformer().transformResponse(
RequestOptions(path: ''),
mockResponseBody,
);
Expand All @@ -106,7 +106,7 @@ void main() {
requestOptions: RequestOptions(
path: 'path',
),
type: DioErrorType.response,
type: DioErrorType.badResponse,
);

requestHandler.throws(
Expand Down
2 changes: 1 addition & 1 deletion test/matchers/http_matcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {
queryParameters: <String, dynamic>{},
): true,
Request(
route: path + '/url/request/matcher',
route: '$path/url/request/matcher',
method: RequestMethods.post,
queryParameters: <String, dynamic>{},
): false,
Expand Down
1 change: 0 additions & 1 deletion test/matchers/list_param_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:dio/dio.dart';
import 'package:dio/src/parameter.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
import 'package:test/test.dart';

Expand Down
6 changes: 1 addition & 5 deletions test/mixins/recording_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ void main() {
expect(
() async => await dio.get('/undefined'),
throwsA(
predicate(
(DioError dioError) => dioError.message.startsWith(
'Assertion failed',
),
),
predicate((DioError dioError) => dioError.error is AssertionError),
),
);
});
Expand Down
10 changes: 2 additions & 8 deletions test/mixins/request_handling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void main() {
'foo': 'bar',
},
headers: <String, Object?>{
Headers.contentTypeHeader: Headers.jsonContentType,
Headers.contentLengthHeader: Matchers.integer,
},
);
Expand All @@ -130,7 +129,7 @@ void main() {
statusCode: 500,
requestOptions: RequestOptions(path: path),
),
type: DioErrorType.response,
type: DioErrorType.badResponse,
);

tester.onGet(
Expand All @@ -143,12 +142,7 @@ void main() {
expect(
() async => await dio.get(path),
throwsA(
predicate(
(DioError error) =>
error is DioError &&
error is MockDioError &&
error.message == dioError.error.toString(),
),
predicate((DioError error) => error is MockDioError),
),
);
});
Expand Down

0 comments on commit ba8c544

Please sign in to comment.