Integrate browse API into TUI MB daemon #230

Merged
wojtek merged 15 commits from 160---provide-a-keyboard-shortcut-to-pull-all-release-groups-of-an-artist into main 2024-10-06 15:32:46 +02:00
4 changed files with 97 additions and 3 deletions
Showing only changes of commit 9c2bbd2397 - Show all commits

View File

@ -50,7 +50,7 @@ grcov codecov/debug/profraw \
--ignore "tests/*" \
--ignore "src/main.rs" \
--ignore "src/bin/musichoard-edit.rs" \
--excl-line "^#\[derive" \
--excl-line "^#\[derive|unimplemented\!\(\)" \
--excl-start "GRCOV_EXCL_START|mod tests \{" \
--excl-stop "GRCOV_EXCL_STOP" \
--output-path ./codecov/debug/coverage/

View File

@ -61,7 +61,7 @@ impl<Http> MusicBrainzClient<Http> {
}
}
#[derive(Debug, Default)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct PageSettings {
limit: Option<usize>,
offset: Option<usize>,
@ -80,7 +80,7 @@ impl PageSettings {
}
pub fn with_offset(mut self, offset: usize) -> Self {
self.offset = Some(offset);
self.set_offset(offset);
self
}

View File

@ -467,6 +467,12 @@ mod tests {
])
}
fn browse_albums_requests() -> VecDeque<MbParams> {
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.info.musicbrainz);
let arid = mb_ref_opt_unwrap(mbref).mbid().clone();
VecDeque::from([MbParams::browse_release_group(arid)])
}
fn album_artist_id() -> ArtistId {
COLLECTION[1].meta.id.clone()
}
@ -609,6 +615,9 @@ mod tests {
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Err(JobError::JobQueueEmpty));
let result = result_receiver.try_recv().unwrap();
assert_eq!(
result,
@ -657,6 +666,9 @@ mod tests {
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Err(JobError::JobQueueEmpty));
let result = result_receiver.try_recv().unwrap();
let artist_id = album_artist_id();
assert_eq!(
@ -703,6 +715,9 @@ mod tests {
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Err(JobError::JobQueueEmpty));
let result = result_receiver.try_recv().unwrap();
assert_eq!(
result,
@ -759,6 +774,9 @@ mod tests {
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Err(JobError::JobQueueEmpty));
let artist_id = album_artist_id();
let result = result_receiver.try_recv().unwrap();
@ -828,6 +846,75 @@ mod tests {
assert_eq!(result, Err(JobError::EventChannelDisconnected));
}
fn browse_release_group_expectation(
musicbrainz: &mut MockIMusicBrainz,
seq: &mut Sequence,
mbid: &Mbid,
page: Option<PageSettings>,
matches: &[Entity<AlbumMeta>],
next_page: Option<PageSettings>,
) {
let result = Ok(matches.to_owned());
musicbrainz
.expect_browse_release_group()
.with(predicate::eq(mbid.clone()), predicate::eq(page))
.times(1)
.in_sequence(seq)
.return_once(move |_, paging| {
*paging = next_page;
result
});
}
#[test]
fn execute_browse_release_groups() {
let mut musicbrainz = musicbrainz();
let arid = album_arid_expectation();
let (_, matches_1) = search_album_expectations_1();
let (_, matches_4) = search_album_expectations_4();
let mut seq = Sequence::new();
let page = Some(PageSettings::with_max_limit());
let next = Some(PageSettings::with_max_limit().with_offset(10));
browse_release_group_expectation(&mut musicbrainz, &mut seq, &arid, page, &matches_1, next);
let page = next;
let next = None;
browse_release_group_expectation(&mut musicbrainz, &mut seq, &arid, page, &matches_4, next);
let mut event_sender = event_sender();
fetch_complete_expectation(&mut event_sender, 2);
let (job_sender, job_receiver) = job_channel();
let mut daemon = daemon_with(musicbrainz, job_receiver, event_sender);
let requests = browse_albums_requests();
let (result_sender, result_receiver) = mpsc::channel();
let result = job_sender.submit_background_job(result_sender, requests);
assert_eq!(result, Ok(()));
let result = daemon.enqueue_all_pending_jobs();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Ok(()));
let result = daemon.execute_next_job();
assert_eq!(result, Err(JobError::JobQueueEmpty));
let result = result_receiver.try_recv().unwrap();
let fetch = EntityList::Album(matches_1.into_iter().map(|m| m.entity).collect());
assert_eq!(result, Ok(MbReturn::Fetch(fetch)));
let result = result_receiver.try_recv().unwrap();
let fetch = EntityList::Album(matches_4.into_iter().map(|m| m.entity).collect());
assert_eq!(result, Ok(MbReturn::Fetch(fetch)));
}
#[test]
fn job_queue() {
let mut queue = JobQueue::new();

View File

@ -135,6 +135,13 @@ impl MbParams {
album,
}))
}
#[allow(dead_code)] // TODO: to be removed by completion of #160
pub fn browse_release_group(artist: Mbid) -> Self {
MbParams::Browse(BrowseParams::ReleaseGroup(BrowseReleaseGroupParams {
artist,
}))
}
}
#[cfg(test)]