Add support for MusicBrainz's Browse API #228
14
src/external/musicbrainz/api/browse.rs
vendored
14
src/external/musicbrainz/api/browse.rs
vendored
@ -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";
|
||||
|
20
src/external/musicbrainz/api/mod.rs
vendored
20
src/external/musicbrainz/api/mod.rs
vendored
@ -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();
|
||||
|
17
src/external/musicbrainz/api/search/mod.rs
vendored
17
src/external/musicbrainz/api/search/mod.rs
vendored
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user