use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ReplicationInfo {
pub enabled: bool,
pub status: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_sync: Option<String>,
pub pending_changes: usize,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct StorageStatusResponse {
pub replication: ReplicationInfo,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_replication_info_disabled_serialize() {
let info = ReplicationInfo {
enabled: false,
status: "disabled".to_string(),
last_sync: None,
pending_changes: 0,
};
let json = serde_json::to_string(&info).unwrap();
assert!(json.contains("\"enabled\":false"));
assert!(json.contains("\"disabled\""));
assert!(json.contains("\"pending_changes\":0"));
assert!(!json.contains("last_sync"));
}
#[test]
fn test_replication_info_active_serialize() {
let info = ReplicationInfo {
enabled: true,
status: "active".to_string(),
last_sync: Some("2025-01-15T10:30:00+00:00".to_string()),
pending_changes: 3,
};
let json = serde_json::to_string(&info).unwrap();
assert!(json.contains("\"enabled\":true"));
assert!(json.contains("\"active\""));
assert!(json.contains("2025-01-15T10:30:00+00:00"));
assert!(json.contains("\"pending_changes\":3"));
}
#[test]
fn test_storage_status_response_serialize() {
let response = StorageStatusResponse {
replication: ReplicationInfo {
enabled: false,
status: "disabled".to_string(),
last_sync: None,
pending_changes: 0,
},
};
let json = serde_json::to_string(&response).unwrap();
assert!(json.contains("\"replication\""));
assert!(json.contains("\"enabled\":false"));
}
}