From e51b9d72b12346adda1a3d00b517987af41609d2 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 9 Sep 2026 16:55:28 -0600 Subject: [PATCH] test(radarr): pin which table build_add_movie_body reads from The handler fixtures for a collection movie and a searched movie both carried tmdb_id 1234 and the title Test, so the two branches of build_add_movie_body were value equivalent. The builder test also populated only the table its branch needed, so swapping the branches was caught by an unwrap panic on the empty table rather than by any assertion on the values. The searched movie fixture now has its own identity, and the builder test seeds both tables so the branch is chosen against real competing data. Swapping the branches now fails with a value diff naming the wrong tmdb_id and title. Only the handler copy of the fixture is changed. The network copy deliberately shares tmdb_id 1234 with the movie fixture, which is what drives the already in library marker in the add movie snapshots, so changing it there would have silently removed that marker. --- .../library/add_movie_handler_tests.rs | 63 ++++++++++++------- .../radarr_handler_test_utils.rs | 4 +- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs b/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs index 62e6daf5..2a49c611 100644 --- a/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs +++ b/src/handlers/radarr_handlers/library/add_movie_handler_tests.rs @@ -18,7 +18,7 @@ mod tests { use crate::handlers::radarr_handlers::radarr_handler_test_utils::utils::collection_movie; use crate::models::HorizontallyScrollableText; use crate::models::radarr_models::{ - AddMovieSearchResult, CollectionMovie, MinimumAvailability, MovieMonitor, + AddMovieBody, AddMovieSearchResult, CollectionMovie, MinimumAvailability, MovieMonitor, }; use crate::models::servarr_data::radarr::modals::AddMovieModal; use crate::models::servarr_data::radarr::radarr_data::{ADD_MOVIE_BLOCKS, ActiveRadarrBlock}; @@ -1076,7 +1076,7 @@ mod tests { assert_navigation_popped!(app, ActiveRadarrBlock::Movies.into()); assert_some_eq_x!( &app.data.radarr_data.prompt_confirm_action, - &RadarrEvent::AddMovie(add_movie_body()) + &RadarrEvent::AddMovie(expected_add_movie_body(movie_details_context)) ); assert_modal_absent!(app.data.radarr_data.add_movie_modal); } @@ -1517,7 +1517,7 @@ mod tests { assert_navigation_popped!(app, ActiveRadarrBlock::Movies.into()); assert_some_eq_x!( &app.data.radarr_data.prompt_confirm_action, - &RadarrEvent::AddMovie(add_movie_body()) + &RadarrEvent::AddMovie(expected_add_movie_body(movie_details_context)) ); assert_modal_absent!(app.data.radarr_data.add_movie_modal); } @@ -1609,29 +1609,29 @@ mod tests { app.data.radarr_data.add_movie_modal = Some(add_movie_modal); app.data.radarr_data.quality_profile_map = BiMap::from_iter([(1111, "Any".to_owned()), (2222, "HD - 1080p".to_owned())]); + app.data.radarr_data.collection_movies.set_items(vec![ + CollectionMovie { + tmdb_id: 5678, + title: HorizontallyScrollableText::from("Some Other Movie"), + ..CollectionMovie::default() + }, + collection_movie(), + ]); + app.data.radarr_data.collection_movies.select_index(Some(1)); + let mut add_searched_movies = StatefulTable::default(); + add_searched_movies.set_items(vec![ + AddMovieSearchResult { + tmdb_id: 5678, + title: HorizontallyScrollableText::from("Some Other Movie"), + ..AddMovieSearchResult::default() + }, + add_movie_search_result(), + ]); + add_searched_movies.select_index(Some(1)); + app.data.radarr_data.add_searched_movies = Some(add_searched_movies); let context = if movie_details_context { - app.data.radarr_data.collection_movies.set_items(vec![ - CollectionMovie { - tmdb_id: 5678, - title: HorizontallyScrollableText::from("Some Other Movie"), - ..CollectionMovie::default() - }, - collection_movie(), - ]); - app.data.radarr_data.collection_movies.select_index(Some(1)); Some(ActiveRadarrBlock::CollectionDetails) } else { - let mut add_searched_movies = StatefulTable::default(); - add_searched_movies.set_items(vec![ - AddMovieSearchResult { - tmdb_id: 5678, - title: HorizontallyScrollableText::from("Some Other Movie"), - ..AddMovieSearchResult::default() - }, - add_movie_search_result(), - ]); - add_searched_movies.select_index(Some(1)); - app.data.radarr_data.add_searched_movies = Some(add_searched_movies); None }; @@ -1643,7 +1643,10 @@ mod tests { ) .build_add_movie_body(); - assert_eq!(actual_add_movie_body, add_movie_body()); + assert_eq!( + actual_add_movie_body, + expected_add_movie_body(movie_details_context) + ); } #[test] @@ -1675,4 +1678,16 @@ mod tests { assert!(handler.is_ready()); } + + fn expected_add_movie_body(movie_details_context: bool) -> AddMovieBody { + if movie_details_context { + add_movie_body() + } else { + AddMovieBody { + tmdb_id: 4321, + title: "Test Search Result".to_owned(), + ..add_movie_body() + } + } + } } diff --git a/src/handlers/radarr_handlers/radarr_handler_test_utils.rs b/src/handlers/radarr_handlers/radarr_handler_test_utils.rs index 82241948..77a0382e 100644 --- a/src/handlers/radarr_handlers/radarr_handler_test_utils.rs +++ b/src/handlers/radarr_handlers/radarr_handler_test_utils.rs @@ -392,8 +392,8 @@ pub(in crate::handlers::radarr_handlers) mod utils { pub fn add_movie_search_result() -> AddMovieSearchResult { AddMovieSearchResult { - tmdb_id: 1234, - title: HorizontallyScrollableText::from("Test"), + tmdb_id: 4321, + title: HorizontallyScrollableText::from("Test Search Result"), original_language: language(), status: "released".to_owned(), overview: "New movie blah blah blah".to_owned(),