From b84be9abcd9738d9ba6fcb9b11b50cfb38173e2d Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Fri, 3 Jan 2025 20:56:10 +0100 Subject: [PATCH] Complete unit tests --- src/external/musicbrainz/api/browse.rs | 48 +++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/external/musicbrainz/api/browse.rs b/src/external/musicbrainz/api/browse.rs index e662d0f..2a3125d 100644 --- a/src/external/musicbrainz/api/browse.rs +++ b/src/external/musicbrainz/api/browse.rs @@ -33,11 +33,10 @@ impl BrowseReleaseGroupPage { pub type SerdeBrowseReleaseGroupPage = BrowseReleaseGroupPage; impl MusicBrainzClient { - pub fn browse_release_group( - &mut self, + fn browse_release_group_url( request: &BrowseReleaseGroupRequest, paging: &PageSettings, - ) -> Result { + ) -> String { let entity = &request.entity; let mbid = request.mbid.uuid().as_hyphenated(); let status = request @@ -47,8 +46,15 @@ impl MusicBrainzClient { .unwrap_or_default(); let page = ApiDisplay::format_page_settings(paging); - let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}"); + format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}") + } + pub fn browse_release_group( + &mut self, + request: &BrowseReleaseGroupRequest, + paging: &PageSettings, + ) -> Result { + let url = Self::browse_release_group_url(request, paging); let response: DeserializeBrowseReleaseGroupResponse = self.http.get(&url)?; Ok(response.into()) } @@ -207,4 +213,38 @@ mod tests { let result = client.browse_release_group(&request, &paging).unwrap(); assert_eq!(result, response); } + + #[test] + fn browse_release_group_filter_status() { + type Client = MusicBrainzClient; + let mbid_str = "00000000-0000-0000-0000-000000000000"; + let mbid: Mbid = mbid_str.try_into().unwrap(); + let paging = PageSettings::with_max_limit(); + + let request = BrowseReleaseGroupRequest::artist(&mbid); + let url = format!( + "https://musicbrainz.org/ws/2/release-group\ + ?artist={mbid_str}\ + &limit={MB_MAX_PAGE_LIMIT}", + ); + assert_eq!(Client::browse_release_group_url(&request, &paging), url); + + let request = BrowseReleaseGroupRequest::artist(&mbid).filter_status_website_default(); + let url = format!( + "https://musicbrainz.org/ws/2/release-group\ + ?artist={mbid_str}\ + &release-group-status=website-default\ + &limit={MB_MAX_PAGE_LIMIT}", + ); + assert_eq!(Client::browse_release_group_url(&request, &paging), url); + + let request = BrowseReleaseGroupRequest::artist(&mbid).filter_status_all(); + let url = format!( + "https://musicbrainz.org/ws/2/release-group\ + ?artist={mbid_str}\ + &release-group-status=all\ + &limit={MB_MAX_PAGE_LIMIT}", + ); + assert_eq!(Client::browse_release_group_url(&request, &paging), url); + } }