Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/jmap/identities/identity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class Identity with EquatableMixin {
@JsonKey(includeIfNull: false)
final String? email;

@JsonKey(includeIfNull: false)
final Set<EmailAddress>? cc;

@JsonKey(includeIfNull: false)
final Set<EmailAddress>? bcc;

Expand All @@ -48,7 +45,6 @@ class Identity with EquatableMixin {
this.description,
this.name,
this.email,
this.cc,
this.bcc,
this.replyTo,
this.textSignature,
Expand Down
4 changes: 0 additions & 4 deletions lib/jmap/identities/identity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions lib/jmap/identities/set/set_identity_method.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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/http/converter/set/set_method_properties_converter.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/method/request/set_method.dart';
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';

class SetIdentityMethod extends SetMethod<Identity> {
SetIdentityMethod(AccountId accountId) : super(accountId);

@override
MethodName get methodName => MethodName('Identity/set');

@override
Set<CapabilityIdentifier> get requiredCapabilities => {
CapabilityIdentifier.jmapCore,
CapabilityIdentifier.jmapSubmission
};

@override
Map<String, dynamic> toJson() {
final val = <String, dynamic>{
'accountId': const AccountIdConverter().toJson(accountId),
};

void writeNotNull(String key, dynamic value) {
if (value != null) {
val[key] = value;
}
}

writeNotNull('ifInState', ifInState?.value);
writeNotNull('create', create
?.map((id, create) => SetMethodPropertiesConverter().fromMapIdToJson(id, create.toJson())));
writeNotNull('update', update
?.map((id, update) => SetMethodPropertiesConverter().fromMapIdToJson(id, update.toJson())));
writeNotNull('destroy', destroy
?.map((destroyId) => IdConverter().toJson(destroyId)).toList());

return val;
}

@override
List<Object?> get props => [accountId, ifInState, create, update, destroy];
}
76 changes: 76 additions & 0 deletions lib/jmap/identities/set/set_identity_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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/http/converter/state_converter.dart';
import 'package:jmap_dart_client/http/converter/state_nullable_converter.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';

class SetIdentityResponse extends SetResponse<Identity> {
SetIdentityResponse(
AccountId accountId,
State newState, {
State? oldState,
Map<Id, Identity>? created,
Map<Id, Identity?>? updated,
Set<Id>? destroyed,
Map<Id, SetError>? notCreated,
Map<Id, SetError>? notUpdated,
Map<Id, SetError>? notDestroyed
}) : super(
accountId,
newState,
oldState: oldState,
created: created,
updated: updated,
destroyed: destroyed,
notCreated: notCreated,
notUpdated: notUpdated,
notDestroyed: notDestroyed
);

static SetIdentityResponse deserialize(Map<String, dynamic> json) {
return SetIdentityResponse(
const AccountIdConverter().fromJson(json['accountId'] as String),
const StateConverter().fromJson(json['newState'] as String),
oldState: StateNullableConverter().fromJson(json['oldState'] as String?),
created: (json['created'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
Identity.fromJson(value as Map<String, dynamic>))),
updated: (json['updated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
value != null ? Identity.fromJson(value as Map<String, dynamic>) : null)),
destroyed: (json['destroyed'] as List<dynamic>?)
?.map((id) => IdConverter().fromJson(id)).toSet(),
notCreated: (json['notCreated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
notUpdated: (json['notUpdated'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
notDestroyed: (json['notDestroyed'] as Map<String, dynamic>?)
?.map((key, value) => MapEntry(
IdConverter().fromJson(key),
SetError.fromJson(value))),
);
}

@override
List<Object?> get props => [
oldState,
newState,
created,
updated,
destroyed,
notCreated,
notUpdated,
notDestroyed
];
}
99 changes: 99 additions & 0 deletions test/jmap/identities/set_identity_method_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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/identities/identity.dart';
import 'package:jmap_dart_client/jmap/identities/set/set_identity_method.dart';
import 'package:jmap_dart_client/jmap/identities/set/set_identity_response.dart';
import 'package:jmap_dart_client/jmap/jmap_request.dart';

void main() {
group('test to json set identity method', () {
final expectedCreated = Identity(
id: IdentityId(Id('bc6d7c78-672a-45e9-b0de-1dfd2699020a')),
);

test('set identity method and response parsing', () async {
final baseOption = BaseOptions(method: 'POST');
final dio = Dio(baseOption)
..options.baseUrl = 'http://domain.com';
final dioAdapter = DioAdapter(dio: dio);
dioAdapter.onPost(
'/jmap',
(server) => server.reply(200, {
"sessionState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
"methodResponses": [
[
"Identity/set",
{
"accountId": "3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12",
"newState": "2c9f1b12-b35a-43e6-9af2-0106fb53a943",
"created": {
"dab246": {
"id": "bc6d7c78-672a-45e9-b0de-1dfd2699020a",
"mayDelete": true
}
}
},
"c0"
]
]
}),
data: {
"using": [
"urn:ietf:params:jmap:core",
"urn:ietf:params:jmap:submission"
],
"methodCalls": [
[
"Identity/set",
{
"accountId": "3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12",
"create": {
"dab246": {
"name": "User B1",
"email": "[email protected]",
"textSignature": "",
"htmlSignature": "<body><div>Dat T. Vu <br>Mobile Engineer <br>LINAGORA VIETNAM <br>A: 8th Floor (Toong VPBank Tower, No. 5 Dien Bien Phu Str., Ba Dinh Dist., Ha Noi <br>P: (+84) 366-769-439<br>E: [email protected]</div></body>"
}
}
},
"c0"
]
]
},
headers: {
"accept": "application/json;jmapVersion=rfc-8621",
"content-type": "application/json; charset=utf-8",
"content-length": 512
}
);

final setIdentityMethod = SetIdentityMethod(AccountId(Id('3ce33c876a726662c627746eb9537a1d13c2338193ef27bd051a3ce5c0fe5b12')))
..addCreate(Id('dab246'),
Identity(
name: 'User B1',
email: '[email protected]',
textSignature: Signature(''),
htmlSignature: Signature('<body><div>Dat T. Vu <br>Mobile Engineer <br>LINAGORA VIETNAM <br>A: 8th Floor (Toong VPBank Tower, No. 5 Dien Bien Phu Str., Ba Dinh Dist., Ha Noi <br>P: (+84) 366-769-439<br>E: [email protected]</div></body>')
)
);

final httpClient = HttpClient(dio);
final requestBuilder = JmapRequestBuilder(httpClient, ProcessingInvocation());
final setIdentityInvocation = requestBuilder.invocation(setIdentityMethod);
final response = await (requestBuilder
..usings(setIdentityMethod.requiredCapabilities))
.build()
.execute();

final setIdentityResponse = response.parse<SetIdentityResponse>(
setIdentityInvocation.methodCallId,
SetIdentityResponse.deserialize);

expect(setIdentityResponse!.created![Id('dab246')]!.id, equals(expectedCreated.id));
});
});
}