-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
266: Customize dio adapter r=brunoocasali a=ahmednfwela Fixes #138 this adds a new `MeiliSearchClient.withCustomDio` which can customize adapter and interceptors - [ ] Added Tests Co-authored-by: Ahmed Fwela <ahmednfwela@bdaya-dev.com>
- Loading branch information
Showing
7 changed files
with
133 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:dio/io.dart'; | ||
import 'package:meilisearch/meilisearch.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'utils/client.dart'; | ||
|
||
class TestInterceptor extends Interceptor { | ||
bool onRequestCalled = false; | ||
@override | ||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) { | ||
onRequestCalled = true; | ||
super.onRequest(options, handler); | ||
} | ||
} | ||
|
||
class TestAdapter extends IOHttpClientAdapter { | ||
bool fetchCalled = false; | ||
@override | ||
Future<ResponseBody> fetch(RequestOptions options, | ||
Stream<Uint8List>? requestStream, Future<void>? cancelFuture) { | ||
fetchCalled = true; | ||
return super.fetch(options, requestStream, cancelFuture); | ||
} | ||
} | ||
|
||
void main() { | ||
group('Custom dio', () { | ||
test('Interceptor', () async { | ||
final interceptor = TestInterceptor(); | ||
final client = MeiliSearchClient.withCustomDio( | ||
testServer, | ||
apiKey: "masterKey", | ||
interceptors: [interceptor], | ||
); | ||
|
||
var health = await client.health(); | ||
|
||
expect(health, {'status': 'available'}); | ||
expect(interceptor.onRequestCalled, equals(true)); | ||
}); | ||
test("Adapter", () async { | ||
final adapter = TestAdapter(); | ||
final client = MeiliSearchClient.withCustomDio( | ||
testServer, | ||
apiKey: "masterKey", | ||
adapter: adapter, | ||
); | ||
|
||
var health = await client.health(); | ||
|
||
expect(health, {'status': 'available'}); | ||
expect(adapter.fetchCalled, equals(true)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters