/* * This file is a part of RSPlayer * Licensed under the GPL-3.0 License * Copyright (C) 2026 Salmonik @ salmonik@tuta.io * https://codeberg.org/salmonik/RSPlayer */ use std::path::PathBuf; use rsp::daemon::ScrobbleState; use rsp::queue::Track; #[test] fn test_scrobble_state_new() { let s = ScrobbleState::new(); assert!(s.track.is_none()); assert!(s.start_time.is_none()); assert!(s.timestamp.is_none()); } #[test] fn test_scrobble_state_clear() { let mut s = ScrobbleState::new(); let t = Track { path: PathBuf::from("/test/song.mp3"), title: Some("Test".into()), artist: Some("Artist".into()), album: None, track_number: None, duration_secs: Some(200.0), is_stream: false, }; s.start(t); assert!(s.track.is_some()); s.clear(); assert!(s.track.is_none()); assert!(s.start_time.is_none()); assert!(s.timestamp.is_none()); } #[test] fn test_should_scrobble_without_track_returns_false() { assert!(!ScrobbleState::new().should_scrobble()); } #[test] fn test_should_scrobble_threshold_below_30_seconds() { assert!(!ScrobbleState::should_scrobble_with_params(29, Some(200.0))); } #[test] fn test_should_scrobble_threshold_half_duration() { assert!(ScrobbleState::should_scrobble_with_params(100, Some(200.0))); } #[test] fn test_should_scrobble_threshold_below_half_duration() { assert!(!ScrobbleState::should_scrobble_with_params(80, Some(200.0))); } #[test] fn test_should_scrobble_threshold_capped_at_4min() { assert!(ScrobbleState::should_scrobble_with_params(240, Some(600.0))); assert!(!ScrobbleState::should_scrobble_with_params( 239, Some(600.0) )); } #[test] fn test_should_scrobble_no_duration_requires_4min() { assert!(ScrobbleState::should_scrobble_with_params(240, None)); assert!(!ScrobbleState::should_scrobble_with_params(239, None)); } #[test] fn test_should_scrobble_short_song() { assert!(ScrobbleState::should_scrobble_with_params(30, Some(60.0))); assert!(!ScrobbleState::should_scrobble_with_params(15, Some(60.0))); }