Complete unit tests
This commit is contained in:
parent
493b8a3928
commit
b84be9abcd
@ -33,11 +33,10 @@ impl BrowseReleaseGroupPage {
|
||||
pub type SerdeBrowseReleaseGroupPage = BrowseReleaseGroupPage;
|
||||
|
||||
impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
||||
pub fn browse_release_group(
|
||||
&mut self,
|
||||
fn browse_release_group_url(
|
||||
request: &BrowseReleaseGroupRequest,
|
||||
paging: &PageSettings,
|
||||
) -> Result<BrowseReleaseGroupResponse, Error> {
|
||||
) -> String {
|
||||
let entity = &request.entity;
|
||||
let mbid = request.mbid.uuid().as_hyphenated();
|
||||
let status = request
|
||||
@ -47,8 +46,15 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
||||
.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<BrowseReleaseGroupResponse, Error> {
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user