use serde::{Deserialize, Serialize}; /// A single news feed card representing an AI-related article. /// /// # Fields /// /// * `title` - Headline of the article /// * `source` - Publishing outlet or author /// * `summary` - Brief summary text /// * `content` - Full content snippet from search results /// * `category` - Display label for the search topic (e.g. "AI", "Finance") /// * `url` - Link to the full article /// * `thumbnail_url` - Optional thumbnail image URL /// * `published_at` - ISO 8601 date string #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct NewsCard { pub title: String, pub source: String, pub summary: String, pub content: String, pub category: String, pub url: String, pub thumbnail_url: Option, pub published_at: String, } #[cfg(test)] mod tests { use super::*; use pretty_assertions::assert_eq; #[test] fn news_card_serde_round_trip() { let card = NewsCard { title: "AI Breakthrough".into(), source: "techcrunch.com".into(), summary: "New model released".into(), content: "Full article content here".into(), category: "AI".into(), url: "https://example.com/article".into(), thumbnail_url: Some("https://example.com/thumb.jpg".into()), published_at: "2025-06-01".into(), }; let json = serde_json::to_string(&card).expect("serialize NewsCard"); let back: NewsCard = serde_json::from_str(&json).expect("deserialize NewsCard"); assert_eq!(card, back); } #[test] fn news_card_thumbnail_none() { let card = NewsCard { title: "No Thumb".into(), source: "bbc.com".into(), summary: "Summary".into(), content: "Content".into(), category: "Tech".into(), url: "https://bbc.com/article".into(), thumbnail_url: None, published_at: "2025-06-01".into(), }; let json = serde_json::to_string(&card).expect("serialize"); let back: NewsCard = serde_json::from_str(&json).expect("deserialize"); assert_eq!(card, back); } #[test] fn news_card_thumbnail_some() { let card = NewsCard { title: "With Thumb".into(), source: "cnn.com".into(), summary: "Summary".into(), content: "Content".into(), category: "News".into(), url: "https://cnn.com/article".into(), thumbnail_url: Some("https://cnn.com/img.jpg".into()), published_at: "2025-06-01".into(), }; let json = serde_json::to_string(&card).expect("serialize"); assert!(json.contains("img.jpg")); let back: NewsCard = serde_json::from_str(&json).expect("deserialize"); assert_eq!(card.thumbnail_url, back.thumbnail_url); } }