From 5f2d1897b245fbee12d17b5910eaf5233ca6802b Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 5 May 2026 23:29:39 +0200 Subject: Add unit tests in /tests directory for config, database, playback, and scrobbler modules --- tests/scrobbler.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/scrobbler.rs (limited to 'tests/scrobbler.rs') diff --git a/tests/scrobbler.rs b/tests/scrobbler.rs new file mode 100644 index 0000000..f326250 --- /dev/null +++ b/tests/scrobbler.rs @@ -0,0 +1,77 @@ +use rsp::scrobbler::Scrobbler; + +#[test] +fn test_scrobbler_new_with_all_params() { + let scrobbler = Scrobbler::new( + Some("api_key".to_string()), + Some("secret".to_string()), + Some("session".to_string()), + Some("token".to_string()), + ); + assert!(scrobbler.lastfm_api_key.is_some()); + assert!(scrobbler.lastfm_api_secret.is_some()); + assert!(scrobbler.lastfm_session_key.is_some()); + assert!(scrobbler.listenbrainz_token.is_some()); +} + +#[test] +fn test_scrobbler_new_with_none() { + let scrobbler = Scrobbler::new(None, None, None, None); + assert!(scrobbler.lastfm_api_key.is_none()); + assert!(scrobbler.lastfm_api_secret.is_none()); + assert!(scrobbler.lastfm_session_key.is_none()); + assert!(scrobbler.listenbrainz_token.is_none()); +} + +#[test] +fn test_scrobbler_now_playing_no_api_key() { + let scrobbler = Scrobbler::new(None, None, None, None); + scrobbler.now_playing("Artist", "Track", Some("Album")); +} + +#[test] +fn test_scrobbler_now_playing_with_api_key() { + let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); + scrobbler.now_playing("Artist", "Track", Some("Album")); +} + +#[test] +fn test_scrobbler_scrobble_no_keys() { + let scrobbler = Scrobbler::new(None, None, None, None); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); +} + +#[test] +fn test_scrobbler_scrobble_with_lastfm() { + let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); +} + +#[test] +fn test_scrobbler_scrobble_with_listenbrainz() { + let scrobbler = Scrobbler::new(None, None, None, Some("token".to_string())); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); +} + +#[test] +fn test_scrobbler_scrobble_with_both() { + let scrobbler = Scrobbler::new( + Some("api_key".to_string()), + None, + None, + Some("token".to_string()), + ); + scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); +} + +#[test] +fn test_scrobbler_now_playing_no_album() { + let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); + scrobbler.now_playing("Artist", "Track", None); +} + +#[test] +fn test_scrobbler_scrobble_no_album() { + let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); + scrobbler.scrobble("Artist", "Track", None, 1234567890); +} -- cgit v1.2.3