Skip to content

Commit 42fcbcb

Browse files
committed
Fix CI test failures and improve code quality
- Fix account format in tests (4 segments not 5) - Set test transactions to business hours to reduce time-based risk - Fix velocity detection test with unique transaction IDs - Add debug output for validation failures - All 30 tests now passing - No clippy warnings
1 parent a86e9e2 commit 42fcbcb

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

src/fraud_patterns.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,32 @@ mod tests {
393393
..Default::default()
394394
});
395395

396-
for _ in 0..3 {
397-
let txn = create_test_transaction(100.0);
398-
let score = detector.calculate_fraud_score(&txn);
399-
if detector.get_transaction_count("ACC-123") >= 2 {
400-
assert!(score
401-
.flags
402-
.iter()
403-
.any(|f| f.flag_type == FraudFlagType::VelocityExceeded));
404-
}
405-
}
396+
// First transaction - should pass
397+
let mut txn1 = create_test_transaction(100.0);
398+
txn1.transaction_id = "TXN-VEL-001".to_string();
399+
let score1 = detector.calculate_fraud_score(&txn1);
400+
assert!(score1
401+
.flags
402+
.iter()
403+
.all(|f| f.flag_type != FraudFlagType::VelocityExceeded));
404+
405+
// Second transaction - should pass (at limit but not exceeded)
406+
let mut txn2 = create_test_transaction(100.0);
407+
txn2.transaction_id = "TXN-VEL-002".to_string();
408+
let score2 = detector.calculate_fraud_score(&txn2);
409+
assert!(score2
410+
.flags
411+
.iter()
412+
.all(|f| f.flag_type != FraudFlagType::VelocityExceeded));
413+
414+
// Third transaction - should trigger velocity flag (exceeds limit of 2)
415+
let mut txn3 = create_test_transaction(100.0);
416+
txn3.transaction_id = "TXN-VEL-003".to_string();
417+
let score3 = detector.calculate_fraud_score(&txn3);
418+
assert!(score3
419+
.flags
420+
.iter()
421+
.any(|f| f.flag_type == FraudFlagType::VelocityExceeded));
406422
}
407423

408424
#[test]

src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,22 @@ mod tests {
583583
use super::*;
584584

585585
fn create_valid_transaction() -> Transaction {
586+
// Create timestamp at 12 PM UTC (business hours) to minimize time-based risk
587+
let now = Utc::now();
588+
let timestamp = now
589+
.date_naive()
590+
.and_hms_opt(12, 0, 0)
591+
.unwrap()
592+
.and_utc();
593+
586594
Transaction {
587595
transaction_id: "TXN-001".to_string(),
588596
transaction_type: TransactionType::Transfer,
589597
amount: 1000.0,
590598
currency: "USD".to_string(),
591-
from_account: Some("ACCT-1234-5678-9012-3456".to_string()),
592-
to_account: Some("ACCT-6789-0123-4567-8901".to_string()),
593-
timestamp: Utc::now(),
599+
from_account: Some("ACCT-1234-5678-9012".to_string()),
600+
to_account: Some("ACCT-6789-0123-4567".to_string()),
601+
timestamp,
594602
user_id: "USER-001".to_string(),
595603
metadata: None,
596604
}
@@ -602,7 +610,15 @@ mod tests {
602610
let transaction = create_valid_transaction();
603611
let result = validator.validate(&transaction);
604612

605-
assert!(result.is_valid);
613+
// Debug output
614+
if !result.is_valid {
615+
eprintln!("Validation failed!");
616+
eprintln!("Errors: {:?}", result.errors);
617+
eprintln!("Fraud score: {}", result.fraud_score);
618+
eprintln!("Risk breakdown: {:?}", result.risk_breakdown);
619+
}
620+
621+
assert!(result.is_valid, "Transaction should be valid. Errors: {:?}, Fraud score: {}", result.errors, result.fraud_score);
606622
assert!(result.errors.is_empty());
607623
}
608624

0 commit comments

Comments
 (0)