pinakes-core: add integration tests for batch_update_media
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0787bec99f7c1d098c1c1168560a43266a6a6964
This commit is contained in:
parent
592a9bcc47
commit
cf76d42c33
1 changed files with 105 additions and 0 deletions
|
|
@ -927,3 +927,108 @@ async fn test_transcode_sessions() {
|
|||
.unwrap();
|
||||
assert_eq!(cleaned, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_update_media_empty() {
|
||||
let storage = setup().await;
|
||||
|
||||
// Empty ID slice must return 0 without error.
|
||||
let count = storage
|
||||
.batch_update_media(&[], Some("title"), None, None, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_update_media_no_fields() {
|
||||
let storage = setup().await;
|
||||
let item = make_test_media("bum_nofield");
|
||||
storage.insert_media(&item).await.unwrap();
|
||||
|
||||
// No fields to change: implementation returns 0 (only updated_at would
|
||||
// shift, but the bulk path short-circuits when no real fields are given).
|
||||
let count = storage
|
||||
.batch_update_media(&[item.id], None, None, None, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_update_media_single_field() {
|
||||
let storage = setup().await;
|
||||
let item = make_test_media("bum_single");
|
||||
storage.insert_media(&item).await.unwrap();
|
||||
|
||||
let count = storage
|
||||
.batch_update_media(&[item.id], Some("Bulk Title"), None, None, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 1);
|
||||
|
||||
let fetched = storage.get_media(item.id).await.unwrap();
|
||||
assert_eq!(fetched.title.as_deref(), Some("Bulk Title"));
|
||||
// Fields not touched must remain unchanged.
|
||||
assert_eq!(fetched.artist.as_deref(), Some("Test Artist"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_update_media_multiple_items() {
|
||||
let storage = setup().await;
|
||||
|
||||
let item_a = make_test_media("bum_multi_a");
|
||||
let item_b = make_test_media("bum_multi_b");
|
||||
let item_c = make_test_media("bum_multi_c");
|
||||
storage.insert_media(&item_a).await.unwrap();
|
||||
storage.insert_media(&item_b).await.unwrap();
|
||||
storage.insert_media(&item_c).await.unwrap();
|
||||
|
||||
let ids = [item_a.id, item_b.id, item_c.id];
|
||||
let count = storage
|
||||
.batch_update_media(
|
||||
&ids,
|
||||
Some("Shared Title"),
|
||||
Some("Shared Artist"),
|
||||
Some("Shared Album"),
|
||||
Some("Jazz"),
|
||||
Some(2025),
|
||||
Some("Batch desc"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 3);
|
||||
|
||||
for id in &ids {
|
||||
let fetched = storage.get_media(*id).await.unwrap();
|
||||
assert_eq!(fetched.title.as_deref(), Some("Shared Title"));
|
||||
assert_eq!(fetched.artist.as_deref(), Some("Shared Artist"));
|
||||
assert_eq!(fetched.album.as_deref(), Some("Shared Album"));
|
||||
assert_eq!(fetched.genre.as_deref(), Some("Jazz"));
|
||||
assert_eq!(fetched.year, Some(2025));
|
||||
assert_eq!(fetched.description.as_deref(), Some("Batch desc"));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_update_media_subset_of_items() {
|
||||
let storage = setup().await;
|
||||
|
||||
let item_a = make_test_media("bum_subset_a");
|
||||
let item_b = make_test_media("bum_subset_b");
|
||||
storage.insert_media(&item_a).await.unwrap();
|
||||
storage.insert_media(&item_b).await.unwrap();
|
||||
|
||||
// Only update item_a.
|
||||
let count = storage
|
||||
.batch_update_media(&[item_a.id], Some("Only A"), None, None, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 1);
|
||||
|
||||
let fetched_a = storage.get_media(item_a.id).await.unwrap();
|
||||
let fetched_b = storage.get_media(item_b.id).await.unwrap();
|
||||
assert_eq!(fetched_a.title.as_deref(), Some("Only A"));
|
||||
// item_b must be untouched.
|
||||
assert_eq!(fetched_b.title, item_b.title);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue