use super::super::import_dats;
use super::super::import_roms;
use super::*;
use std::path::{Path, PathBuf};
use tempfile::{NamedTempFile, TempDir};
use tokio::fs;
#[tokio::test]
async fn test() {
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(&mut connection, PathBuf::from(rom_directory.path())).await;
let tmp_directory = TempDir::new_in(test_directory).unwrap();
let tmp_directory =
set_tmp_directory(&mut connection, PathBuf::from(tmp_directory.path())).await;
let matches = import_dats::subcommand().get_matches_from([
"import-dats",
"tests/Test System (20240229) (Single Track).dat",
]);
import_dats::main(&mut connection, &matches, &progress_bar)
.await
.unwrap();
let cue_romfile_path = tmp_directory.join("Test Game (USA, Europe) (Single Track).cue");
fs::copy(
test_directory.join("Test Game (USA, Europe) (Single Track).cue"),
&cue_romfile_path,
)
.await
.unwrap();
let chd_romfile_path = tmp_directory.join("Test Game (USA, Europe) (Single Track).chd");
fs::copy(
test_directory.join("Test Game (USA, Europe) (Single Track).chd"),
&chd_romfile_path,
)
.await
.unwrap();
let system = find_systems(&mut connection).await.remove(0);
let matches = import_roms::subcommand().get_matches_from([
"import-roms",
chd_romfile_path.as_os_str().to_str().unwrap(),
cue_romfile_path.as_os_str().to_str().unwrap(),
]);
import_roms::main(&mut connection, &matches, &progress_bar)
.await
.unwrap();
let mut roms_by_game_id: IndexMap<i64, Vec<Rom>> = IndexMap::new();
let mut romfiles_by_id: HashMap<i64, Romfile> = HashMap::new();
let roms = find_roms_with_romfile_by_system_id(&mut connection, system.id).await;
for rom in &roms {
let romfile = find_romfile_by_id(&mut connection, rom.romfile_id.unwrap()).await;
romfiles_by_id.insert(romfile.id, romfile);
}
roms_by_game_id.insert(roms[0].game_id, roms);
let destination_directory = tmp_directory.join("destination");
create_directory(&progress_bar, &destination_directory, true)
.await
.unwrap();
to_iso(
&mut connection,
&progress_bar,
&destination_directory,
roms_by_game_id,
romfiles_by_id,
)
.await
.unwrap();
assert!(
destination_directory
.join("Test Game (USA, Europe) (CUE BIN).iso")
.is_file()
);
}