msr_api/
lib.rs

1pub mod types;
2
3#[cfg(test)]
4mod tests {
5    use crate::types::{
6        album::{fetch_album_details, fetch_album_list, Album}, lyrics::{from_lyrics_url, Lyrics}, song::{fetch_autoplay_song_id, fetch_song_details, fetch_song_list, Song}
7    };
8    use tokio;
9
10    #[tokio::test]
11    async fn test_fetch_song_list() {
12        let song_list: Vec<crate::types::song::SongSyn> = fetch_song_list().await.unwrap();
13        assert!(song_list.len() > 0);
14    }
15    #[tokio::test]
16    async fn test_fetch_autoplay_song_id() {
17        let auto_play_song: String = fetch_autoplay_song_id().await.unwrap();
18        assert!(auto_play_song.eq("048794"));
19    }
20
21    #[tokio::test]
22    async fn test_fetch_song_details() {
23        let song: Song = fetch_song_details("880318").await.unwrap();
24        assert!(song.cid_ref().eq("880318"));
25        assert!(song.name_ref().eq("Protocol"));
26        assert!(song.album_cid_ref().eq("7769"));
27    }
28
29	#[tokio::test]
30	async fn test_fetch_song_index() {
31		assert!(fetch_song_details("880318").await.unwrap().fetch_song_index().await.unwrap() == 1);
32		assert!(fetch_song_details("880319").await.unwrap().fetch_song_index().await.unwrap() == 2);
33	}
34
35	#[tokio::test]
36	async fn test_get_song_index() {
37		let album: Album = fetch_album_details("9385").await.unwrap();
38		assert!(fetch_song_details("697619").await.unwrap().get_song_index(&album).unwrap() == 1);
39		assert!(fetch_song_details("125065").await.unwrap().get_song_index(&album).unwrap() == 7);
40		assert!(fetch_song_details("880329").await.unwrap().get_song_index(&album).unwrap() == 11);
41	}
42
43    #[tokio::test]
44    async fn test_fetch_album_details() {
45        let album: Album = fetch_album_details("7769").await.unwrap();
46        assert!(album.cid_ref().eq("7769"));
47        assert!(album.name_ref().eq("卫戍协议OST"));
48        assert!(album.songs_ref().len() == 2);
49    }
50    #[tokio::test]
51    async fn test_fetch_album_list() {
52        let albums: Vec<crate::types::album::AlbumSyn> = fetch_album_list().await.unwrap();
53        let a0: &crate::types::album::AlbumSyn = albums.get(0).unwrap();
54        assert!(albums.len() >= 215);
55        assert!(a0.cid_ref().eq("4504"))
56    }
57    #[tokio::test]
58    async fn test_lyrics_from_url() {
59        let lyrics: Lyrics = from_lyrics_url("https://web.hycdn.cn/siren/lyric/20230427/673ac618161e937954f4b8fc93c346fd.lrc").await.unwrap();
60        assert!(lyrics.lines_ref()[0].content_ref().eq("Waiting by the window to revel in the last light of day"));
61        assert!(lyrics.lines_ref()[1].content_ref().eq("Hoping that these empty halls are here to guide my way"));
62        println!("{}", lyrics.to_lrc());
63    }
64    
65    
66    #[tokio::test]
67    async fn test_get_release_date() {
68        assert!(fetch_song_details("880318").await.unwrap().get_release_date().eq(&chrono::NaiveDate::from_ymd_opt(2024, 11, 15).unwrap()));
69        assert!(fetch_song_details("232258").await.unwrap().get_release_date().eq(&chrono::NaiveDate::from_ymd_opt(2023, 12, 28).unwrap()));
70    }
71}