test(core): fix album_with_artists fixture — missing composer/version

qbz-core tests did not compile since the Album model gained these
fields; the test-only helper never got them. Found while adding the
poisoned-item parse_page test.

cc
This commit is contained in:
vicrodh committed 2026-07-08 11:00:15 -06:00
1 parent 2f258e1933
commit 982716acb7
1 file changed
+42 -9
+42 -9
View File
@@ -45,15 +45,24 @@ fn parse_page<T: serde::de::DeserializeOwned>(
value: &serde_json::Value,
key: &str,
) -> SearchResultsPage<T> {
value
.get(key)
.and_then(|v| serde_json::from_value(v.clone()).ok())
.unwrap_or(SearchResultsPage {
items: Vec::new(),
total: 0,
offset: 0,
limit: 0,
})
// Scalars keep the old fallback semantics (missing/odd-shaped → 0, per
// the serde defaults on SearchResultsPage), but the items array is parsed
// PER ITEM: the previous whole-page `from_value(...).ok()` was
// all-or-nothing, so one malformed entry blanked the entire search tab
// (same class as favorites #556).
let scalar = |name: &str| {
value
.get(key)
.and_then(|p| p.get(name))
.and_then(|v| v.as_u64())
.unwrap_or(0) as u32
};
SearchResultsPage {
items: qbz_models::lenient::parse_items_array(value, key, key),
total: scalar("total"),
offset: scalar("offset"),
limit: scalar("limit"),
}
}
/// Pick the first `most_popular` entry that survives the blacklist.
@@ -2802,6 +2811,28 @@ mod tests {
assert!(out.most_popular.is_none());
}
#[test]
fn parse_page_skips_poisoned_item_keeps_rest() {
// One malformed entry (id is a string where Artist.id: u64) must NOT
// blank the page — the old whole-page from_value did exactly that.
let json = serde_json::json!({
"artists": {
"items": [
{ "id": 1, "name": "Keep" },
{ "id": "poisoned", "name": "Bad" },
{ "id": 2, "name": "AlsoKeep" }
],
"total": 3, "offset": 0, "limit": 30
}
});
let page = parse_page::<Artist>(&json, "artists");
assert_eq!(page.items.len(), 2);
assert_eq!(page.items[0].name, "Keep");
assert_eq!(page.items[1].name, "AlsoKeep");
assert_eq!(page.total, 3);
assert_eq!(page.limit, 30);
}
// --- D-FEAT featured-aware blacklist helpers ---
use qbz_models::types::{AlbumArtist, AlbumSummary};
@@ -2858,6 +2889,8 @@ mod tests {
awards: None,
parental_warning: None,
artists: Some(artists),
composer: None,
version: None,
}
}