Skip to content

Commit

Permalink
add a unit test for custom name reversing
Browse files Browse the repository at this point in the history
  • Loading branch information
alucryd committed Mar 14, 2024
1 parent b7317a9 commit 704d397
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/import_dats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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;
Expand Down
61 changes: 61 additions & 0 deletions src/import_dats/test_dat_custom_name_revert.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 704d397

Please sign in to comment.