RTIX / src /mock_tests.rs
github-actions
deploy: clean backend production release
18d6188
#[cfg(test)]
mod tests {
use rtix::application::services::india_tax::IndiaTaxService;
use rtix::application::services::pricing::PricingEngine;
use rtix::domain::models::{Coupon, OrderRecord};
use uuid::Uuid;
#[test]
fn test_mock_india_tax_logic() {
// Test Intra-state (KA to KA)
let breakdown = IndiaTaxService::calculate_gst(1000.0, 29, "560001", 0.18);
assert_eq!(breakdown.cgst, 90.0);
assert_eq!(breakdown.sgst, 90.0);
assert_eq!(breakdown.igst, 0.0);
// Test Inter-state (KA to DL)
let breakdown = IndiaTaxService::calculate_gst(1000.0, 29, "110001", 0.18);
assert_eq!(breakdown.cgst, 0.0);
assert_eq!(breakdown.sgst, 0.0);
assert_eq!(breakdown.igst, 180.0);
}
#[test]
fn test_mock_pricing_engine() {
let fee = PricingEngine::calculate_platform_fee(1000.0, 95.0); // High trust
assert_eq!(fee, 0.0); // Platform fee removed during checkout
let fee_low_trust = PricingEngine::calculate_platform_fee(1000.0, 50.0);
assert_eq!(fee_low_trust, 0.0); // Platform fee removed during checkout
}
#[test]
fn test_mock_coupon_validation() {
let coupon = Coupon {
id: Uuid::new_v4(),
merchant_id: "m1".into(),
code: "TEST50".into(),
discount_type: "PERCENTAGE".into(),
discount_value: 50.0,
min_order_amount: 500.0,
max_discount_amount: Some(200.0),
is_active: true,
usage_count: 0,
expiry_date: None,
created_at: None,
};
// Valid order
assert!(coupon.is_valid(600.0));
// Below min amount
assert!(!coupon.is_valid(400.0));
// Discount calculation
let discount = coupon.calculate_discount(1000.0);
assert_eq!(discount, 200.0); // Capped at 200
}
#[test]
fn test_mock_security_redaction() {
let order = OrderRecord {
transaction_id: "tx1".into(),
merchant_id: "m1".into(),
link_id: "l1".into(),
buyer_phone: "9876543210".into(),
buyer_phone_hash: None,
buyer_name: "John Doe".into(),
buyer_email: "john@example.com".into(),
shipping_pincode: Some("560001".into()),
delivery_address: Some("123 Street".into()),
price_inr: 1000.0,
status: "PAID".into(),
vpa: None,
outbound_weight: 500.0,
return_weight: 0.0,
proof_data: None,
proof_received_at: None,
settled_at: None,
paid_at: None,
shipped_at: None,
delivered_at: None,
shipping_method: None,
estimated_delivery_at: None,
payu_id: "p1".into(),
is_payment: true,
platform_fee_paid: true,
platform_fee: 25.0,
delivery_fee: 50.0,
distance_km: 10.0,
risk_score: 10.0,
risk_flags: None,
cgst: 90.0,
sgst: 90.0,
igst: 0.0,
utr_number: None,
platform_fee_utr: None,
delivery_gps_lat: None,
delivery_gps_lng: None,
is_geofence_verified: None,
pincode_volatility_at_checkout: 0.0,
discount_amount: 0.0,
coupon_code: None,
checkout_gps_lat: None,
checkout_gps_lng: None,
device_fingerprint: None,
created_at: None,
brand_name: None,
};
let debug_output = format!("{:?}", order);
assert!(debug_output.contains("[REDACTED]"));
assert!(!debug_output.contains("9876543210"));
assert!(!debug_output.contains("john@example.com"));
}
#[test]
fn test_mock_risk_blocking_threshold() {
let order = OrderRecord {
transaction_id: "tx1".into(),
merchant_id: "m1".into(),
link_id: "l1".into(),
buyer_phone: "9876543210".into(),
buyer_phone_hash: None,
buyer_name: "John Doe".into(),
buyer_email: "scammer@tempmail.com".into(),
shipping_pincode: Some("560001".into()),
delivery_address: Some("123 Street".into()),
price_inr: 15000.0,
status: "PENDING".into(),
vpa: None,
outbound_weight: 500.0,
return_weight: 0.0,
proof_data: None,
proof_received_at: None,
settled_at: None,
paid_at: None,
shipped_at: None,
delivered_at: None,
shipping_method: None,
estimated_delivery_at: None,
payu_id: "".into(),
is_payment: false,
platform_fee_paid: false,
platform_fee: 0.0,
delivery_fee: 100.0,
distance_km: 1500.0,
risk_score: 0.0,
risk_flags: None,
cgst: 0.0,
sgst: 0.0,
igst: 0.0,
utr_number: None,
platform_fee_utr: None,
delivery_gps_lat: None,
delivery_gps_lng: None,
is_geofence_verified: None,
pincode_volatility_at_checkout: 0.0,
discount_amount: 0.0,
coupon_code: None,
checkout_gps_lat: None,
checkout_gps_lng: None,
device_fingerprint: None,
created_at: None,
brand_name: None,
};
let (score, flags) =
rtix::application::services::risk::RiskEngine::calculate_risk_score(&order, 0, 0.0);
assert!(
score >= 80.0,
"Risk score {:.1} should exceed blocking threshold of 80.0",
score
);
assert!(flags.get("SUSPICIOUS_EMAIL_DOMAIN").is_some());
assert!(flags.get("NEW_BUYER").is_some());
}
}