aboutsummaryrefslogtreecommitdiffstats
path: root/tests/daemon.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/daemon.rs')
-rw-r--r--tests/daemon.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/daemon.rs b/tests/daemon.rs
new file mode 100644
index 0000000..e5cb270
--- /dev/null
+++ b/tests/daemon.rs
@@ -0,0 +1,79 @@
1/*
2 * This file is a part of RSPlayer
3 * Licensed under the GPL-3.0 License
4 * Copyright (C) 2026 Salmonik @ salmonik@tuta.io
5 * https://codeberg.org/salmonik/RSPlayer
6*/
7
8use std::path::PathBuf;
9
10use rsp::daemon::ScrobbleState;
11use rsp::queue::Track;
12
13#[test]
14fn test_scrobble_state_new() {
15 let s = ScrobbleState::new();
16 assert!(s.track.is_none());
17 assert!(s.start_time.is_none());
18 assert!(s.timestamp.is_none());
19}
20
21#[test]
22fn test_scrobble_state_clear() {
23 let mut s = ScrobbleState::new();
24 let t = Track {
25 path: PathBuf::from("/test/song.mp3"),
26 title: Some("Test".into()),
27 artist: Some("Artist".into()),
28 album: None,
29 duration_secs: Some(200.0),
30 is_stream: false,
31 };
32 s.start(t);
33 assert!(s.track.is_some());
34 s.clear();
35 assert!(s.track.is_none());
36 assert!(s.start_time.is_none());
37 assert!(s.timestamp.is_none());
38}
39
40#[test]
41fn test_should_scrobble_without_track_returns_false() {
42 assert!(!ScrobbleState::new().should_scrobble());
43}
44
45#[test]
46fn test_should_scrobble_threshold_below_30_seconds() {
47 assert!(!ScrobbleState::should_scrobble_with_params(29, Some(200.0)));
48}
49
50#[test]
51fn test_should_scrobble_threshold_half_duration() {
52 assert!(ScrobbleState::should_scrobble_with_params(100, Some(200.0)));
53}
54
55#[test]
56fn test_should_scrobble_threshold_below_half_duration() {
57 assert!(!ScrobbleState::should_scrobble_with_params(80, Some(200.0)));
58}
59
60#[test]
61fn test_should_scrobble_threshold_capped_at_4min() {
62 assert!(ScrobbleState::should_scrobble_with_params(240, Some(600.0)));
63 assert!(!ScrobbleState::should_scrobble_with_params(
64 239,
65 Some(600.0)
66 ));
67}
68
69#[test]
70fn test_should_scrobble_no_duration_requires_4min() {
71 assert!(ScrobbleState::should_scrobble_with_params(240, None));
72 assert!(!ScrobbleState::should_scrobble_with_params(239, None));
73}
74
75#[test]
76fn test_should_scrobble_short_song() {
77 assert!(ScrobbleState::should_scrobble_with_params(30, Some(60.0)));
78 assert!(!ScrobbleState::should_scrobble_with_params(15, Some(60.0)));
79}