Add support for MusicBrainz's Browse API #228

Merged
wojtek merged 9 commits from 160---provide-a-keyboard-shortcut-to-pull-all-release-groups-of-an-artist into main 2024-09-29 21:33:43 +02:00
3 changed files with 49 additions and 2 deletions
Showing only changes of commit 03c1b2b9ae - Show all commits

View File

@ -109,8 +109,8 @@ mod tests {
collection::album::{AlbumPrimaryType, AlbumSecondaryType},
external::musicbrainz::{
api::{
SerdeAlbumDate, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, SerdeMbid,
MB_MAX_PAGE_LIMIT,
tests::next_page_test, SerdeAlbumDate, SerdeAlbumPrimaryType,
SerdeAlbumSecondaryType, SerdeMbid, MB_MAX_PAGE_LIMIT,
},
MockIMusicBrainzHttp,
},
@ -118,6 +118,16 @@ mod tests {
use super::*;
#[test]
fn browse_release_group_next_page() {
let page = BrowseReleaseGroupPage {
release_group_offset: 5,
release_group_count: 45,
};
next_page_test(|val| page.next_page_offset(val));
}
#[test]
fn browse_release_group() {
let mbid = "00000000-0000-0000-0000-000000000000";

View File

@ -84,6 +84,7 @@ impl PageSettings {
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum NextPage {
Offset(usize),
Complete,
@ -358,6 +359,25 @@ mod tests {
assert!(!format!("{unk_err:?}").is_empty());
}
pub fn next_page_test<Fn>(mut f: Fn)
where
Fn: FnMut(usize) -> NextPage,
{
let next = f(20);
assert_eq!(next, NextPage::Offset(25));
let next = f(40);
assert_eq!(next, NextPage::Complete);
let next = f(100);
assert_eq!(next, NextPage::Complete);
}
#[test]
fn next_page() {
next_page_test(|val| NextPage::next_page_offset(5, 45, val));
}
#[test]
fn format_page_settings() {
let paging = PageSettings::default();

View File

@ -64,3 +64,20 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
impl_search_entity!(Artist, "artist");
impl_search_entity!(ReleaseGroup, "release-group");
}
#[cfg(test)]
mod tests {
use crate::external::musicbrainz::api::tests::next_page_test;
use super::*;
#[test]
fn search_next_page() {
let page = SearchPage {
offset: 5,
count: 45,
};
next_page_test(|val| page.next_page_offset(val));
}
}