diff --git a/crates/tui/src/app.rs b/crates/tui/src/app.rs index 5703f9ec..8ea1b1b3 100644 --- a/crates/tui/src/app.rs +++ b/crates/tui/src/app.rs @@ -988,7 +988,3 @@ pub fn update(app: &mut App, action: Action) -> Vec { } } } - -#[cfg(test)] -#[path = "tests/app.rs"] -mod tests; diff --git a/crates/tui/src/config.rs b/crates/tui/src/config.rs index b387bd10..9512565f 100644 --- a/crates/tui/src/config.rs +++ b/crates/tui/src/config.rs @@ -76,7 +76,3 @@ impl Config { Ok(()) } } - -#[cfg(test)] -#[path = "tests/config.rs"] -mod tests; diff --git a/crates/tui/src/tests/client.rs b/crates/tui/src/tests/client.rs index a7ca1bfc..bdef7460 100644 --- a/crates/tui/src/tests/client.rs +++ b/crates/tui/src/tests/client.rs @@ -1,56 +1,5 @@ use super::*; -#[test] -fn apierror_unauthorized_display() { - let err = ApiError::Unauthorized; - assert!(matches!(err, ApiError::Unauthorized)); - assert_eq!(err.to_string(), "unauthorized"); -} - -#[test] -fn apierror_validation_display() { - let err = ApiError::Validation("rating must be 0-5".into()); - assert!(err.to_string().contains("validation error")); -} - -#[test] -fn log_review_request_skips_none_fields() { - let req = LogReviewRequest { - external_metadata_id: None, - manual_title: Some("The Matrix".into()), - manual_release_year: None, - manual_director: None, - rating: 5, - comment: None, - watched_at: "2024-01-15T20:00:00".into(), - watch_medium: None, - spoilers: false, - }; - let json = serde_json::to_string(&req).unwrap(); - assert!(!json.contains("external_metadata_id")); - assert!(!json.contains("manual_release_year")); - assert!(!json.contains("manual_director")); - assert!(json.contains("\"manual_title\":\"The Matrix\"")); - assert!(json.contains("\"rating\":5")); -} - -#[test] -fn log_review_request_includes_director_when_set() { - let req = LogReviewRequest { - external_metadata_id: None, - manual_title: Some("Dune".into()), - manual_release_year: Some(2021), - manual_director: Some("Denis Villeneuve".into()), - rating: 5, - comment: None, - watched_at: "2024-01-15T20:00:00".into(), - watch_medium: None, - spoilers: false, - }; - let json = serde_json::to_string(&req).unwrap(); - assert!(json.contains("\"manual_director\":\"Denis Villeneuve\"")); -} - #[test] fn api_client_builds_versioned_urls() { let client = ApiClient::new("http://localhost:3000"); diff --git a/crates/tui/tests/api_client_test.rs b/crates/tui/tests/api_client_test.rs new file mode 100644 index 00000000..c66c721f --- /dev/null +++ b/crates/tui/tests/api_client_test.rs @@ -0,0 +1,53 @@ +use api_types::LogReviewRequest; +use tui::client::ApiError; + +#[test] +fn apierror_unauthorized_display() { + let err = ApiError::Unauthorized; + assert!(matches!(err, ApiError::Unauthorized)); + assert_eq!(err.to_string(), "unauthorized"); +} + +#[test] +fn apierror_validation_display() { + let err = ApiError::Validation("rating must be 0-5".into()); + assert!(err.to_string().contains("validation error")); +} + +#[test] +fn log_review_request_skips_none_fields() { + let req = LogReviewRequest { + external_metadata_id: None, + manual_title: Some("The Matrix".into()), + manual_release_year: None, + manual_director: None, + rating: 5, + comment: None, + watched_at: "2024-01-15T20:00:00".into(), + watch_medium: None, + spoilers: false, + }; + let json = serde_json::to_string(&req).unwrap(); + assert!(!json.contains("external_metadata_id")); + assert!(!json.contains("manual_release_year")); + assert!(!json.contains("manual_director")); + assert!(json.contains("\"manual_title\":\"The Matrix\"")); + assert!(json.contains("\"rating\":5")); +} + +#[test] +fn log_review_request_includes_director_when_set() { + let req = LogReviewRequest { + external_metadata_id: None, + manual_title: Some("Dune".into()), + manual_release_year: Some(2021), + manual_director: Some("Denis Villeneuve".into()), + rating: 5, + comment: None, + watched_at: "2024-01-15T20:00:00".into(), + watch_medium: None, + spoilers: false, + }; + let json = serde_json::to_string(&req).unwrap(); + assert!(json.contains("\"manual_director\":\"Denis Villeneuve\"")); +} diff --git a/crates/tui/src/tests/app.rs b/crates/tui/tests/app_update_test.rs similarity index 99% rename from crates/tui/src/tests/app.rs rename to crates/tui/tests/app_update_test.rs index bbd61883..808dda04 100644 --- a/crates/tui/src/tests/app.rs +++ b/crates/tui/tests/app_update_test.rs @@ -1,5 +1,5 @@ -use super::*; -use api_types::{DiaryEntryDto, MovieDto, ReviewDto}; +use api_types::{DiaryEntryDto, LogReviewRequest, MovieDto, ReviewDto}; +use tui::app::*; use uuid::Uuid; fn setup_app() -> App { diff --git a/crates/tui/src/tests/config.rs b/crates/tui/tests/config_test.rs similarity index 73% rename from crates/tui/src/tests/config.rs rename to crates/tui/tests/config_test.rs index 00f81328..af819e55 100644 --- a/crates/tui/src/tests/config.rs +++ b/crates/tui/tests/config_test.rs @@ -1,7 +1,7 @@ -use super::*; +use tui::config::Config; #[test] -fn config_roundtrip() { +fn config_survives_json_round_trip() { let config = Config { api_url: "http://localhost:3000".into(), }; @@ -11,6 +11,6 @@ fn config_roundtrip() { } #[test] -fn load_returns_none_when_no_file() { +fn load_without_config_file_does_not_panic() { let _ = Config::load(); }