From fa997aac287a648c21af37d131e58080d382da61 Mon Sep 17 00:00:00 2001 From: DatDang Date: Mon, 4 Nov 2024 09:19:22 +0700 Subject: [PATCH] fixup! Implement SearchSnippet/get --- .../search_snippet_get_response.dart | 2 - .../search_snippet_get_method_test.dart | 72 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/lib/jmap/mail/email/search_snippet/search_snippet_get_response.dart b/lib/jmap/mail/email/search_snippet/search_snippet_get_response.dart index a6d864d..d5d9695 100644 --- a/lib/jmap/mail/email/search_snippet/search_snippet_get_response.dart +++ b/lib/jmap/mail/email/search_snippet/search_snippet_get_response.dart @@ -1,5 +1,4 @@ import 'package:jmap_dart_client/http/converter/account_id_converter.dart'; -import 'package:jmap_dart_client/http/converter/email_id_converter.dart'; import 'package:jmap_dart_client/http/converter/id_converter.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/method/method_response.dart'; @@ -13,7 +12,6 @@ part 'search_snippet_get_response.g.dart'; explicitToJson: true, converters: [ AccountIdConverter(), - EmailIdConverter(), IdConverter(), ] ) diff --git a/test/jmap/mail/email/search_snippet/search_snippet_get_method_test.dart b/test/jmap/mail/email/search_snippet/search_snippet_get_method_test.dart index 7e24511..f2c9adc 100644 --- a/test/jmap/mail/email/search_snippet/search_snippet_get_method_test.dart +++ b/test/jmap/mail/email/search_snippet/search_snippet_get_method_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http_mock_adapter/http_mock_adapter.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/core/error/method/error_method_response.dart'; +import 'package:jmap_dart_client/jmap/core/error/method/exception/error_method_response_exception.dart'; import 'package:jmap_dart_client/jmap/core/filter/filter.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/request/reference_path.dart'; @@ -205,5 +207,75 @@ void main() { searchSnippetGetResponse?.notFound, equals(notFoundEmailIds.map((emailId) => emailId.id))); }); + + test( + 'should return error if server returns error', + () async { + // arrange + final notFoundEmailIds = [EmailId(Id('some-email-id'))]; + final filter = EmailFilterCondition(text: 'some-text'); + dioAdapter.onPost( + '', + (server) => server.reply( + 200, + { + "sessionState": sessionState.value, + "methodResponses": [ + [ + "Email/query", + { + "accountId": accountId.id.value, + "ids": notFoundEmailIds.map((emailId) => emailId.id.value).toList(), + }, + "c0" + ], + [ + "error", + { + "type": "unknownMethod", + }, + "c1" + ] + ] + }, + ), + data: generateRequest( + foundSearchSnippets: [], + notFoundEmailIds: notFoundEmailIds, + filter: filter, + ), + ); + + final HttpClient httpClient = HttpClient(dio); + final processingInvocation = ProcessingInvocation(); + final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation); + + final emailQueryMethod = QueryEmailMethod(accountId) + ..filter = filter; + final emailQueryMethodInvocation = jmapRequestBuilder.invocation( + emailQueryMethod); + + final searchSnippetGetMethod = SearchSnippetGetMethod(accountId) + ..filter = filter; + searchSnippetGetMethod.addReferenceEmailIds( + processingInvocation.createResultReference( + emailQueryMethodInvocation.methodCallId, + ReferencePath.idsPath)); + final methodInvocation = jmapRequestBuilder.invocation(searchSnippetGetMethod); + + // act + final result = await (jmapRequestBuilder + ..usings(searchSnippetGetMethod.requiredCapabilities)) + .build() + .execute(); + + // assert + expect( + () => result.parse( + methodInvocation.methodCallId, + SearchSnippetGetResponse.fromJson), + throwsA(ErrorMethodResponseException(UnknownMethodResponse())) + ); + }); }); } \ No newline at end of file