TF-1204 Add FirebaseRegistration/get method/response and write unit test
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import 'package:fcm/utils/firebase_utils.dart';
|
||||||
|
import 'package:jmap_dart_client/http/converter/id_converter.dart';
|
||||||
|
import 'package:jmap_dart_client/http/converter/properties_converter.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/method/request/get_method.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/request/request_invocation.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/request/result_reference.dart';
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'firebase_registration_get_method.g.dart';
|
||||||
|
|
||||||
|
@IdConverter()
|
||||||
|
@PropertiesConverter()
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class FirebaseRegistrationGetMethod extends GetMethodNoNeedAccountId {
|
||||||
|
|
||||||
|
FirebaseRegistrationGetMethod() : super();
|
||||||
|
|
||||||
|
@override
|
||||||
|
MethodName get methodName => MethodName('FirebaseRegistration/get');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Set<CapabilityIdentifier> get requiredCapabilities => {
|
||||||
|
CapabilityIdentifier.jmapCore,
|
||||||
|
FirebaseUtils.capabilityLinagoraFirebase,
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [methodName, ids, requiredCapabilities];
|
||||||
|
|
||||||
|
factory FirebaseRegistrationGetMethod.fromJson(Map<String, dynamic> json) => _$FirebaseRegistrationGetMethodFromJson(json);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() => _$FirebaseRegistrationGetMethodToJson(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import 'package:fcm/model/firebase_registration.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/jmap/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/method/response/get_response.dart';
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'firebase_registration_get_response.g.dart';
|
||||||
|
|
||||||
|
@StateConverter()
|
||||||
|
@IdConverter()
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class FirebaseRegistrationGetResponse extends GetResponseNoAccountId<FirebaseRegistration> {
|
||||||
|
|
||||||
|
FirebaseRegistrationGetResponse(
|
||||||
|
List<FirebaseRegistration> list,
|
||||||
|
List<Id>? notFound
|
||||||
|
) : super(list, notFound);
|
||||||
|
|
||||||
|
factory FirebaseRegistrationGetResponse.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$FirebaseRegistrationGetResponseFromJson(json);
|
||||||
|
|
||||||
|
static FirebaseRegistrationGetResponse deserialize(Map<String, dynamic> json) {
|
||||||
|
return FirebaseRegistrationGetResponse.fromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$FirebaseRegistrationGetResponseToJson(this);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [list, notFound];
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
class TypeName with EquatableMixin {
|
class TypeName with EquatableMixin {
|
||||||
|
static final mailboxType = TypeName('Mailbox');
|
||||||
|
static final emailType = TypeName('Email');
|
||||||
|
static final emailDelivery = TypeName('EmailDelivery');
|
||||||
|
|
||||||
final String value;
|
final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
|
||||||
|
|
||||||
class FCMUtils {
|
|
||||||
static final capabilityFCM = CapabilityIdentifier(Uri.parse('com:linagora:params:jmap:firebase:push'));
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||||
|
|
||||||
|
class FirebaseUtils {
|
||||||
|
static final capabilityLinagoraFirebase = CapabilityIdentifier(Uri.parse('com:linagora:params:jmap:firebase:push'));
|
||||||
|
}
|
||||||
@@ -235,6 +235,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.0"
|
version: "2.2.0"
|
||||||
|
http_mock_adapter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: http_mock_adapter
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.3.2"
|
||||||
http_multi_server:
|
http_multi_server:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -328,6 +335,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.2"
|
version: "1.0.2"
|
||||||
|
mockito:
|
||||||
|
dependency: "direct dev"
|
||||||
|
description:
|
||||||
|
name: mockito
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "5.2.0"
|
||||||
package_config:
|
package_config:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ dependencies:
|
|||||||
url: https://github.com/linagora/jmap-dart-client.git
|
url: https://github.com/linagora/jmap-dart-client.git
|
||||||
ref: master
|
ref: master
|
||||||
|
|
||||||
|
http_mock_adapter: 0.3.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
@@ -30,6 +32,7 @@ dev_dependencies:
|
|||||||
|
|
||||||
json_serializable: 6.2.0
|
json_serializable: 6.2.0
|
||||||
|
|
||||||
|
mockito: 5.2.0
|
||||||
flutter:
|
flutter:
|
||||||
|
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:fcm/method/get/firebase_registration_get_method.dart';
|
||||||
|
import 'package:fcm/method/get/firebase_registration_get_response.dart';
|
||||||
|
import 'package:fcm/model/device_client_id.dart';
|
||||||
|
import 'package:fcm/model/firebase_expired_time.dart';
|
||||||
|
import 'package:fcm/model/firebase_registration.dart';
|
||||||
|
import 'package:fcm/model/firebase_registration_id.dart';
|
||||||
|
import 'package:fcm/model/type_name.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/core/id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('test to json firebase registration get method', () {
|
||||||
|
final expectFirebaseRegistration1 = FirebaseRegistration(
|
||||||
|
id: FirebaseRegistrationId(Id('e50b2c1d-9553-41a3-b0a7-a7d26b599ee1')),
|
||||||
|
deviceClientId: DeviceClientId('b37ff8001ca0'),
|
||||||
|
expires: FirebaseExpiredTime(UTCDate(DateTime.parse('2018-07-31T00:13:21Z'))),
|
||||||
|
types: [TypeName.mailboxType],
|
||||||
|
);
|
||||||
|
|
||||||
|
final expectFirebaseRegistration2 = FirebaseRegistration(
|
||||||
|
id: FirebaseRegistrationId(Id('f2d0aab5-e976-4e8b-ad4b-b380a5b987e4')),
|
||||||
|
deviceClientId: DeviceClientId('X8980fc'),
|
||||||
|
expires: FirebaseExpiredTime(UTCDate(DateTime.parse('2018-07-12T05:55:00Z'))),
|
||||||
|
types: [TypeName.mailboxType, TypeName.emailType, TypeName.emailDelivery],
|
||||||
|
);
|
||||||
|
|
||||||
|
test('firebase registration get method and response parsing', () async {
|
||||||
|
final baseOption = BaseOptions(method: 'POST');
|
||||||
|
final dio = Dio(baseOption)..options.baseUrl = 'http://domain.com/jmap';
|
||||||
|
final dioAdapter = DioAdapter(dio: dio);
|
||||||
|
dioAdapter.onPost(
|
||||||
|
'',
|
||||||
|
(server) => server.reply(200, {
|
||||||
|
"sessionState": "2c9f1b12-b35a",
|
||||||
|
"methodResponses": [
|
||||||
|
[
|
||||||
|
"FirebaseRegistration/get",
|
||||||
|
{
|
||||||
|
"notFound": [],
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"id": "e50b2c1d-9553-41a3-b0a7-a7d26b599ee1",
|
||||||
|
"deviceClientId": "b37ff8001ca0",
|
||||||
|
"expires": "2018-07-31T00:13:21Z",
|
||||||
|
"types": ["Mailbox"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "f2d0aab5-e976-4e8b-ad4b-b380a5b987e4",
|
||||||
|
"deviceClientId": "X8980fc",
|
||||||
|
"expires": "2018-07-12T05:55:00Z",
|
||||||
|
"types": ["Mailbox", "Email", "EmailDelivery"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
data: {
|
||||||
|
"using": [
|
||||||
|
"urn:ietf:params:jmap:core",
|
||||||
|
"com:linagora:params:jmap:firebase:push"
|
||||||
|
],
|
||||||
|
"methodCalls": [
|
||||||
|
[
|
||||||
|
"FirebaseRegistration/get",
|
||||||
|
{},
|
||||||
|
"c0"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
"accept": "application/json;jmapVersion=rfc-8621",
|
||||||
|
"content-type": "application/json; charset=utf-8",
|
||||||
|
"content-length": 133
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
final httpClient = HttpClient(dio);
|
||||||
|
final processingInvocation = ProcessingInvocation();
|
||||||
|
final requestBuilder = JmapRequestBuilder(httpClient, processingInvocation);
|
||||||
|
|
||||||
|
final firebaseRegistrationGetMethod = FirebaseRegistrationGetMethod();
|
||||||
|
final firebaseRegistrationGetInvocation = requestBuilder.invocation(firebaseRegistrationGetMethod);
|
||||||
|
final response = await (requestBuilder
|
||||||
|
..usings(firebaseRegistrationGetMethod.requiredCapabilities))
|
||||||
|
.build()
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final resultList = response.parse<FirebaseRegistrationGetResponse>(
|
||||||
|
firebaseRegistrationGetInvocation.methodCallId,
|
||||||
|
FirebaseRegistrationGetResponse.deserialize
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(resultList?.list.length, equals(2));
|
||||||
|
expect(resultList?.list, containsAll([expectFirebaseRegistration1, expectFirebaseRegistration2]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user