Compare commits

...

2 Commits

Author SHA1 Message Date
17d94e59f1 Fix all unit tests
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 2m41s
Cargo CI / Lint (pull_request) Successful in 1m5s
2024-10-06 14:31:14 +02:00
dd9141352c Fix lib unit tests 2024-10-06 13:38:07 +02:00
3 changed files with 30 additions and 29 deletions

View File

@ -48,8 +48,12 @@ pub enum MbRefOption<T> {
impl<T> MbRefOption<T> {
pub fn or(self, optb: MbRefOption<T>) -> MbRefOption<T> {
match self {
x @ MbRefOption::Some(_) => x,
MbRefOption::CannotHaveMbid | MbRefOption::None => optb,
opta @ MbRefOption::Some(_) => opta,
opta @ MbRefOption::CannotHaveMbid => match optb {
MbRefOption::Some(_) => optb,
MbRefOption::CannotHaveMbid | MbRefOption::None => opta,
},
MbRefOption::None => optb,
}
}

View File

@ -395,8 +395,10 @@ mod tests {
match matches_info {
EntityMatches::Album(_) => {
let album_id = AlbumId::new("Album");
let mut info = album_meta(album_id.clone()).info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
let info = AlbumInfo {
musicbrainz: MbRefOption::CannotHaveMbid,
..Default::default()
};
music_hoard
.expect_merge_album_info()
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
@ -404,8 +406,10 @@ mod tests {
.return_once(|_, _, _| Ok(()));
}
EntityMatches::Artist(_) => {
let mut info = artist_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
let info = ArtistInfo {
musicbrainz: MbRefOption::CannotHaveMbid,
..Default::default()
};
music_hoard
.expect_merge_artist_info()
.with(eq(artist_id.clone()), eq(info))

View File

@ -252,10 +252,6 @@ impl JobInstance {
api_params: &MbParams,
paging: &mut Option<PageSettings>,
) -> Result<(), JobInstanceError> {
if paging.is_none() {
*paging = Some(PageSettings::with_max_limit());
}
let result = match api_params {
MbParams::Lookup(lookup) => match lookup {
LookupParams::Artist(p) => musicbrainz
@ -280,15 +276,24 @@ impl JobInstance {
}
.map(MbReturn::Match),
MbParams::Browse(browse) => match browse {
BrowseParams::ReleaseGroup(params) => musicbrainz
.browse_release_group(&params.artist, paging)
.map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect())),
BrowseParams::ReleaseGroup(params) => {
Self::init_paging_if_none(paging);
musicbrainz
.browse_release_group(&params.artist, paging)
.map(|rv| EntityList::Album(rv.into_iter().map(|rg| rg.entity).collect()))
}
}
.map(MbReturn::Fetch),
};
Self::return_result(result_sender, event_sender, result)
}
fn init_paging_if_none(paging: &mut Option<PageSettings>) {
if paging.is_none() {
*paging = Some(PageSettings::with_max_limit());
}
}
fn return_result(
result_sender: &mut ResultSender,
event_sender: &mut dyn IFetchCompleteEventSender,
@ -757,24 +762,12 @@ mod tests {
let artist_id = album_artist_id();
let result = result_receiver.try_recv().unwrap();
assert_eq!(
result,
Ok(MbReturn::Match(EntityMatches::album_search(
artist_id.clone(),
album_1.id,
matches_1
)))
);
let matches = EntityMatches::album_search(artist_id.clone(), album_1.id, matches_1);
assert_eq!(result, Ok(MbReturn::Match(matches)));
let result = result_receiver.try_recv().unwrap();
assert_eq!(
result,
Ok(MbReturn::Match(EntityMatches::album_search(
artist_id.clone(),
album_4.id,
matches_4
)))
);
let matches = EntityMatches::album_search(artist_id.clone(), album_4.id, matches_4);
assert_eq!(result, Ok(MbReturn::Match(matches)));
}
#[test]