//! Unit tests for TVDB API client use movie_mapper::model::episode::Episode; use movie_mapper::model::show::{Season, Show, ShowDetails}; use movie_mapper::service::tvdb_api::TVDBClient; #[test] fn test_show_serialization() { let show = Show { id: 73256, series_name: "Breaking Bad".to_string(), status: "Ended".to_string(), first_aired: Some("2008-01-20".to_string()), overview: "A high school chemistry teacher...".to_string(), image: "/api/v3/images/movies/73256/posters/75284.jpg".to_string(), slug: "breaking-bad".to_string(), }; let json = serde_json::to_string(&show).expect("Failed to serialize show"); assert!(json.contains("Breaking Bad")); assert!(json.contains("73256")); } #[test] fn test_episode_serialization() { let episode = Episode { id: 5678, name: "Pilot".to_string(), number: 1, season_number: 1, aired: Some("2008-01-20".to_string()), runtime: Some(58), }; let json = serde_json::to_string(&episode).expect("Failed to serialize episode"); assert!(json.contains("Pilot")); assert!(json.contains("5678")); } #[test] fn test_season_serialization() { let season = Season { id: 1234, number: 1, type_name: "Main Season".to_string(), episode_count: 7, }; let json = serde_json::to_string(&season).expect("Failed to serialize season"); assert!(json.contains("1")); } #[test] fn test_show_details_serialization() { let show_details = ShowDetails { id: 73256, name: "Breaking Bad".to_string(), status: "Ended".to_string(), first_aired: Some("2008-01-20".to_string()), overview: "A high school chemistry teacher...".to_string(), image: "/api/v3/images/movies/73256/posters/75284.jpg".to_string(), slug: "breaking-bad".to_string(), seasons: vec![ Season { id: 1234, number: 1, type_name: "Main Season".to_string(), episode_count: 7, }, Season { id: 1235, number: 2, type_name: "Main Season".to_string(), episode_count: 7, }, ], }; let json = serde_json::to_string(&show_details).expect("Failed to serialize show details"); assert!(json.contains("Breaking Bad")); assert!(json.contains("seasons")); } #[test] fn test_tvdb_client_creation() { let client = TVDBClient::new("test-api-key").expect("Failed to create TVDB client"); assert_eq!(client.api_key(), "test-api-key"); assert!(client.get_token().is_none()); } #[test] fn test_episode_identifier() { let episode = Episode { id: 5678, name: "Pilot".to_string(), number: 1, season_number: 1, aired: Some("2008-01-20".to_string()), runtime: Some(58), }; assert_eq!(episode.identifier(), "E01"); } #[test] fn test_episode_identifier_single_digit() { let episode = Episode { id: 5678, name: "Test".to_string(), number: 5, season_number: 1, aired: None, runtime: None, }; assert_eq!(episode.identifier(), "E05"); } #[test] fn test_episode_identifier_double_digit() { let episode = Episode { id: 5678, name: "Test".to_string(), number: 12, season_number: 1, aired: None, runtime: None, }; assert_eq!(episode.identifier(), "E12"); }