111
This commit is contained in:
1 parent
7c20242ad7
commit
382b8d660f
8 files changed
+802
-21
No files matched your search
@@ -0,0 +1,123 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pj_supermarket_cloud/common/models/api/hard_api_models.dart';
|
||||
import 'package:pj_supermarket_cloud/common/utils/order/terminal_order_recovery.dart';
|
||||
|
||||
void main() {
|
||||
ServiceOrderByAndroidCode snapshot({
|
||||
String status = '5',
|
||||
String payType = '4',
|
||||
String userId = '7',
|
||||
int total = 350,
|
||||
int extra = 0,
|
||||
int paid = 350,
|
||||
}) =>
|
||||
ServiceOrderByAndroidCode(
|
||||
orderId: '2109484384436817922',
|
||||
orderStatus: status,
|
||||
payType: payType,
|
||||
userId: userId,
|
||||
totalPrice: total,
|
||||
extraPrice: extra,
|
||||
payPrice: paid,
|
||||
);
|
||||
|
||||
Future<String?> recover(
|
||||
Future<ServiceOrderByAndroidCode?> Function() lookup, {
|
||||
String payType = '4',
|
||||
String? userId = '7',
|
||||
}) =>
|
||||
TerminalOrderRecovery.recover(
|
||||
lookup: lookup,
|
||||
payType: payType,
|
||||
userId: userId,
|
||||
totalPrice: 350,
|
||||
extraPrice: 0,
|
||||
interval: Duration.zero,
|
||||
attempts: 3,
|
||||
);
|
||||
|
||||
test('Long 订单号与数字金额按原有编码解析', () {
|
||||
final parsed = ServiceOrderByAndroidCode.fromJson({
|
||||
'orderId': '2109484384436817922',
|
||||
'orderStatus': '5',
|
||||
'payType': '4',
|
||||
'userId': 7,
|
||||
'totalPrice': '350',
|
||||
'extraPrice': 0,
|
||||
'payPrice': 350,
|
||||
});
|
||||
expect(parsed.orderId, '2109484384436817922');
|
||||
expect(parsed.userId, '7');
|
||||
expect(parsed.totalPrice, 350);
|
||||
});
|
||||
|
||||
test('请求超时和网关响应丢失可对账,明确业务拒绝及取消不轮询', () {
|
||||
for (final type in [
|
||||
DioExceptionType.connectionTimeout,
|
||||
DioExceptionType.sendTimeout,
|
||||
DioExceptionType.receiveTimeout,
|
||||
DioExceptionType.connectionError,
|
||||
]) {
|
||||
expect(
|
||||
TerminalOrderRecovery.shouldQuery(
|
||||
DioException(requestOptions: RequestOptions(), type: type),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
for (final status in [200, 400, 404, 502]) {
|
||||
final options = RequestOptions();
|
||||
expect(
|
||||
TerminalOrderRecovery.shouldQuery(
|
||||
DioException(
|
||||
requestOptions: options,
|
||||
type: DioExceptionType.badResponse,
|
||||
response: Response(requestOptions: options, statusCode: status),
|
||||
),
|
||||
),
|
||||
status == 502,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('等待原订单提交后找回成功结果,查询次数有界', () async {
|
||||
var calls = 0;
|
||||
final result = await recover(() async => ++calls < 3 ? null : snapshot());
|
||||
expect(result, '2109484384436817922');
|
||||
expect(calls, 3);
|
||||
});
|
||||
|
||||
test('后端未部署对账接口时查询失败保持未确认,不产生支付重放', () async {
|
||||
var calls = 0;
|
||||
final result = await recover(() async {
|
||||
calls++;
|
||||
throw StateError('404');
|
||||
});
|
||||
expect(result, isNull);
|
||||
expect(calls, 3);
|
||||
});
|
||||
|
||||
test('退款、人员、支付方式或金额不一致均不能恢复成功', () async {
|
||||
for (final invalid in [
|
||||
snapshot(status: '10'),
|
||||
snapshot(userId: '8'),
|
||||
snapshot(payType: '3'),
|
||||
snapshot(total: 351),
|
||||
snapshot(extra: 1),
|
||||
]) {
|
||||
expect(await recover(() async => invalid), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test('现金订单沿用实付零约定,使用商品额核对', () async {
|
||||
expect(
|
||||
await recover(
|
||||
() async => snapshot(payType: '8', userId: '-1', paid: 0),
|
||||
payType: '8',
|
||||
userId: null,
|
||||
),
|
||||
'2109484384436817922',
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user