-
Notifications
You must be signed in to change notification settings - Fork 17
Create calendar event maybe method #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
lib/jmap/mail/calendar/reply/calendar_event_maybe_method.dart
This file contains hidden or 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,28 @@ | ||
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'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'calendar_event_maybe_method.g.dart'; | ||
|
||
@JsonSerializable(converters: [ | ||
AccountIdConverter(), | ||
IdConverter(), | ||
]) | ||
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() => _$CalendarEventMaybeMethodToJson(this); | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/jmap/mail/calendar/reply/calendar_event_maybe_method.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
lib/jmap/mail/calendar/reply/calendar_event_maybe_response.dart
This file contains hidden or 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().parsingListEventId(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 hidden or 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])); | ||
}); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.