added tests, use specific CI

This commit is contained in:
2026-02-14 09:08:49 +01:00
parent 57f8a54dac
commit e664bf4620
12 changed files with 1388 additions and 5 deletions
+194
View File
@@ -237,3 +237,197 @@ pub async fn auth_reauthenticate(
Ok(result)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_session_serialization() {
let session = Session {
user_id: "user-123".to_string(),
username: "john_doe".to_string(),
server_id: "server-456".to_string(),
server_url: "https://jellyfin.example.com".to_string(),
server_name: "My Jellyfin".to_string(),
access_token: "token-789-xyz".to_string(),
verified: true,
needs_reauth: false,
};
// Should serialize successfully
let json = serde_json::to_string(&session);
assert!(json.is_ok());
let serialized = json.unwrap();
assert!(serialized.contains("user-123"));
assert!(serialized.contains("john_doe"));
assert!(serialized.contains("server-456"));
}
#[test]
fn test_session_deserialization() {
let json = r#"{
"userId": "user-123",
"username": "john_doe",
"serverId": "server-456",
"serverUrl": "https://jellyfin.example.com",
"serverName": "My Jellyfin",
"accessToken": "token-789",
"verified": true,
"needsReauth": false
}"#;
let result: Result<Session, _> = serde_json::from_str(json);
assert!(result.is_ok());
let session = result.unwrap();
assert_eq!(session.user_id, "user-123");
assert_eq!(session.username, "john_doe");
assert_eq!(session.server_id, "server-456");
assert!(session.verified);
assert!(!session.needs_reauth);
}
#[test]
fn test_session_roundtrip() {
let original = Session {
user_id: "user-999".to_string(),
username: "alice".to_string(),
server_id: "server-111".to_string(),
server_url: "https://server.local".to_string(),
server_name: "Home Server".to_string(),
access_token: "very-long-token-string".to_string(),
verified: true,
needs_reauth: false,
};
let json = serde_json::to_string(&original).unwrap();
let deserialized: Session = serde_json::from_str(&json).unwrap();
assert_eq!(original.user_id, deserialized.user_id);
assert_eq!(original.username, deserialized.username);
assert_eq!(original.server_id, deserialized.server_id);
assert_eq!(original.server_url, deserialized.server_url);
assert_eq!(original.access_token, deserialized.access_token);
assert_eq!(original.verified, deserialized.verified);
}
#[test]
fn test_session_clone() {
let session = Session {
user_id: "user-clone".to_string(),
username: "test_user".to_string(),
server_id: "server-clone".to_string(),
server_url: "https://clone.example.com".to_string(),
server_name: "Clone Server".to_string(),
access_token: "clone-token".to_string(),
verified: false,
needs_reauth: true,
};
let cloned = session.clone();
assert_eq!(session.user_id, cloned.user_id);
assert_eq!(session.username, cloned.username);
assert_eq!(session.verified, cloned.verified);
assert_eq!(session.needs_reauth, cloned.needs_reauth);
}
#[test]
fn test_session_unverified() {
let session = Session {
user_id: "user-unverified".to_string(),
username: "newuser".to_string(),
server_id: "server-new".to_string(),
server_url: "https://new.example.com".to_string(),
server_name: "New Server".to_string(),
access_token: "new-token".to_string(),
verified: false,
needs_reauth: true,
};
let json = serde_json::to_string(&session).unwrap();
assert!(json.contains("false")); // verified: false
assert!(json.contains("true")); // needs_reauth: true
let deserialized: Session = serde_json::from_str(&json).unwrap();
assert!(!deserialized.verified);
assert!(deserialized.needs_reauth);
}
#[test]
fn test_session_debug() {
let session = Session {
user_id: "user-debug".to_string(),
username: "debug_user".to_string(),
server_id: "server-debug".to_string(),
server_url: "https://debug.example.com".to_string(),
server_name: "Debug Server".to_string(),
access_token: "debug-token".to_string(),
verified: true,
needs_reauth: false,
};
let debug_str = format!("{:?}", session);
assert!(debug_str.contains("user-debug"));
assert!(debug_str.contains("Session"));
}
#[test]
fn test_auth_manager_wrapper_structure() {
// Verify wrapper type exists and has correct structure
assert_eq!(std::mem::size_of::<AuthManagerWrapper>() > 0, true);
}
#[test]
fn test_session_verifier_wrapper_structure() {
// Verify wrapper type exists and has correct structure
assert_eq!(std::mem::size_of::<SessionVerifierWrapper>() > 0, true);
}
#[test]
fn test_session_with_special_characters() {
let session = Session {
user_id: "user-special-éñ".to_string(),
username: "user@example.com".to_string(),
server_id: "server/123".to_string(),
server_url: "https://jellyfin.example.com:8096".to_string(),
server_name: "My Jellyfin (v10.8.0)".to_string(),
access_token: "token+with/special=chars".to_string(),
verified: true,
needs_reauth: false,
};
let json = serde_json::to_string(&session).unwrap();
let deserialized: Session = serde_json::from_str(&json).unwrap();
assert_eq!(session.username, deserialized.username);
assert_eq!(session.server_name, deserialized.server_name);
assert_eq!(session.access_token, deserialized.access_token);
}
#[test]
fn test_session_field_presence() {
let session = Session {
user_id: "u1".to_string(),
username: "user1".to_string(),
server_id: "s1".to_string(),
server_url: "url1".to_string(),
server_name: "name1".to_string(),
access_token: "token1".to_string(),
verified: true,
needs_reauth: false,
};
let json = serde_json::to_string(&session).unwrap();
// Verify camelCase serialization (serde rename_all = "camelCase")
assert!(json.contains("userId"));
assert!(json.contains("username"));
assert!(json.contains("serverId"));
assert!(json.contains("serverUrl"));
assert!(json.contains("serverName"));
assert!(json.contains("accessToken"));
assert!(json.contains("verified"));
assert!(json.contains("needsReauth"));
}
}