56 lines
1.5 KiB
Dart
56 lines
1.5 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jinzhi_flutter_app/common/push/push_api_client.dart';
|
|
import 'package:jinzhi_flutter_app/models/pb/jinzhi/v1/push.pb.dart' as pb;
|
|
|
|
void main() {
|
|
test(
|
|
'Retrofit push client uses generated protobuf in both directions',
|
|
() async {
|
|
final adapter = _PushAdapter();
|
|
final client = PushApiClient(
|
|
Dio(BaseOptions(responseType: ResponseType.bytes))
|
|
..httpClientAdapter = adapter,
|
|
);
|
|
|
|
final reply = await client.registerDevice(
|
|
pb.RegisterPushDeviceRequest(
|
|
umengDeviceToken: 'push-token',
|
|
platform: pb.Platform.PLATFORM_IOS,
|
|
appVersion: '1.1.0',
|
|
permissionGranted: true,
|
|
),
|
|
);
|
|
|
|
expect(reply.deviceRecordId, 'device-record');
|
|
final request = pb.RegisterPushDeviceRequest.fromBuffer(adapter.body!);
|
|
expect(request.umengDeviceToken, 'push-token');
|
|
expect(request.platform, pb.Platform.PLATFORM_IOS);
|
|
},
|
|
);
|
|
}
|
|
|
|
class _PushAdapter implements HttpClientAdapter {
|
|
List<int>? body;
|
|
|
|
@override
|
|
Future<ResponseBody> fetch(
|
|
RequestOptions options,
|
|
Stream<Uint8List>? requestStream,
|
|
Future<void>? cancelFuture,
|
|
) async {
|
|
body = (options.data as List<int>).toList();
|
|
return ResponseBody.fromBytes(
|
|
pb.RegisterPushDeviceReply(
|
|
deviceRecordId: 'device-record',
|
|
).writeToBuffer(),
|
|
200,
|
|
);
|
|
}
|
|
|
|
@override
|
|
void close({bool force = false}) {}
|
|
}
|