/* * 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 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_creds() { let scrobbler = Scrobbler::new(None, None, None, None); scrobbler.now_playing("Artist", "Track", Some("Album")); } #[test] fn test_scrobbler_now_playing_partial_lastfm() { // Only api_key set — not enough to trigger Last.fm (needs secret + session_key too) let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); scrobbler.now_playing("Artist", "Track", Some("Album")); } #[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_creds() { let scrobbler = Scrobbler::new(None, None, None, None); scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); } #[test] fn test_scrobbler_scrobble_no_album() { let scrobbler = Scrobbler::new(None, None, None, None); scrobbler.scrobble("Artist", "Track", None, 1234567890); } #[test] fn test_scrobbler_scrobble_partial_lastfm() { // Only api_key set — not enough to trigger Last.fm let scrobbler = Scrobbler::new(Some("api_key".to_string()), None, None, None); scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); } #[test] fn test_scrobbler_skip_empty_credentials() { // Empty strings should be treated as unset — no HTTP requests let scrobbler = Scrobbler::new( Some("".to_string()), Some("".to_string()), Some("".to_string()), Some("".to_string()), ); scrobbler.now_playing("Artist", "Track", Some("Album")); scrobbler.scrobble("Artist", "Track", Some("Album"), 1234567890); }