Files
asd-backend/tests/integration_test.rs

61 lines
2.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#[test]
fn test_basic_compilation() {
assert_eq!(2 + 2, 4);
}
/// 验证套餐天数和 SQL CASE 间隔一致
/// 如果新增套餐类型,此处会失败,提醒同步更新 db.rs 中的 CASE 语句
#[test]
fn test_payment_package_intervals_match() {
// 必须与 db.rs 中 confirm_payment_order 的 CASE WHEN 完全一致
// 与 handlers/payment.rs 中 Pkg.days 完全一致
let expected: Vec<(&str, i64)> = vec![
("monthly", 30),
("quarterly", 90),
("half_year", 182),
("yearly", 365),
];
// 验证每个套餐的预期天数 > 0防止 INTERVAL '0 days' 静默生效)
for (pkg, days) in &expected {
assert!(*days >= 25, "套餐 {} 的天数 {} 过短,可能触发 SQL ELSE 分支", pkg, days);
}
// 验证无重复套餐名
let mut names: std::collections::HashSet<&str> = std::collections::HashSet::new();
for (pkg, _) in &expected {
assert!(
names.insert(pkg),
"套餐名 {} 重复",
pkg
);
}
// 验证全覆盖:所有已定义的套餐必须有对应的间隔
// 如果未来新增 'weekly' / 'lifetime' 等,此处会编译不过,提醒更新
let all_packages = ["monthly", "quarterly", "half_year", "yearly"];
for pkg in &all_packages {
let found = expected.iter().any(|(name, _)| name == pkg);
assert!(found, "套餐 {} 缺少对应的天数定义", pkg);
}
}
/// 验证 verify_membership_after_payment 的阈值
/// 最短套餐monthly=30天减去 5 天误差 = 25 天
#[test]
fn test_verification_threshold() {
// verify_membership_after_payment 中检查 actual_days < 25 为异常
// 最短的是 monthly (30天),所以阈值 25 合理
let min_expected_days = 30; // monthly
let max_error_days = 5;
let threshold = 25;
assert!(
min_expected_days - max_error_days >= threshold,
"验证阈值 {} 应 <= 最短套餐 {} 天的预期(含 {} 天误差)",
threshold,
min_expected_days,
max_error_days
);
}