refactor: modularize codebase and add 404 unit tests (#13)
All checks were successful
CI / Format (push) Successful in 4s
CI / Clippy (push) Successful in 4m19s
CI / Security Audit (push) Successful in 1m44s
CI / Detect Changes (push) Successful in 5s
CI / Tests (push) Successful in 5m15s
CI / Deploy Agent (push) Successful in 2s
CI / Deploy Dashboard (push) Successful in 2s
CI / Deploy Docs (push) Has been skipped
CI / Deploy MCP (push) Successful in 2s

This commit was merged in pull request #13.
This commit is contained in:
2026-03-13 08:03:45 +00:00
parent acc5b86aa4
commit 3bb690e5bb
89 changed files with 11884 additions and 6046 deletions

View File

@@ -12,6 +12,89 @@ fn cap_limit(limit: Option<i64>) -> i64 {
limit.unwrap_or(DEFAULT_LIMIT).clamp(1, MAX_LIMIT)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn cap_limit_default() {
assert_eq!(cap_limit(None), DEFAULT_LIMIT);
}
#[test]
fn cap_limit_normal_value() {
assert_eq!(cap_limit(Some(100)), 100);
}
#[test]
fn cap_limit_exceeds_max() {
assert_eq!(cap_limit(Some(500)), MAX_LIMIT);
assert_eq!(cap_limit(Some(201)), MAX_LIMIT);
}
#[test]
fn cap_limit_zero_clamped_to_one() {
assert_eq!(cap_limit(Some(0)), 1);
}
#[test]
fn cap_limit_negative_clamped_to_one() {
assert_eq!(cap_limit(Some(-10)), 1);
}
#[test]
fn cap_limit_boundary_values() {
assert_eq!(cap_limit(Some(1)), 1);
assert_eq!(cap_limit(Some(MAX_LIMIT)), MAX_LIMIT);
}
#[test]
fn list_findings_params_deserialize() {
let json = serde_json::json!({
"repo_id": "abc",
"severity": "high",
"status": "open",
"scan_type": "sast",
"limit": 25
});
let params: ListFindingsParams = serde_json::from_value(json).unwrap();
assert_eq!(params.repo_id.as_deref(), Some("abc"));
assert_eq!(params.severity.as_deref(), Some("high"));
assert_eq!(params.status.as_deref(), Some("open"));
assert_eq!(params.scan_type.as_deref(), Some("sast"));
assert_eq!(params.limit, Some(25));
}
#[test]
fn list_findings_params_all_optional() {
let json = serde_json::json!({});
let params: ListFindingsParams = serde_json::from_value(json).unwrap();
assert!(params.repo_id.is_none());
assert!(params.severity.is_none());
assert!(params.status.is_none());
assert!(params.scan_type.is_none());
assert!(params.limit.is_none());
}
#[test]
fn get_finding_params_deserialize() {
let json = serde_json::json!({ "id": "507f1f77bcf86cd799439011" });
let params: GetFindingParams = serde_json::from_value(json).unwrap();
assert_eq!(params.id, "507f1f77bcf86cd799439011");
}
#[test]
fn findings_summary_params_deserialize() {
let json = serde_json::json!({ "repo_id": "r1" });
let params: FindingsSummaryParams = serde_json::from_value(json).unwrap();
assert_eq!(params.repo_id.as_deref(), Some("r1"));
let json2 = serde_json::json!({});
let params2: FindingsSummaryParams = serde_json::from_value(json2).unwrap();
assert!(params2.repo_id.is_none());
}
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ListFindingsParams {
/// Filter by repository ID