Skip to content

Commit

Permalink
feat(utils/test): move assert song info to helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia committed Feb 2, 2024
1 parent 28f1711 commit 74a68b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 71 deletions.
75 changes: 4 additions & 71 deletions src/open_subsonic/scan/scan_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
open_subsonic::browsing::test::setup_user_and_music_folders,
utils::{
song::file_type::{to_extension, to_extensions},
test::media::query_all_songs_information,
test::media::assert_song_info,
},
};

Expand All @@ -156,30 +156,8 @@ mod tests {
scan_full::<&str>(db.get_pool(), &[], &music_folders)
.await
.unwrap();
let mut song_db_info = query_all_songs_information(db.get_pool()).await;

for (song_key, song_tag) in song_fs_info {
let (song, album, artists, album_artists) = song_db_info.remove(&song_key).unwrap();
assert_eq!(song_tag.title, song.title);
assert_eq!(song_tag.album, album.name);
assert_eq!(
song_tag.artists.into_iter().sorted().collect_vec(),
artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
assert_eq!(
song_tag.album_artists.into_iter().sorted().collect_vec(),
album_artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
}
assert!(song_db_info.is_empty());
assert_song_info(db.get_pool(), song_fs_info).await;
}

#[tokio::test]
Expand Down Expand Up @@ -228,30 +206,7 @@ mod tests {
.await
.unwrap();

let mut song_db_info = query_all_songs_information(db.get_pool()).await;

for (song_key, song_tag) in song_fs_info {
let (song, album, artists, album_artists) = song_db_info.remove(&song_key).unwrap();
assert_eq!(song_tag.title, song.title);
assert_eq!(song_tag.album, album.name);
assert_eq!(
song_tag.artists.into_iter().sorted().collect_vec(),
artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
assert_eq!(
song_tag.album_artists.into_iter().sorted().collect_vec(),
album_artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
}
assert!(song_db_info.is_empty());
assert_song_info(db.get_pool(), song_fs_info).await;
}

#[tokio::test]
Expand All @@ -275,30 +230,8 @@ mod tests {
scan_full::<&str>(db.get_pool(), &[], &music_folders)
.await
.unwrap();
let mut song_db_info = query_all_songs_information(db.get_pool()).await;

for (song_key, song_tag) in song_fs_info {
let (song, album, artists, album_artists) = song_db_info.remove(&song_key).unwrap();
assert_eq!(song_tag.title, song.title);
assert_eq!(song_tag.album, album.name);
assert_eq!(
song_tag.artists.into_iter().sorted().collect_vec(),
artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
assert_eq!(
song_tag.album_artists.into_iter().sorted().collect_vec(),
album_artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
}
assert!(song_db_info.is_empty());
assert_song_info(db.get_pool(), song_fs_info).await;
}

#[tokio::test]
Expand Down
32 changes: 32 additions & 0 deletions src/utils/test/media.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::models::*;
use crate::utils::song::tag::SongTag;
use crate::DatabasePool;

use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
use futures::stream::{self, StreamExt};
use itertools::Itertools;
use std::collections::HashMap;
use std::path::PathBuf;
use uuid::Uuid;
Expand Down Expand Up @@ -102,3 +104,33 @@ pub async fn query_all_songs_information(
.collect::<HashMap<_, _>>()
.await
}

pub async fn assert_song_info(
pool: &DatabasePool,
song_fs_info: HashMap<(Uuid, PathBuf), SongTag>,
) {
let mut song_db_info = query_all_songs_information(pool).await;

for (song_key, song_tag) in song_fs_info {
let (song, album, artists, album_artists) = song_db_info.remove(&song_key).unwrap();
assert_eq!(song_tag.title, song.title);
assert_eq!(song_tag.album, album.name);
assert_eq!(
song_tag.artists.into_iter().sorted().collect_vec(),
artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
assert_eq!(
song_tag.album_artists.into_iter().sorted().collect_vec(),
album_artists
.into_iter()
.map(|artist| artist.name)
.sorted()
.collect_vec()
);
}
assert!(song_db_info.is_empty());
}

0 comments on commit 74a68b5

Please sign in to comment.