Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "tui"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
edition.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@@ -13,23 +13,22 @@ linux-zbus = [
|
||||
windows = ["dep:windows-native-keyring-store"]
|
||||
|
||||
[dependencies]
|
||||
ratatui = "0.30.0"
|
||||
keyring-core = "1.0.0"
|
||||
directories = "6"
|
||||
csv = "1"
|
||||
ratatui = { workspace = true }
|
||||
keyring-core = { workspace = true }
|
||||
directories = { workspace = true }
|
||||
csv = { workspace = true }
|
||||
|
||||
apple-native-keyring-store = { version = "1.0.0", optional = true, features = [
|
||||
"keychain",
|
||||
] }
|
||||
zbus-secret-service-keyring-store = { version = "1.0.0", optional = true }
|
||||
windows-native-keyring-store = { version = "1.0.0", optional = true }
|
||||
apple-native-keyring-store = { workspace = true, optional = true }
|
||||
zbus-secret-service-keyring-store = { workspace = true, optional = true }
|
||||
windows-native-keyring-store = { workspace = true, optional = true }
|
||||
|
||||
api-types = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
rustls = { workspace = true, features = ["ring", "std", "tls12", "logging"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "sync", "macros", "time"] }
|
||||
anyhow = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
uuid = { workspace = true, features = ["serde"] }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
|
||||
@@ -988,7 +988,3 @@ pub fn update(app: &mut App, action: Action) -> Vec<Command> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/app.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -46,6 +46,7 @@ pub struct ApiClient {
|
||||
|
||||
impl ApiClient {
|
||||
pub fn new(url: &str) -> Self {
|
||||
let _ = rustls::crypto::ring::default_provider().install_default();
|
||||
Self {
|
||||
base_url: std::sync::RwLock::new(url.to_string()),
|
||||
http: reqwest::Client::new(),
|
||||
|
||||
@@ -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