use crate::Result;
use crate::UptrakitClient;
use crate::types_impl::pagination::PaginatedResponse;
use crate::types_impl::update_history::{UpdateHistoryQuery, UpdateHistoryResponse};
use uuid::Uuid;
impl UptrakitClient {
pub async fn list_update_history(
&self,
query: &UpdateHistoryQuery,
) -> Result<PaginatedResponse<UpdateHistoryResponse>> {
self.get_with_query(crate::paths::update_history::BASE, query)
.await
}
pub async fn list_all_update_history(
&self,
query: &UpdateHistoryQuery,
) -> Result<Vec<UpdateHistoryResponse>> {
self.fetch_all_pages(crate::paths::update_history::BASE, query)
.await
}
pub async fn get_update_history(&self, id: &Uuid) -> Result<UpdateHistoryResponse> {
self.get(&crate::paths::update_history::by_id(id)).await
}
}
#[cfg(test)]
mod tests {
use crate::types_impl::update_history::{UpdateHistoryQuery, UpdateStatus};
use uuid::Uuid;
#[test]
fn update_history_query_serialization_with_filters() {
let host_id = Uuid::parse_str("11111111-1111-1111-1111-111111111111").expect("valid uuid");
let query = UpdateHistoryQuery::new(
Some(host_id),
None,
Some(UpdateStatus::Completed),
Some(2),
Some(10),
);
let qs = serde_urlencoded::to_string(&query).expect("serialize");
assert!(qs.contains("host_id=11111111-1111-1111-1111-111111111111"));
assert!(qs.contains("status=completed"));
assert!(qs.contains("page=2"));
assert!(qs.contains("per_page=10"));
}
#[test]
fn update_history_query_serialization_skips_none() {
let query = UpdateHistoryQuery::new(None, None, None, None, None);
let qs = serde_urlencoded::to_string(&query).expect("serialize");
assert!(qs.is_empty());
}
}