38 lines
1.4 KiB
Dart
38 lines
1.4 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pj_supermarket_cloud/common/utils/discounts/terminal_discount_protocol.dart';
|
|
import 'package:pj_supermarket_cloud/common/utils/order/terminal_order_recovery.dart';
|
|
|
|
void main() {
|
|
DioException response(int status, Object? body) {
|
|
final request = RequestOptions();
|
|
return DioException(
|
|
requestOptions: request,
|
|
type: DioExceptionType.badResponse,
|
|
response:
|
|
Response(requestOptions: request, statusCode: status, data: body),
|
|
);
|
|
}
|
|
|
|
test('定价拒绝立即返回并保留重新确认所需证据,不进入超时对账', () {
|
|
final error = response(409, {'code': 40901, 'data': null});
|
|
expect(TerminalDiscountProtocol.isPricingRejected(error), isTrue);
|
|
expect(TerminalOrderRecovery.shouldQuery(error), isFalse);
|
|
});
|
|
|
|
test('其他冲突和未知支付错误不误判为定价拒绝', () {
|
|
for (final error in [
|
|
response(409, {'code': 1}),
|
|
response(409, 'conflict'),
|
|
response(500, {'code': 40901}),
|
|
DioException(
|
|
requestOptions: RequestOptions(),
|
|
type: DioExceptionType.receiveTimeout),
|
|
StateError('unexpected'),
|
|
]) {
|
|
expect(TerminalDiscountProtocol.isPricingRejected(error), isFalse);
|
|
}
|
|
expect(TerminalOrderRecovery.shouldQuery(response(500, null)), isTrue);
|
|
});
|
|
}
|