Enable fetch to apply modifications to the database #221

Merged
wojtek merged 14 commits from 189---enable-fetch-to-apply-modifications-to-the-database into main 2024-09-29 10:44:38 +02:00
3 changed files with 50 additions and 26 deletions
Showing only changes of commit 967c4b4175 - Show all commits

View File

@ -100,14 +100,14 @@ impl ArtistMeta {
impl Default for ArtistInfo {
fn default() -> Self {
Self::new()
Self::new(MbRefOption::None)
}
}
impl ArtistInfo {
pub fn new() -> Self {
pub fn new(musicbrainz: MbRefOption<MbArtistRef>) -> Self {
ArtistInfo {
musicbrainz: MbRefOption::None,
musicbrainz,
properties: HashMap::new(),
}
}

View File

@ -461,7 +461,7 @@ mod tests {
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
assert_eq!(music_hoard.collection[0].meta.info.musicbrainz, expected);
let mut info = ArtistInfo::new();
let mut info = ArtistInfo::default();
info.musicbrainz = MbRefOption::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
// Setting a URL on an artist not in the collection is an error.

View File

@ -308,7 +308,7 @@ impl IAppInteractMatch for AppMachine<MatchState> {
mod tests {
use std::{collections::VecDeque, sync::mpsc};
use mockall::predicate;
use mockall::predicate::{self, eq};
use musichoard::collection::{
album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
artist::{ArtistId, ArtistMeta},
@ -346,8 +346,12 @@ mod tests {
}
}
fn artist_meta() -> ArtistMeta {
ArtistMeta::new(ArtistId::new("Artist"))
}
fn artist_match() -> MatchStateInfo {
let artist = ArtistMeta::new(ArtistId::new("Artist"));
let artist = artist_meta();
let artist_1 = artist.clone();
let artist_match_1 = Match::new(100, artist_1);
@ -361,14 +365,13 @@ mod tests {
}
fn artist_lookup() -> MatchStateInfo {
let artist = ArtistMeta::new(ArtistId::new("Artist"));
let artist = artist_meta();
let lookup = Lookup::new(artist.clone());
MatchStateInfo::artist_lookup(artist, lookup)
}
fn album_match() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = AlbumMeta::new(
fn album_meta() -> AlbumMeta {
AlbumMeta::new(
AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None),
AlbumInfo::new(
@ -376,7 +379,12 @@ mod tests {
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
);
)
}
fn album_match() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = album_meta();
let album_1 = album.clone();
let album_match_1 = Match::new(100, album_1);
@ -392,15 +400,7 @@ mod tests {
fn album_lookup() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = AlbumMeta::new(
AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None),
AlbumInfo::new(
MbRefOption::None,
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
);
let album = album_meta();
let lookup = Lookup::new(album.clone());
MatchStateInfo::album_lookup(artist_id, album, lookup)
}
@ -457,11 +457,34 @@ mod tests {
fn match_state_flow(mut matches_info: MatchStateInfo, len: usize) {
// tx must exist for rx to return Empty rather than Disconnected.
#[allow(unused_variables)]
let (tx, rx) = mpsc::channel();
let (_tx, rx) = mpsc::channel();
let app_matches = MatchState::new(Some(matches_info.clone()), FetchState::new(rx));
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
let mut music_hoard = music_hoard(vec![]);
let artist_id = ArtistId::new("Artist");
match matches_info {
MatchStateInfo::Album(_) => {
let album_id = AlbumId::new("Album");
let mut info = album_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
music_hoard
.expect_set_album_info()
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
.times(1)
.return_once(|_, _, _| Ok(()));
}
MatchStateInfo::Artist(_) => {
let mut info = artist_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
music_hoard
.expect_set_artist_info()
.with(eq(artist_id.clone()), eq(info))
.times(1)
.return_once(|_, _| Ok(()));
}
}
let matches = AppMachine::match_state(inner(music_hoard), app_matches);
matches_info.push_cannot_have_mbid();
matches_info.push_manual_input_mbid();
@ -547,10 +570,11 @@ mod tests {
#[test]
fn select_empty() {
// Note that what really matters in this test is actually that the transmit channel has
// disconnected and so the receive within FetchState concludes there are no more matches.
// This test will become obsolete with #203 so it just needs to work well enough for
// coverage. We expect the error state, because after selecting, fetch will be invoked, but
// with an empty collection, an error will be raised.
let matches = AppMachine::match_state(inner(music_hoard(vec![])), match_state(None));
matches.select().unwrap_browse();
matches.select().unwrap_error();
}
#[test]