use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct PaginatedResponse<T> {
pub results: Vec<T>,
pub next: Option<String>,
pub previous: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct ResultsResponse<T> {
pub results: Vec<T>,
}
#[derive(Debug, Deserialize)]
pub struct CursorPaginatedResponse<T> {
pub results: Vec<T>,
pub next: Option<String>,
}
#[cfg(test)]
mod tests {
use super::CursorPaginatedResponse;
#[test]
fn cursor_paginated_response_deserializes_with_next() {
let json = r#"{"results": [1, 2, 3], "next": "cursor_abc123"}"#;
let resp: CursorPaginatedResponse<i32> = serde_json::from_str(json).unwrap();
assert_eq!(resp.results, vec![1, 2, 3]);
assert_eq!(resp.next.as_deref(), Some("cursor_abc123"));
}
#[test]
fn cursor_paginated_response_deserializes_without_next() {
let json = r#"{"results": [4, 5]}"#;
let resp: CursorPaginatedResponse<i32> = serde_json::from_str(json).unwrap();
assert_eq!(resp.results, vec![4, 5]);
assert!(resp.next.is_none());
}
#[test]
fn cursor_paginated_response_deserializes_null_next() {
let json = r#"{"results": [], "next": null}"#;
let resp: CursorPaginatedResponse<i32> = serde_json::from_str(json).unwrap();
assert!(resp.results.is_empty());
assert!(resp.next.is_none());
}
}