test: move tui tests to tests/
Kept inline: tui src/client.rs tests::{api_client_builds_versioned_urls,api_client_update_url} - ApiClient::api/url private.
This commit is contained in:
@@ -988,7 +988,3 @@ pub fn update(app: &mut App, action: Action) -> Vec<Command> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/app.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -76,7 +76,3 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/config.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -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");
|
||||
|
||||
53
crates/tui/tests/api_client_test.rs
Normal file
53
crates/tui/tests/api_client_test.rs
Normal file
@@ -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\""));
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user