TF-548 Implement datasource for getAutoComplete
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
## 0.0.1
|
||||
|
||||
* TODO: Describe initial release.
|
||||
@@ -1 +0,0 @@
|
||||
TODO: Add your license here.
|
||||
+2
-38
@@ -1,39 +1,3 @@
|
||||
<!--
|
||||
This README describes the package. If you publish this package to pub.dev,
|
||||
this README's contents appear on the landing page for your package.
|
||||
# contact
|
||||
|
||||
For information about how to write a good package README, see the guide for
|
||||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
|
||||
|
||||
For general information about developing packages, see the Dart guide for
|
||||
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
|
||||
and the Flutter guide for
|
||||
[developing packages and plugins](https://flutter.dev/developing-packages).
|
||||
-->
|
||||
|
||||
TODO: Put a short description of the package here that helps potential users
|
||||
know whether this package might be useful for them.
|
||||
|
||||
## Features
|
||||
|
||||
TODO: List what your package can do. Maybe include images, gifs, or videos.
|
||||
|
||||
## Getting started
|
||||
|
||||
TODO: List prerequisites and provide or point to information on how to
|
||||
start using the package.
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Include short and useful examples for package users. Add longer examples
|
||||
to `/example` folder.
|
||||
|
||||
```dart
|
||||
const like = 'sample';
|
||||
```
|
||||
|
||||
## Additional information
|
||||
|
||||
TODO: Tell users more about the package: where to find more information, how to
|
||||
contribute to the package, how to file issues, what response they can expect
|
||||
from the package authors, and more.
|
||||
Contact Module
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
import 'package:contact/contact/model/tmail_contact.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
|
||||
abstract class AutoCompleteDataSource {
|
||||
Future<List<TMailContact>> getAutoComplete(AccountId accountId, String word, {int? limit});
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:contact/contact/model/tmail_contact.dart';
|
||||
import 'package:contact/data/datasource/auto_complete_datasource.dart';
|
||||
import 'package:contact/data/network/contact_api.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
|
||||
class TMailContactDataSourceImpl extends AutoCompleteDataSource {
|
||||
|
||||
final ContactAPI _contactAPI;
|
||||
|
||||
TMailContactDataSourceImpl(this._contactAPI);
|
||||
|
||||
@override
|
||||
Future<List<TMailContact>> getAutoComplete(AccountId accountId, String word, {int? limit}) {
|
||||
return Future.sync(() async {
|
||||
return _contactAPI.getAutoComplete(accountId, word, limit: limit);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
import 'package:contact/contact/autocomplete/autocomplete_tmail_contact_method.dart';
|
||||
import 'package:contact/contact/autocomplete/autocomplete_tmail_contact_response.dart';
|
||||
import 'package:contact/contact/model/contact_filter.dart';
|
||||
import 'package:contact/contact/model/tmail_contact.dart';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||
|
||||
class ContactAPI {
|
||||
|
||||
final HttpClient _httpClient;
|
||||
|
||||
ContactAPI(this._httpClient);
|
||||
|
||||
Future<List<TMailContact>> getAutoComplete(AccountId accountId, String word, {int? limit}) async {
|
||||
final processingInvocation = ProcessingInvocation();
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
|
||||
|
||||
final autoCompleteMethod = AutoCompleteTMailContactMethod(accountId, ContactFilter(word));
|
||||
|
||||
final autoCompleteInvocation = requestBuilder.invocation(autoCompleteMethod);
|
||||
final response = await (requestBuilder
|
||||
..usings(autoCompleteMethod.requiredCapabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final result = response.parse<AutoCompleteTMailContactResponse>(
|
||||
autoCompleteInvocation.methodCallId,
|
||||
AutoCompleteTMailContactResponse.deserialize);
|
||||
|
||||
return result?.list ?? <TMailContact>[];
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ dev_dependencies:
|
||||
json_serializable: 6.1.4
|
||||
|
||||
http_mock_adapter: 0.3.2
|
||||
|
||||
mockito: 5.0.17
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
import 'package:contact/contact/model/tmail_contact.dart';
|
||||
import 'package:contact/data/datasource_impl/tmail_contact_datasource_impl.dart';
|
||||
import 'package:contact/data/network/contact_api.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
|
||||
import 'tmail_contact_datasource_impl_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([ContactAPI])
|
||||
void main() {
|
||||
final contact1 = TMailContact(
|
||||
'2',
|
||||
'',
|
||||
'',
|
||||
'marie@otherdomain.tld'
|
||||
);
|
||||
|
||||
final contact2 = TMailContact(
|
||||
'4',
|
||||
'Marie',
|
||||
'Dupond',
|
||||
'mdupond@linagora.com'
|
||||
);
|
||||
|
||||
group('tmail_contact_datasource_impl_test', () {
|
||||
late ContactAPI _contactAPI;
|
||||
late TMailContactDataSourceImpl _tmailContactDataSourceImpl;
|
||||
|
||||
setUp(() {
|
||||
_contactAPI = MockContactAPI();
|
||||
_tmailContactDataSourceImpl = TMailContactDataSourceImpl(_contactAPI);
|
||||
});
|
||||
|
||||
test('getAutoComplete should return success with valid data', () async {
|
||||
when(_contactAPI.getAutoComplete(
|
||||
AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')),
|
||||
'marie'
|
||||
)).thenAnswer((_) async => [contact1, contact2]);
|
||||
|
||||
final result = await _tmailContactDataSourceImpl.getAutoComplete(
|
||||
AccountId(Id('29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6')),
|
||||
'marie'
|
||||
);
|
||||
expect(result, [contact1, contact2]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Mocks generated by Mockito 5.0.17 from annotations
|
||||
// in contact/test/datasource/tmail_contact_datasource_impl_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:contact/contact/model/tmail_contact.dart' as _i4;
|
||||
import 'package:contact/data/network/contact_api.dart' as _i2;
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart' as _i5;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
|
||||
/// A class which mocks [ContactAPI].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockContactAPI extends _i1.Mock implements _i2.ContactAPI {
|
||||
MockContactAPI() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.TMailContact>> getAutoComplete(
|
||||
_i5.AccountId? accountId, String? word, {int? limit}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getAutoComplete, [accountId, word], {#limit: limit}),
|
||||
returnValue:
|
||||
Future<List<_i4.TMailContact>>.value(<_i4.TMailContact>[]))
|
||||
as _i3.Future<List<_i4.TMailContact>>);
|
||||
}
|
||||
Reference in New Issue
Block a user