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},
|
collection::album::{AlbumPrimaryType, AlbumSecondaryType},
|
||||||
external::musicbrainz::{
|
external::musicbrainz::{
|
||||||
api::{
|
api::{
|
||||||
SerdeAlbumDate, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, SerdeMbid,
|
tests::next_page_test, SerdeAlbumDate, SerdeAlbumPrimaryType,
|
||||||
MB_MAX_PAGE_LIMIT,
|
SerdeAlbumSecondaryType, SerdeMbid, MB_MAX_PAGE_LIMIT,
|
||||||
},
|
},
|
||||||
MockIMusicBrainzHttp,
|
MockIMusicBrainzHttp,
|
||||||
},
|
},
|
||||||
@ -118,6 +118,16 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn browse_release_group() {
|
fn browse_release_group() {
|
||||||
let mbid = "00000000-0000-0000-0000-000000000000";
|
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 {
|
pub enum NextPage {
|
||||||
Offset(usize),
|
Offset(usize),
|
||||||
Complete,
|
Complete,
|
||||||
@ -358,6 +359,25 @@ mod tests {
|
|||||||
assert!(!format!("{unk_err:?}").is_empty());
|
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]
|
#[test]
|
||||||
fn format_page_settings() {
|
fn format_page_settings() {
|
||||||
let paging = PageSettings::default();
|
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!(Artist, "artist");
|
||||||
impl_search_entity!(ReleaseGroup, "release-group");
|
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