Complete unit tests
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m7s
Cargo CI / Lint (pull_request) Successful in 1m7s

This commit is contained in:
Wojciech Kozlowski 2025-01-03 20:56:10 +01:00
parent 493b8a3928
commit b84be9abcd

View File

@ -33,11 +33,10 @@ impl BrowseReleaseGroupPage {
pub type SerdeBrowseReleaseGroupPage = BrowseReleaseGroupPage; pub type SerdeBrowseReleaseGroupPage = BrowseReleaseGroupPage;
impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> { impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
pub fn browse_release_group( fn browse_release_group_url(
&mut self,
request: &BrowseReleaseGroupRequest, request: &BrowseReleaseGroupRequest,
paging: &PageSettings, paging: &PageSettings,
) -> Result<BrowseReleaseGroupResponse, Error> { ) -> String {
let entity = &request.entity; let entity = &request.entity;
let mbid = request.mbid.uuid().as_hyphenated(); let mbid = request.mbid.uuid().as_hyphenated();
let status = request let status = request
@ -47,8 +46,15 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
.unwrap_or_default(); .unwrap_or_default();
let page = ApiDisplay::format_page_settings(paging); 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<BrowseReleaseGroupResponse, Error> {
let url = Self::browse_release_group_url(request, paging);
let response: DeserializeBrowseReleaseGroupResponse = self.http.get(&url)?; let response: DeserializeBrowseReleaseGroupResponse = self.http.get(&url)?;
Ok(response.into()) Ok(response.into())
} }
@ -207,4 +213,38 @@ mod tests {
let result = client.browse_release_group(&request, &paging).unwrap(); let result = client.browse_release_group(&request, &paging).unwrap();
assert_eq!(result, response); assert_eq!(result, response);
} }
#[test]
fn browse_release_group_filter_status() {
type Client = MusicBrainzClient<MockIMusicBrainzHttp>;
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);
}
} }