games_app/prediqo_mobile/test/withdrawal_status_display_test.dart

63 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:prediqo_mobile/data/models/transaction_model.dart';
import 'package:prediqo_mobile/features/wallet/utils/transaction_display.dart';
import 'package:prediqo_mobile/l10n/app_strings.dart';
TransactionModel _withdrawal(String status) => TransactionModel.fromJson({
'id': 'w-$status',
'wallet_type_id': 1,
'type': 'withdrawal',
'amount': '5000000',
'fee': '1000000',
'status': status,
'created_at': '2026-11-12T10:00:00.000Z',
});
void main() {
final en = AppStrings(const Locale('en'));
final fr = AppStrings(const Locale('fr'));
test('withdrawal state machine statuses have labels in EN and FR', () {
expect(transactionStatusLabel('pending', en), 'Pending');
expect(transactionStatusLabel('processing', en), 'Processing');
expect(transactionStatusLabel('completed', en), 'Completed');
expect(transactionStatusLabel('failed', en), 'Failed');
expect(transactionStatusLabel('rejected', en), 'Rejected');
expect(transactionStatusLabel('cancelled', en), 'Cancelled');
expect(transactionStatusLabel('processing', fr), 'En cours');
expect(transactionStatusLabel('rejected', fr), 'Refusé');
expect(transactionStatusLabel('completed', fr), 'Terminé');
});
test('legacy statuses map to the closest current label', () {
expect(transactionStatusLabel('pending_approval', en), 'Pending');
expect(transactionStatusLabel('broadcasting', en), 'Processing');
expect(transactionStatusLabel('confirming', en), 'Processing');
expect(transactionStatusLabel('failed_refunded', en), 'Failed');
});
test('tones', () {
expect(transactionStatusTone('pending'), TxStatusTone.warning);
expect(transactionStatusTone('processing'), TxStatusTone.info);
expect(transactionStatusTone('completed'), TxStatusTone.success);
expect(transactionStatusTone('failed'), TxStatusTone.danger);
expect(transactionStatusTone('rejected'), TxStatusTone.danger);
});
test('only a pending withdrawal can be cancelled by the user', () {
expect(canCancelWithdrawal(_withdrawal('pending')), isTrue);
for (final s in ['processing', 'completed', 'failed', 'rejected', 'cancelled']) {
expect(canCancelWithdrawal(_withdrawal(s)), isFalse, reason: s);
}
});
test('refunded withdrawals are flagged', () {
expect(isRefundedWithdrawal(_withdrawal('rejected')), isTrue);
expect(isRefundedWithdrawal(_withdrawal('cancelled')), isTrue);
expect(isRefundedWithdrawal(_withdrawal('failed_refunded')), isTrue);
expect(isRefundedWithdrawal(_withdrawal('failed')), isFalse);
expect(isRefundedWithdrawal(_withdrawal('completed')), isFalse);
});
}