Skip to content

Commit

Permalink
fixup! Implement SearchSnippet/get
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Nov 4, 2024
1 parent 9aeb0cb commit fa997aa
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,7 +12,6 @@ part 'search_snippet_get_response.g.dart';
explicitToJson: true,
converters: [
AccountIdConverter(),
EmailIdConverter(),
IdConverter(),
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<SearchSnippetGetResponse>(
methodInvocation.methodCallId,
SearchSnippetGetResponse.fromJson),
throwsA(ErrorMethodResponseException(UnknownMethodResponse()))
);
});
});
}

0 comments on commit fa997aa

Please sign in to comment.