Fix unit tests
This commit is contained in:
parent
925063d0e7
commit
b7779905bc
@ -365,7 +365,7 @@ impl IAppEventFetch for AppMachine<FetchState> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use mockall::predicate;
|
use mockall::{predicate, Sequence};
|
||||||
use musichoard::collection::{
|
use musichoard::collection::{
|
||||||
album::AlbumMeta,
|
album::AlbumMeta,
|
||||||
artist::{ArtistId, ArtistMeta},
|
artist::{ArtistId, ArtistMeta},
|
||||||
@ -739,11 +739,18 @@ mod tests {
|
|||||||
tx.send(fetch_result).unwrap();
|
tx.send(fetch_result).unwrap();
|
||||||
drop(tx);
|
drop(tx);
|
||||||
|
|
||||||
let mut music_hoard = music_hoard(collection);
|
let mut music_hoard = music_hoard(collection.clone());
|
||||||
|
let mut seq = Sequence::new();
|
||||||
|
music_hoard
|
||||||
|
.expect_get_collection()
|
||||||
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
|
.return_const(collection);
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_add_album()
|
.expect_add_album()
|
||||||
.with(predicate::eq(artist_id), predicate::eq(new_album))
|
.with(predicate::eq(artist_id), predicate::eq(new_album))
|
||||||
.times(1)
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
.return_once(|_, _| Ok(()));
|
.return_once(|_, _| Ok(()));
|
||||||
|
|
||||||
let app = AppMachine::app_fetch_next(inner(music_hoard), fetch);
|
let app = AppMachine::app_fetch_next(inner(music_hoard), fetch);
|
||||||
@ -766,11 +773,18 @@ mod tests {
|
|||||||
tx.send(fetch_result).unwrap();
|
tx.send(fetch_result).unwrap();
|
||||||
drop(tx);
|
drop(tx);
|
||||||
|
|
||||||
let mut music_hoard = music_hoard(collection);
|
let mut music_hoard = music_hoard(collection.clone());
|
||||||
|
let mut seq = Sequence::new();
|
||||||
|
music_hoard
|
||||||
|
.expect_get_collection()
|
||||||
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
|
.return_const(collection);
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_add_album()
|
.expect_add_album()
|
||||||
.with(predicate::eq(artist_id), predicate::eq(new_album))
|
.with(predicate::eq(artist_id), predicate::eq(new_album))
|
||||||
.times(1)
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
.return_once(|_, _| Err(musichoard::Error::CollectionError(String::from("get rekt"))));
|
.return_once(|_, _| Err(musichoard::Error::CollectionError(String::from("get rekt"))));
|
||||||
|
|
||||||
let app = AppMachine::app_fetch_next(inner(music_hoard), fetch);
|
let app = AppMachine::app_fetch_next(inner(music_hoard), fetch);
|
||||||
|
@ -447,7 +447,8 @@ mod tests {
|
|||||||
let (_tx, rx) = mpsc::channel();
|
let (_tx, rx) = mpsc::channel();
|
||||||
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
||||||
|
|
||||||
let mut music_hoard = music_hoard(vec![]);
|
let collection = vec![];
|
||||||
|
let mut music_hoard = music_hoard(collection.clone());
|
||||||
let artist_id = ArtistId::new("Artist");
|
let artist_id = ArtistId::new("Artist");
|
||||||
match matches_info {
|
match matches_info {
|
||||||
EntityMatches::Album(_) => {
|
EntityMatches::Album(_) => {
|
||||||
@ -456,6 +457,11 @@ mod tests {
|
|||||||
let info = AlbumInfo::default();
|
let info = AlbumInfo::default();
|
||||||
|
|
||||||
let mut seq = Sequence::new();
|
let mut seq = Sequence::new();
|
||||||
|
music_hoard
|
||||||
|
.expect_get_collection()
|
||||||
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
|
.return_const(collection);
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_merge_album_info()
|
.expect_merge_album_info()
|
||||||
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
|
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
|
||||||
@ -595,7 +601,8 @@ mod tests {
|
|||||||
let (_tx, rx) = mpsc::channel();
|
let (_tx, rx) = mpsc::channel();
|
||||||
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
||||||
|
|
||||||
let mut music_hoard = music_hoard(vec![]);
|
let collection = vec![];
|
||||||
|
let mut music_hoard = music_hoard(collection.clone());
|
||||||
match matches_info {
|
match matches_info {
|
||||||
EntityMatches::Artist(_) => panic!(),
|
EntityMatches::Artist(_) => panic!(),
|
||||||
EntityMatches::Album(matches) => {
|
EntityMatches::Album(matches) => {
|
||||||
@ -606,6 +613,11 @@ mod tests {
|
|||||||
let artist = matches.artist.clone();
|
let artist = matches.artist.clone();
|
||||||
|
|
||||||
let mut seq = Sequence::new();
|
let mut seq = Sequence::new();
|
||||||
|
music_hoard
|
||||||
|
.expect_get_collection()
|
||||||
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
|
.return_const(collection);
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_merge_album_info()
|
.expect_merge_album_info()
|
||||||
.with(eq(artist.clone()), eq(album_id.clone()), eq(meta.info))
|
.with(eq(artist.clone()), eq(album_id.clone()), eq(meta.info))
|
||||||
@ -647,13 +659,19 @@ mod tests {
|
|||||||
let (_tx, rx) = mpsc::channel();
|
let (_tx, rx) = mpsc::channel();
|
||||||
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
|
||||||
|
|
||||||
let mut music_hoard = music_hoard(vec![artist]);
|
let collection = vec![artist];
|
||||||
|
let mut music_hoard = music_hoard(collection.clone());
|
||||||
match matches_info {
|
match matches_info {
|
||||||
EntityMatches::Artist(_) => panic!(),
|
EntityMatches::Artist(_) => panic!(),
|
||||||
EntityMatches::Album(matches) => {
|
EntityMatches::Album(matches) => {
|
||||||
let artist = matches.artist.clone();
|
let artist = matches.artist.clone();
|
||||||
|
|
||||||
let mut seq = Sequence::new();
|
let mut seq = Sequence::new();
|
||||||
|
music_hoard
|
||||||
|
.expect_get_collection()
|
||||||
|
.times(1)
|
||||||
|
.in_sequence(&mut seq)
|
||||||
|
.return_const(collection);
|
||||||
music_hoard
|
music_hoard
|
||||||
.expect_remove_album()
|
.expect_remove_album()
|
||||||
.times(1)
|
.times(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user