This commit is contained in:
@@ -204,3 +204,61 @@ fn mode_str(mode: GameMode) -> &'static str {
|
||||
GameMode::Difficulty(_) => "difficulty",
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use solitaire_core::game_state::DifficultyLevel;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn client_for_requires_analytics_opt_in() {
|
||||
let settings = Settings {
|
||||
analytics_enabled: false,
|
||||
matomo_url: Some("https://analytics.example.com".into()),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
assert!(client_for(&settings).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_for_requires_matomo_url() {
|
||||
let settings = Settings {
|
||||
analytics_enabled: true,
|
||||
matomo_url: None,
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
assert!(client_for(&settings).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_for_creates_client_when_enabled_and_configured() {
|
||||
let settings = Settings {
|
||||
analytics_enabled: true,
|
||||
matomo_url: Some("https://analytics.example.com".into()),
|
||||
matomo_site_id: 2,
|
||||
sync_backend: SyncBackend::SolitaireServer {
|
||||
url: "https://solitaire.example.com".into(),
|
||||
username: "alice".into(),
|
||||
avatar_url: None,
|
||||
},
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
assert!(client_for(&settings).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mode_labels_match_analytics_payload_contract() {
|
||||
assert_eq!(mode_str(GameMode::Classic), "classic");
|
||||
assert_eq!(mode_str(GameMode::Zen), "zen");
|
||||
assert_eq!(mode_str(GameMode::Challenge), "challenge");
|
||||
assert_eq!(mode_str(GameMode::TimeAttack), "time_attack");
|
||||
assert_eq!(
|
||||
mode_str(GameMode::Difficulty(DifficultyLevel::Grandmaster)),
|
||||
"difficulty"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user