fix: AddMovie Radarr event is now populated in the dispatch thread before being sent to the network thread
This commit is contained in:
@@ -7,15 +7,15 @@ use serde_json::{json, Value};
|
||||
use urlencoding::encode;
|
||||
|
||||
use crate::models::radarr_models::{
|
||||
AddMovieBody, AddMovieOptions, AddMovieSearchResult, BlocklistResponse, Collection,
|
||||
CollectionMovie, Credit, CreditType, DeleteMovieParams, DownloadRecord, DownloadsResponse,
|
||||
AddMovieBody, AddMovieSearchResult, BlocklistResponse, Collection,
|
||||
Credit, CreditType, DeleteMovieParams, DownloadRecord, DownloadsResponse,
|
||||
EditCollectionParams, EditMovieParams, IndexerSettings, IndexerTestResult, Movie,
|
||||
MovieCommandBody, MovieHistoryItem, RadarrRelease, RadarrReleaseDownloadBody, RadarrSerdeable,
|
||||
RadarrTask, RadarrTaskName, SystemStatus,
|
||||
};
|
||||
use crate::models::servarr_data::modals::{EditIndexerModal, IndexerTestResultModalItem};
|
||||
use crate::models::servarr_data::radarr::modals::{
|
||||
AddMovieModal, EditCollectionModal, EditMovieModal, MovieDetailsModal,
|
||||
EditCollectionModal, EditMovieModal, MovieDetailsModal,
|
||||
};
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::servarr_models::{
|
||||
@@ -35,7 +35,7 @@ mod radarr_network_tests;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
pub enum RadarrEvent {
|
||||
AddMovie(Option<AddMovieBody>),
|
||||
AddMovie(AddMovieBody),
|
||||
AddRootFolder(Option<String>),
|
||||
AddTag(String),
|
||||
ClearBlocklist,
|
||||
@@ -282,101 +282,18 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_movie(&mut self, add_movie_body_option: Option<AddMovieBody>) -> Result<Value> {
|
||||
async fn add_movie(&mut self, mut add_movie_body: AddMovieBody) -> Result<Value> {
|
||||
info!("Adding new movie to Radarr");
|
||||
let event = RadarrEvent::AddMovie(None);
|
||||
let body = if let Some(add_movie_body) = add_movie_body_option {
|
||||
add_movie_body
|
||||
} else {
|
||||
let tags = self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.add_movie_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
let tag_ids_vec = self.extract_and_add_radarr_tag_ids_vec(tags).await;
|
||||
let mut app = self.app.lock().await;
|
||||
let AddMovieModal {
|
||||
root_folder_list,
|
||||
monitor_list,
|
||||
minimum_availability_list,
|
||||
quality_profile_list,
|
||||
..
|
||||
} = app.data.radarr_data.add_movie_modal.as_ref().unwrap();
|
||||
let (tmdb_id, title) = if let Route::Radarr(active_radarr_block, _) = app.get_current_route()
|
||||
{
|
||||
if active_radarr_block == ActiveRadarrBlock::CollectionDetails {
|
||||
let CollectionMovie { tmdb_id, title, .. } = app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
} else {
|
||||
let AddMovieSearchResult { tmdb_id, title, .. } = app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
}
|
||||
} else {
|
||||
let AddMovieSearchResult { tmdb_id, title, .. } = app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
};
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *app
|
||||
.data
|
||||
.radarr_data
|
||||
.quality_profile_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == quality_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
let event = RadarrEvent::AddMovie(add_movie_body.clone());
|
||||
let tag_ids_vec = self
|
||||
.extract_and_add_radarr_tag_ids_vec(add_movie_body.tag_input_string.clone())
|
||||
.await;
|
||||
add_movie_body.tags = tag_ids_vec;
|
||||
|
||||
let path = root_folder_list.current_selection().path.clone();
|
||||
let monitor = monitor_list.current_selection().to_string();
|
||||
let minimum_availability = minimum_availability_list.current_selection().to_string();
|
||||
|
||||
app.data.radarr_data.add_movie_modal = None;
|
||||
|
||||
AddMovieBody {
|
||||
tmdb_id,
|
||||
title,
|
||||
root_folder_path: path,
|
||||
minimum_availability,
|
||||
monitored: true,
|
||||
quality_profile_id,
|
||||
tags: tag_ids_vec,
|
||||
add_options: AddMovieOptions {
|
||||
monitor,
|
||||
search_for_movie: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
debug!("Add movie body: {body:?}");
|
||||
debug!("Add movie body: {add_movie_body:?}");
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(event, RequestMethod::Post, Some(body), None, None)
|
||||
.request_props_from(event, RequestMethod::Post, Some(add_movie_body), None, None)
|
||||
.await;
|
||||
|
||||
self
|
||||
@@ -782,7 +699,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
|
||||
info!("Constructing edit collection body");
|
||||
|
||||
let mut detailed_collection_body: Value = serde_json::from_str(&response).unwrap();
|
||||
let mut detailed_collection_body: Value = serde_json::from_str(&response)?;
|
||||
let (monitored, minimum_availability, quality_profile_id, root_folder_path, search_on_add) =
|
||||
if let Some(params) = edit_collection_params {
|
||||
let monitored = params.monitored.unwrap_or_else(|| {
|
||||
@@ -926,7 +843,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
|
||||
info!("Constructing edit indexer body");
|
||||
|
||||
let mut detailed_indexer_body: Value = serde_json::from_str(&response).unwrap();
|
||||
let mut detailed_indexer_body: Value = serde_json::from_str(&response)?;
|
||||
|
||||
let (
|
||||
name,
|
||||
@@ -1171,7 +1088,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
|
||||
info!("Constructing edit movie body");
|
||||
|
||||
let mut detailed_movie_body: Value = serde_json::from_str(&response).unwrap();
|
||||
let mut detailed_movie_body: Value = serde_json::from_str(&response)?;
|
||||
let (monitored, minimum_availability, quality_profile_id, root_folder_path, tags) =
|
||||
if let Some(params) = edit_movie_params {
|
||||
let monitored = params.monitored.unwrap_or(
|
||||
|
||||
@@ -15,8 +15,8 @@ mod test {
|
||||
|
||||
use crate::app::ServarrConfig;
|
||||
use crate::models::radarr_models::{
|
||||
BlocklistItem, BlocklistItemMovie, CollectionMovie, MediaInfo, MinimumAvailability,
|
||||
MovieCollection, MovieFile, MovieMonitor, Rating, RatingsList,
|
||||
AddMovieOptions, BlocklistItem, BlocklistItemMovie, CollectionMovie, MediaInfo,
|
||||
MinimumAvailability, MovieCollection, MovieFile, Rating, RatingsList,
|
||||
};
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::servarr_models::{
|
||||
@@ -117,7 +117,7 @@ mod test {
|
||||
#[rstest]
|
||||
fn test_resource_movie(
|
||||
#[values(
|
||||
RadarrEvent::AddMovie(None),
|
||||
RadarrEvent::AddMovie(AddMovieBody::default()),
|
||||
RadarrEvent::EditMovie(None),
|
||||
RadarrEvent::GetMovies,
|
||||
RadarrEvent::GetMovieDetails(None),
|
||||
@@ -3396,9 +3396,8 @@ mod test {
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn test_handle_add_movie_event(#[values(true, false)] movie_details_context: bool) {
|
||||
async fn test_handle_add_movie_event() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
@@ -3416,104 +3415,14 @@ mod test {
|
||||
})),
|
||||
Some(json!({})),
|
||||
None,
|
||||
RadarrEvent::AddMovie(None),
|
||||
RadarrEvent::AddMovie(AddMovieBody::default()),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
{
|
||||
let mut app = app_arc.lock().await;
|
||||
let mut add_movie_modal = AddMovieModal {
|
||||
tags: "usenet, testing".into(),
|
||||
..AddMovieModal::default()
|
||||
};
|
||||
add_movie_modal.root_folder_list.set_items(vec![
|
||||
RootFolder {
|
||||
id: 1,
|
||||
path: "/nfs".to_owned(),
|
||||
accessible: true,
|
||||
free_space: 219902325555200,
|
||||
unmapped_folders: None,
|
||||
},
|
||||
RootFolder {
|
||||
id: 2,
|
||||
path: "/nfs2".to_owned(),
|
||||
accessible: true,
|
||||
free_space: 21990232555520,
|
||||
unmapped_folders: None,
|
||||
},
|
||||
]);
|
||||
add_movie_modal.root_folder_list.state.select(Some(1));
|
||||
add_movie_modal
|
||||
.quality_profile_list
|
||||
.set_items(vec!["HD - 1080p".to_owned()]);
|
||||
add_movie_modal
|
||||
.monitor_list
|
||||
.set_items(Vec::from_iter(MovieMonitor::iter()));
|
||||
add_movie_modal
|
||||
.minimum_availability_list
|
||||
.set_items(Vec::from_iter(MinimumAvailability::iter()));
|
||||
app.data.radarr_data.add_movie_modal = Some(add_movie_modal);
|
||||
app.data.radarr_data.quality_profile_map =
|
||||
BiMap::from_iter([(2222, "HD - 1080p".to_owned())]);
|
||||
app.data.radarr_data.tags_map =
|
||||
BiMap::from_iter([(1, "usenet".to_owned()), (2, "testing".to_owned())]);
|
||||
if movie_details_context {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.set_items(vec![collection_movie()]);
|
||||
app.push_navigation_stack(ActiveRadarrBlock::CollectionDetails.into());
|
||||
} else {
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(vec![add_movie_search_result()]);
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
}
|
||||
}
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::AddMovie(None))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
assert!(app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.add_movie_modal
|
||||
.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_add_movie_event_uses_provided_body() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
"tmdbId": 1234,
|
||||
"title": "Test",
|
||||
"rootFolderPath": "/nfs2",
|
||||
"minimumAvailability": "announced",
|
||||
"monitored": true,
|
||||
"qualityProfileId": 2222,
|
||||
"tags": [1, 2],
|
||||
"addOptions": {
|
||||
"monitor": "movieOnly",
|
||||
"searchForMovie": true
|
||||
}
|
||||
})),
|
||||
Some(json!({})),
|
||||
None,
|
||||
RadarrEvent::AddMovie(None),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let body = AddMovieBody {
|
||||
app_arc.lock().await.data.radarr_data.tags_map =
|
||||
BiMap::from_iter([(1, "usenet".to_owned()), (2, "testing".to_owned())]);
|
||||
let add_movie_body = AddMovieBody {
|
||||
tmdb_id: 1234,
|
||||
title: "Test".to_owned(),
|
||||
root_folder_path: "/nfs2".to_owned(),
|
||||
@@ -3521,6 +3430,7 @@ mod test {
|
||||
monitored: true,
|
||||
quality_profile_id: 2222,
|
||||
tags: vec![1, 2],
|
||||
tag_input_string: "usenet, testing".into(),
|
||||
add_options: AddMovieOptions {
|
||||
monitor: "movieOnly".to_owned(),
|
||||
search_for_movie: true,
|
||||
@@ -3530,119 +3440,11 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::AddMovie(Some(body)))
|
||||
.handle_radarr_event(RadarrEvent::AddMovie(add_movie_body))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
assert!(app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.add_movie_modal
|
||||
.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_add_movie_event_reuse_existing_table_if_search_already_performed() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
"tmdbId": 5678,
|
||||
"title": "Test",
|
||||
"rootFolderPath": "/nfs2",
|
||||
"minimumAvailability": "announced",
|
||||
"monitored": true,
|
||||
"qualityProfileId": 2222,
|
||||
"tags": [1, 2],
|
||||
"addOptions": {
|
||||
"monitor": "movieOnly",
|
||||
"searchForMovie": true
|
||||
}
|
||||
})),
|
||||
Some(json!({})),
|
||||
None,
|
||||
RadarrEvent::AddMovie(None),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
{
|
||||
let mut app = app_arc.lock().await;
|
||||
let mut add_movie_modal = AddMovieModal {
|
||||
tags: "usenet, testing".into(),
|
||||
..AddMovieModal::default()
|
||||
};
|
||||
add_movie_modal.root_folder_list.set_items(vec![
|
||||
RootFolder {
|
||||
id: 1,
|
||||
path: "/nfs".to_owned(),
|
||||
accessible: true,
|
||||
free_space: 219902325555200,
|
||||
unmapped_folders: None,
|
||||
},
|
||||
RootFolder {
|
||||
id: 2,
|
||||
path: "/nfs2".to_owned(),
|
||||
accessible: true,
|
||||
free_space: 21990232555520,
|
||||
unmapped_folders: None,
|
||||
},
|
||||
]);
|
||||
add_movie_modal.root_folder_list.state.select(Some(1));
|
||||
add_movie_modal
|
||||
.quality_profile_list
|
||||
.set_items(vec!["HD - 1080p".to_owned()]);
|
||||
add_movie_modal
|
||||
.monitor_list
|
||||
.set_items(Vec::from_iter(MovieMonitor::iter()));
|
||||
add_movie_modal
|
||||
.minimum_availability_list
|
||||
.set_items(Vec::from_iter(MinimumAvailability::iter()));
|
||||
app.data.radarr_data.add_movie_modal = Some(add_movie_modal);
|
||||
app.data.radarr_data.quality_profile_map =
|
||||
BiMap::from_iter([(2222, "HD - 1080p".to_owned())]);
|
||||
app.data.radarr_data.tags_map =
|
||||
BiMap::from_iter([(1, "usenet".to_owned()), (2, "testing".to_owned())]);
|
||||
let secondary_search_result = AddMovieSearchResult {
|
||||
tmdb_id: 5678,
|
||||
..add_movie_search_result()
|
||||
};
|
||||
let mut add_searched_movies = StatefulTable::default();
|
||||
add_searched_movies.set_items(vec![add_movie_search_result(), secondary_search_result]);
|
||||
add_searched_movies.scroll_to_bottom();
|
||||
app.data.radarr_data.add_searched_movies = Some(add_searched_movies);
|
||||
}
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::AddMovie(None))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
assert!(app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.add_movie_modal
|
||||
.is_none());
|
||||
assert_eq!(
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.tmdb_id,
|
||||
5678
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user