-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da7a4a5
commit 7629f68
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
lib/jmap/mail/calendar/reply/calendar_event_maybe_method.dart
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,35 @@ | ||
import 'package:jmap_dart_client/http/converter/account_id_converter.dart'; | ||
import 'package:jmap_dart_client/http/converter/id_converter.dart'; | ||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; | ||
import 'package:jmap_dart_client/jmap/core/method/request/calendar_event_reply_method.dart'; | ||
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart'; | ||
|
||
class CalendarEventMaybeMethod extends CalendarEventReplyMethod { | ||
CalendarEventMaybeMethod(super.accountId, {required super.blobIds}); | ||
|
||
@override | ||
MethodName get methodName => MethodName('CalendarEvent/maybe'); | ||
|
||
@override | ||
Set<CapabilityIdentifier> get requiredCapabilities => { | ||
CapabilityIdentifier.jmapCore, | ||
CapabilityIdentifier.jamesCalendarEvent | ||
}; | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
final json = { | ||
'accountId': const AccountIdConverter().toJson(accountId), | ||
'blobIds': blobIds.map(const IdConverter().toJson).toList(), | ||
}; | ||
|
||
void writeNotNull(String key, dynamic value) { | ||
if (value == null) return; | ||
json[key] = value; | ||
} | ||
|
||
writeNotNull('language', language); | ||
|
||
return json; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
lib/jmap/mail/calendar/reply/calendar_event_maybe_response.dart
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,29 @@ | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/method/response/calendar_event_reply_response.dart'; | ||
import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart'; | ||
import 'package:jmap_dart_client/util/json_parsers.dart'; | ||
|
||
class CalendarEventMaybeResponse extends CalendarEventReplyResponse { | ||
CalendarEventMaybeResponse( | ||
super.accountId, | ||
super.notFound, | ||
{ | ||
this.maybe, | ||
this.notMaybe | ||
}); | ||
|
||
final List<EventId>? maybe; | ||
final List<Id>? notMaybe; | ||
|
||
static CalendarEventMaybeResponse deserialize(Map<String, dynamic> json) { | ||
return CalendarEventMaybeResponse( | ||
JsonParsers().parsingAccountId(json), | ||
JsonParsers().parsingListId(json, 'notFound'), | ||
maybe: JsonParsers().parsingEventId(json, 'maybe'), | ||
notMaybe: JsonParsers().parsingListId(json, 'notMaybe'), | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [...super.props, maybe, notMaybe]; | ||
} |
91 changes: 91 additions & 0 deletions
91
test/jmap/mail/calendar/reply/calendar_event_maybe_method_test.dart
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,91 @@ | ||
import 'package:dio/dio.dart'; | ||
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/id.dart'; | ||
import 'package:jmap_dart_client/jmap/core/method/request/calendar_event_reply_method.dart'; | ||
import 'package:jmap_dart_client/jmap/core/method/response/calendar_event_reply_response.dart'; | ||
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart'; | ||
import 'package:jmap_dart_client/jmap/jmap_request.dart'; | ||
import 'package:jmap_dart_client/jmap/mail/calendar/properties/event_id.dart'; | ||
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_method.dart'; | ||
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_maybe_response.dart'; | ||
|
||
void main() { | ||
final baseOption = BaseOptions(method: 'POST'); | ||
final dio = Dio(baseOption)..options.baseUrl = 'http://domain.com/jmap'; | ||
final dioAdapter = DioAdapter(dio: dio); | ||
final dioAdapterHeaders = {"accept": "application/json;jmapVersion=rfc-8621"}; | ||
final httpClient = HttpClient(dio); | ||
final processingInvocation = ProcessingInvocation(); | ||
final requestBuilder = JmapRequestBuilder(httpClient, processingInvocation); | ||
final accountId = AccountId(Id('123abc')); | ||
final successBlobId = Id('abc123'); | ||
final failureBlobId = Id('def456'); | ||
final notFoundBlobId = Id('ghi789'); | ||
final blobIds = [successBlobId, failureBlobId, notFoundBlobId]; | ||
final methodCallId = MethodCallId('c0'); | ||
|
||
Map<String, dynamic> constructData(CalendarEventReplyMethod method) => { | ||
"using": method.requiredCapabilities | ||
.map((capability) => capability.value.toString()) | ||
.toList(), | ||
"methodCalls": [ | ||
[ | ||
method.methodName.value, | ||
{ | ||
"accountId": accountId.id.value, | ||
"blobIds": blobIds.map((id) => id.value).toList(), | ||
}, | ||
methodCallId.value | ||
] | ||
] | ||
}; | ||
|
||
Map<String, dynamic> constructResponse(CalendarEventReplyMethod method) => { | ||
"sessionState": "abcdefghij", | ||
"methodResponses": [[ | ||
method.methodName.value, | ||
{ | ||
"accountId": accountId.id.value, | ||
"maybe": [successBlobId.value], | ||
"notMaybe": [failureBlobId.value], | ||
"notFound": [notFoundBlobId.value], | ||
}, | ||
methodCallId.value | ||
]] | ||
}; | ||
|
||
group('calendar event maybe method', () { | ||
final method = CalendarEventMaybeMethod(accountId, blobIds: blobIds); | ||
|
||
test('should succeed with success blob data, ' | ||
'and fail with failure blob data ' | ||
'and not found with not found blob data', () async { | ||
// arrange | ||
final invocation = requestBuilder.invocation(method, methodCallId: methodCallId); | ||
dioAdapter.onPost( | ||
'', | ||
(server) => server.reply(200, constructResponse(method)), | ||
data: constructData(method), | ||
headers: dioAdapterHeaders, | ||
); | ||
|
||
// act | ||
final response = (await (requestBuilder..usings(method.requiredCapabilities)) | ||
.build() | ||
.execute()) | ||
.parse<CalendarEventReplyResponse>( | ||
invocation.methodCallId, | ||
CalendarEventMaybeResponse.deserialize); | ||
|
||
// assert | ||
expect( | ||
(response as CalendarEventMaybeResponse?)?.maybe, | ||
equals([EventId(successBlobId.value)])); | ||
expect(response?.notMaybe, equals([failureBlobId])); | ||
expect(response?.notFound, equals([notFoundBlobId])); | ||
}); | ||
}); | ||
} |