Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
183 lines
5.4 KiB
Rust
183 lines
5.4 KiB
Rust
// Integration tests for accounts module
|
|
|
|
use tele_tui::accounts::{
|
|
account_db_path, validate_account_name, AccountProfile, AccountsConfig,
|
|
};
|
|
|
|
#[test]
|
|
fn test_default_single_config() {
|
|
let config = AccountsConfig::default_single();
|
|
assert_eq!(config.default_account, "default");
|
|
assert_eq!(config.accounts.len(), 1);
|
|
assert_eq!(config.accounts[0].name, "default");
|
|
assert_eq!(config.accounts[0].display_name, "Default");
|
|
}
|
|
|
|
#[test]
|
|
fn test_find_account_exists() {
|
|
let config = AccountsConfig::default_single();
|
|
let account = config.find_account("default");
|
|
assert!(account.is_some());
|
|
assert_eq!(account.unwrap().name, "default");
|
|
}
|
|
|
|
#[test]
|
|
fn test_find_account_not_found() {
|
|
let config = AccountsConfig::default_single();
|
|
assert!(config.find_account("work").is_none());
|
|
assert!(config.find_account("").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn test_db_path_structure() {
|
|
let path = account_db_path("default");
|
|
let path_str = path.to_string_lossy();
|
|
|
|
assert!(path_str.contains("tele-tui"));
|
|
assert!(path_str.contains("accounts"));
|
|
assert!(path_str.contains("default"));
|
|
assert!(path_str.ends_with("tdlib_data"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_db_path_per_account() {
|
|
let path_default = account_db_path("default");
|
|
let path_work = account_db_path("work");
|
|
|
|
assert_ne!(path_default, path_work);
|
|
assert!(path_default.to_string_lossy().contains("default"));
|
|
assert!(path_work.to_string_lossy().contains("work"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_account_profile_db_path() {
|
|
let profile = AccountProfile {
|
|
name: "test-account".to_string(),
|
|
display_name: "Test".to_string(),
|
|
};
|
|
let path = profile.db_path();
|
|
assert!(path.to_string_lossy().contains("test-account"));
|
|
assert!(path.to_string_lossy().ends_with("tdlib_data"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_valid() {
|
|
assert!(validate_account_name("default").is_ok());
|
|
assert!(validate_account_name("work").is_ok());
|
|
assert!(validate_account_name("my-account").is_ok());
|
|
assert!(validate_account_name("account123").is_ok());
|
|
assert!(validate_account_name("test_account").is_ok());
|
|
assert!(validate_account_name("a").is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_empty() {
|
|
let err = validate_account_name("").unwrap_err();
|
|
assert!(err.contains("empty"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_too_long() {
|
|
let long_name = "a".repeat(33);
|
|
let err = validate_account_name(&long_name).unwrap_err();
|
|
assert!(err.contains("32"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_uppercase() {
|
|
assert!(validate_account_name("MyAccount").is_err());
|
|
assert!(validate_account_name("WORK").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_spaces() {
|
|
assert!(validate_account_name("my account").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_starts_with_dash() {
|
|
assert!(validate_account_name("-bad").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_starts_with_underscore() {
|
|
assert!(validate_account_name("_bad").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_validate_account_name_special_chars() {
|
|
assert!(validate_account_name("foo@bar").is_err());
|
|
assert!(validate_account_name("foo.bar").is_err());
|
|
assert!(validate_account_name("foo/bar").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_resolve_account_default() {
|
|
let config = AccountsConfig::default_single();
|
|
let result = tele_tui::accounts::resolve_account(&config, None);
|
|
assert!(result.is_ok());
|
|
let (name, path) = result.unwrap();
|
|
assert_eq!(name, "default");
|
|
assert!(path.to_string_lossy().contains("default"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_resolve_account_explicit() {
|
|
let config = AccountsConfig::default_single();
|
|
let result = tele_tui::accounts::resolve_account(&config, Some("default"));
|
|
assert!(result.is_ok());
|
|
let (name, _) = result.unwrap();
|
|
assert_eq!(name, "default");
|
|
}
|
|
|
|
#[test]
|
|
fn test_resolve_account_not_found() {
|
|
let config = AccountsConfig::default_single();
|
|
let result = tele_tui::accounts::resolve_account(&config, Some("work"));
|
|
assert!(result.is_err());
|
|
let err = result.unwrap_err();
|
|
assert!(err.contains("work"));
|
|
assert!(err.contains("not found"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_resolve_account_invalid_name() {
|
|
let config = AccountsConfig::default_single();
|
|
let result = tele_tui::accounts::resolve_account(&config, Some("BAD NAME"));
|
|
assert!(result.is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_accounts_config_serde_roundtrip() {
|
|
let config = AccountsConfig::default_single();
|
|
let toml_str = toml::to_string_pretty(&config).unwrap();
|
|
let parsed: AccountsConfig = toml::from_str(&toml_str).unwrap();
|
|
|
|
assert_eq!(parsed.default_account, config.default_account);
|
|
assert_eq!(parsed.accounts.len(), config.accounts.len());
|
|
assert_eq!(parsed.accounts[0].name, config.accounts[0].name);
|
|
}
|
|
|
|
#[test]
|
|
fn test_accounts_config_multi_account_serde() {
|
|
let config = AccountsConfig {
|
|
default_account: "default".to_string(),
|
|
accounts: vec![
|
|
AccountProfile {
|
|
name: "default".to_string(),
|
|
display_name: "Default".to_string(),
|
|
},
|
|
AccountProfile {
|
|
name: "work".to_string(),
|
|
display_name: "Work".to_string(),
|
|
},
|
|
],
|
|
};
|
|
|
|
let toml_str = toml::to_string_pretty(&config).unwrap();
|
|
let parsed: AccountsConfig = toml::from_str(&toml_str).unwrap();
|
|
|
|
assert_eq!(parsed.accounts.len(), 2);
|
|
assert!(parsed.find_account("work").is_some());
|
|
}
|