fix:对齐金值,主要注销,一键登录等方面修改
This commit is contained in:
1 parent
e29ed0a2c8
commit
6997a65c96
37 files changed
+3442
-514
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jinzhi_flutter_app/common/network/api_error_message.dart';
|
||||
import 'package:jinzhi_flutter_app/common/network/kratos_error_interceptor.dart';
|
||||
import 'package:jinzhi_flutter_app/models/pb/errors/errors.pb.dart' as errors;
|
||||
|
||||
void main() {
|
||||
test('decodes a protobuf error body before it reaches the UI', () async {
|
||||
final dio = Dio()
|
||||
..httpClientAdapter = _ErrorAdapter(
|
||||
errors.Status(
|
||||
code: 401,
|
||||
reason: 'INVALID_CODE',
|
||||
message: '验证码错误',
|
||||
).writeToBuffer(),
|
||||
)
|
||||
..interceptors.add(KratosErrorInterceptor());
|
||||
|
||||
await expectLater(
|
||||
dio.delete<void>(
|
||||
'/api/v1/me',
|
||||
options: Options(responseType: ResponseType.bytes),
|
||||
),
|
||||
throwsA(
|
||||
isA<DioException>().having(
|
||||
(error) => kratosDisplayMessage(error, fallback: '注销失败,请重试'),
|
||||
'display message',
|
||||
'验证码错误',
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
class _ErrorAdapter implements HttpClientAdapter {
|
||||
_ErrorAdapter(this._body);
|
||||
|
||||
final List<int> _body;
|
||||
|
||||
@override
|
||||
Future<ResponseBody> fetch(
|
||||
RequestOptions options,
|
||||
Stream<Uint8List>? requestStream,
|
||||
Future<void>? cancelFuture,
|
||||
) async => ResponseBody.fromBytes(
|
||||
_body,
|
||||
401,
|
||||
headers: {
|
||||
'content-type': ['application/x-protobuf'],
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
void close({bool force = false}) {}
|
||||
}
|
||||
Reference in new issue
Block a user