Updted to also allow mbid
This commit is contained in:
@@ -3,6 +3,7 @@ use sea_orm::ActiveValue::Set;
|
||||
|
||||
use shanty_db::entities::wanted_item::{ItemType, WantedStatus};
|
||||
use shanty_db::{Database, queries};
|
||||
use shanty_tag::MusicBrainzClient;
|
||||
use shanty_watch::{add_album, add_artist, add_track, library_summary, list_items, remove_item};
|
||||
|
||||
async fn test_db() -> Database {
|
||||
@@ -36,11 +37,14 @@ async fn insert_track(db: &Database, artist: &str, title: &str, album: &str) {
|
||||
queries::tracks::upsert(db.conn(), active).await.unwrap();
|
||||
}
|
||||
|
||||
// No MB client needed for tests — pass None
|
||||
const NO_MB: Option<&MusicBrainzClient> = None;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_artist_wanted() {
|
||||
let db = test_db().await;
|
||||
|
||||
let entry = add_artist(db.conn(), "Radiohead", None).await.unwrap();
|
||||
let entry = add_artist(db.conn(), Some("Radiohead"), None, NO_MB).await.unwrap();
|
||||
assert_eq!(entry.item_type, ItemType::Artist);
|
||||
assert_eq!(entry.name, "Radiohead");
|
||||
assert_eq!(entry.status, WantedStatus::Wanted);
|
||||
@@ -50,11 +54,9 @@ async fn test_add_artist_wanted() {
|
||||
async fn test_add_artist_auto_owned() {
|
||||
let db = test_db().await;
|
||||
|
||||
// Index some tracks first
|
||||
insert_track(&db, "Pink Floyd", "Time", "DSOTM").await;
|
||||
|
||||
// Add artist to watchlist — should auto-detect as owned
|
||||
let entry = add_artist(db.conn(), "Pink Floyd", None).await.unwrap();
|
||||
let entry = add_artist(db.conn(), Some("Pink Floyd"), None, NO_MB).await.unwrap();
|
||||
assert_eq!(entry.status, WantedStatus::Owned);
|
||||
}
|
||||
|
||||
@@ -62,7 +64,7 @@ async fn test_add_artist_auto_owned() {
|
||||
async fn test_add_album_wanted() {
|
||||
let db = test_db().await;
|
||||
|
||||
let entry = add_album(db.conn(), "Radiohead", "OK Computer", None)
|
||||
let entry = add_album(db.conn(), Some("Radiohead"), Some("OK Computer"), None, NO_MB)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(entry.item_type, ItemType::Album);
|
||||
@@ -76,7 +78,7 @@ async fn test_add_album_auto_owned() {
|
||||
|
||||
insert_track(&db, "Pink Floyd", "Time", "DSOTM").await;
|
||||
|
||||
let entry = add_album(db.conn(), "Pink Floyd", "DSOTM", None)
|
||||
let entry = add_album(db.conn(), Some("Pink Floyd"), Some("DSOTM"), None, NO_MB)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(entry.status, WantedStatus::Owned);
|
||||
@@ -86,7 +88,7 @@ async fn test_add_album_auto_owned() {
|
||||
async fn test_add_track_wanted() {
|
||||
let db = test_db().await;
|
||||
|
||||
let entry = add_track(db.conn(), "Radiohead", "Creep", None)
|
||||
let entry = add_track(db.conn(), Some("Radiohead"), Some("Creep"), None, NO_MB)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(entry.item_type, ItemType::Track);
|
||||
@@ -100,7 +102,7 @@ async fn test_add_track_auto_owned() {
|
||||
|
||||
insert_track(&db, "Pink Floyd", "Time", "DSOTM").await;
|
||||
|
||||
let entry = add_track(db.conn(), "Pink Floyd", "Time", None)
|
||||
let entry = add_track(db.conn(), Some("Pink Floyd"), Some("Time"), None, NO_MB)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(entry.status, WantedStatus::Owned);
|
||||
@@ -110,8 +112,8 @@ async fn test_add_track_auto_owned() {
|
||||
async fn test_list_items_with_filters() {
|
||||
let db = test_db().await;
|
||||
|
||||
add_artist(db.conn(), "Radiohead", None).await.unwrap();
|
||||
add_artist(db.conn(), "Tool", None).await.unwrap();
|
||||
add_artist(db.conn(), Some("Radiohead"), None, NO_MB).await.unwrap();
|
||||
add_artist(db.conn(), Some("Tool"), None, NO_MB).await.unwrap();
|
||||
|
||||
// List all
|
||||
let all = list_items(db.conn(), None, None).await.unwrap();
|
||||
@@ -140,7 +142,7 @@ async fn test_list_items_with_filters() {
|
||||
async fn test_remove_item() {
|
||||
let db = test_db().await;
|
||||
|
||||
let entry = add_artist(db.conn(), "Radiohead", None).await.unwrap();
|
||||
let entry = add_artist(db.conn(), Some("Radiohead"), None, NO_MB).await.unwrap();
|
||||
let all = list_items(db.conn(), None, None).await.unwrap();
|
||||
assert_eq!(all.len(), 1);
|
||||
|
||||
@@ -155,10 +157,10 @@ async fn test_library_summary() {
|
||||
|
||||
insert_track(&db, "Pink Floyd", "Time", "DSOTM").await;
|
||||
|
||||
add_artist(db.conn(), "Radiohead", None).await.unwrap(); // wanted
|
||||
add_artist(db.conn(), "Pink Floyd", None).await.unwrap(); // owned
|
||||
add_album(db.conn(), "Tool", "Lateralus", None).await.unwrap(); // wanted
|
||||
add_track(db.conn(), "Pink Floyd", "Time", None).await.unwrap(); // owned
|
||||
add_artist(db.conn(), Some("Radiohead"), None, NO_MB).await.unwrap();
|
||||
add_artist(db.conn(), Some("Pink Floyd"), None, NO_MB).await.unwrap();
|
||||
add_album(db.conn(), Some("Tool"), Some("Lateralus"), None, NO_MB).await.unwrap();
|
||||
add_track(db.conn(), Some("Pink Floyd"), Some("Time"), None, NO_MB).await.unwrap();
|
||||
|
||||
let summary = library_summary(db.conn()).await.unwrap();
|
||||
assert_eq!(summary.total_artists, 2);
|
||||
|
||||
Reference in New Issue
Block a user