diff --git a/movie_collection_lib/src/make_queue.rs b/movie_collection_lib/src/make_queue.rs index 6b152e4..d433214 100644 --- a/movie_collection_lib/src/make_queue.rs +++ b/movie_collection_lib/src/make_queue.rs @@ -71,12 +71,15 @@ pub async fn make_queue_worker( } else if !del_files.is_empty() { for file in del_files { match file { - PathOrIndex::Index(idx) => mq.remove_from_queue_by_idx(*idx).await?, + PathOrIndex::Index(idx) => { + mq.remove_from_queue_by_idx(*idx).await?; + } PathOrIndex::Path(path) => { mq.remove_from_queue_by_path(&path.to_string_lossy()) .await?; } }; + mq.reorder_queue().await?; } } else if add_files.is_empty() { let movie_queue = mq.print_movie_queue(patterns, None, None, None).await?; @@ -101,6 +104,7 @@ pub async fn make_queue_worker( if let PathOrIndex::Path(path) = &add_files[0] { mq.insert_into_queue(max_idx + 1, &path.to_string_lossy()) .await?; + mq.reorder_queue().await?; } else { return Err(format_err!("No file specified")); } @@ -123,12 +127,14 @@ pub async fn make_queue_worker( } } } + mq.reorder_queue().await?; } else { for file in add_files { let max_idx = mq.get_max_queue_index().await?; if let PathOrIndex::Path(path) = file { mq.insert_into_queue(max_idx + 1, &path.to_string_lossy()) .await?; + mq.reorder_queue().await?; } else { return Err(format_err!("{} is not a path", file)); } diff --git a/movie_collection_lib/src/movie_collection.rs b/movie_collection_lib/src/movie_collection.rs index 66040d6..0243f4f 100644 --- a/movie_collection_lib/src/movie_collection.rs +++ b/movie_collection_lib/src/movie_collection.rs @@ -1035,7 +1035,10 @@ mod tests { use anyhow::Error; use stdout_channel::{MockStdout, StdoutChannel}; - use crate::{config::Config, movie_collection::MovieCollection, pgpool::PgPool}; + use crate::{ + config::Config, movie_collection::MovieCollection, movie_queue::MovieQueueDB, + pgpool::PgPool, + }; #[tokio::test] #[ignore] @@ -1055,4 +1058,16 @@ mod tests { assert_eq!(files.len(), 2); Ok(()) } + + #[tokio::test] + #[ignore] + async fn test_reorder_queue() -> Result<(), Error> { + let config = Config::with_config()?; + let pool = PgPool::new(&config.pgurl)?; + let mock_stdout = MockStdout::new(); + let stdout = StdoutChannel::with_mock_stdout(mock_stdout.clone(), mock_stdout.clone()); + let mc = MovieQueueDB::new(&config, &pool, &stdout); + mc.reorder_queue().await?; + Ok(()) + } }