diff --git a/src/import_dats.rs b/src/import_dats.rs index 6922bfe7..fb91e4c5 100644 --- a/src/import_dats.rs +++ b/src/import_dats.rs @@ -108,7 +108,10 @@ pub async fn main( progress_bar.println("Custom system name requires a single DAT file"); return Ok(()); } - if find_system_by_name(connection, custom_name.unwrap()).await.is_some() { + if find_system_by_name(connection, custom_name.unwrap()) + .await + .is_some() + { progress_bar.println("Custom system name must not match a known system name"); return Ok(()); } @@ -650,6 +653,8 @@ mod test_dat; #[cfg(test)] mod test_dat_custom_name; #[cfg(test)] +mod test_dat_custom_name_revert; +#[cfg(test)] mod test_dat_headered; #[cfg(test)] mod test_dat_headered_duplicate_clrmamepro; diff --git a/src/import_dats/test_dat_custom_name_revert.rs b/src/import_dats/test_dat_custom_name_revert.rs new file mode 100644 index 00000000..58b9df2a --- /dev/null +++ b/src/import_dats/test_dat_custom_name_revert.rs @@ -0,0 +1,61 @@ +use super::super::database::*; +use super::*; +use std::path::PathBuf; +use tempfile::{NamedTempFile, TempDir}; + +#[tokio::test] +async fn test() { + // given + let _guard = MUTEX.lock().await; + + let test_directory = Path::new("tests"); + let progress_bar = ProgressBar::hidden(); + + let db_file = NamedTempFile::new().unwrap(); + let pool = establish_connection(db_file.path().to_str().unwrap()).await; + let mut connection = pool.acquire().await.unwrap(); + + let rom_directory = TempDir::new_in(&test_directory).unwrap(); + set_rom_directory(PathBuf::from(rom_directory.path())); + let tmp_directory = TempDir::new_in(&test_directory).unwrap(); + set_tmp_directory(PathBuf::from(tmp_directory.path())); + + let dat_path = test_directory.join("Test System (20200721).dat"); + let (datfile_xml, detector_xml) = parse_dat(&progress_bar, &dat_path, false).await.unwrap(); + + import_dat( + &mut connection, + &progress_bar, + &datfile_xml, + &detector_xml, + Some(&String::from("Custom Test System")), + false, + false, + ) + .await + .unwrap(); + + // when + import_dat( + &mut connection, + &progress_bar, + &datfile_xml, + &detector_xml, + None, + false, + true, + ) + .await + .unwrap(); + + // then + let systems = find_systems(&mut connection).await; + assert_eq!(systems.len(), 1); + + let system = systems.first().unwrap(); + assert_eq!(system.name, "Test System"); + assert!(system.custom_name.is_none()); + + assert_eq!(find_games(&mut connection).await.len(), 6); + assert_eq!(find_roms(&mut connection).await.len(), 8); +}