fix(radarr): Construct and pass edit collection parameters alongside the EditCollection event when publishing to the networking channel
This commit is contained in:
+47
-103
@@ -14,9 +14,7 @@ use crate::models::radarr_models::{
|
||||
RadarrTask, RadarrTaskName, SystemStatus,
|
||||
};
|
||||
use crate::models::servarr_data::modals::{EditIndexerModal, IndexerTestResultModalItem};
|
||||
use crate::models::servarr_data::radarr::modals::{
|
||||
EditCollectionModal, EditMovieModal, MovieDetailsModal,
|
||||
};
|
||||
use crate::models::servarr_data::radarr::modals::{EditMovieModal, MovieDetailsModal};
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::servarr_models::{
|
||||
AddRootFolderBody, CommandBody, DiskSpace, EditIndexerParams, HostConfig, Indexer, LogResponse,
|
||||
@@ -47,7 +45,7 @@ pub enum RadarrEvent {
|
||||
DeleteTag(i64),
|
||||
DownloadRelease(RadarrReleaseDownloadBody),
|
||||
EditAllIndexerSettings(IndexerSettings),
|
||||
EditCollection(Option<EditCollectionParams>),
|
||||
EditCollection(EditCollectionParams),
|
||||
EditIndexer(Option<EditIndexerParams>),
|
||||
EditMovie(Option<EditMovieParams>),
|
||||
GetBlocklist,
|
||||
@@ -462,11 +460,9 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
)
|
||||
.await;
|
||||
|
||||
let resp = self
|
||||
self
|
||||
.handle_request::<(), ()>(request_props, |_, _| ())
|
||||
.await;
|
||||
|
||||
resp
|
||||
.await
|
||||
}
|
||||
|
||||
async fn delete_radarr_root_folder(&mut self, root_folder_id: i64) -> Result<()> {
|
||||
@@ -517,27 +513,21 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.request_props_from(event, RequestMethod::Put, Some(params), None, None)
|
||||
.await;
|
||||
|
||||
let resp = self
|
||||
self
|
||||
.handle_request::<IndexerSettings, Value>(request_props, |_, _| {})
|
||||
.await;
|
||||
|
||||
resp
|
||||
.await
|
||||
}
|
||||
|
||||
async fn edit_collection(
|
||||
&mut self,
|
||||
edit_collection_params: Option<EditCollectionParams>,
|
||||
edit_collection_params: EditCollectionParams,
|
||||
) -> Result<()> {
|
||||
info!("Editing Radarr collection");
|
||||
let detail_event = RadarrEvent::GetCollections;
|
||||
let event = RadarrEvent::EditCollection(None);
|
||||
let event = RadarrEvent::EditCollection(edit_collection_params.clone());
|
||||
info!("Fetching collection details");
|
||||
let collection_id = edit_collection_params.collection_id;
|
||||
|
||||
let collection_id = if let Some(ref params) = edit_collection_params {
|
||||
params.collection_id
|
||||
} else {
|
||||
self.extract_collection_id().await
|
||||
};
|
||||
let request_props = self
|
||||
.request_props_from(
|
||||
detail_event,
|
||||
@@ -559,80 +549,46 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
info!("Constructing edit collection body");
|
||||
|
||||
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(|| {
|
||||
detailed_collection_body["monitored"]
|
||||
.as_bool()
|
||||
.expect("Unable to deserialize 'monitored' bool")
|
||||
});
|
||||
let minimum_availability = params
|
||||
.minimum_availability
|
||||
.unwrap_or_else(|| {
|
||||
serde_json::from_value(detailed_collection_body["minimumAvailability"].clone())
|
||||
.expect("Unable to deserialize 'minimumAvailability'")
|
||||
})
|
||||
.to_string();
|
||||
let quality_profile_id = params.quality_profile_id.unwrap_or_else(|| {
|
||||
detailed_collection_body["qualityProfileId"]
|
||||
.as_i64()
|
||||
.expect("Unable to deserialize 'qualityProfileId'")
|
||||
});
|
||||
let root_folder_path = params.root_folder_path.unwrap_or_else(|| {
|
||||
detailed_collection_body["rootFolderPath"]
|
||||
.as_str()
|
||||
.expect("Unable to deserialize 'rootFolderPath'")
|
||||
.to_owned()
|
||||
});
|
||||
let search_on_add = params.search_on_add.unwrap_or_else(|| {
|
||||
detailed_collection_body["searchOnAdd"]
|
||||
.as_bool()
|
||||
.expect("Unable to deserialize 'searchOnAdd'")
|
||||
});
|
||||
let (monitored, minimum_availability, quality_profile_id, root_folder_path, search_on_add) = {
|
||||
let monitored = edit_collection_params.monitored.unwrap_or_else(|| {
|
||||
detailed_collection_body["monitored"]
|
||||
.as_bool()
|
||||
.expect("Unable to deserialize 'monitored' bool")
|
||||
});
|
||||
let minimum_availability = edit_collection_params
|
||||
.minimum_availability
|
||||
.unwrap_or_else(|| {
|
||||
serde_json::from_value(detailed_collection_body["minimumAvailability"].clone())
|
||||
.expect("Unable to deserialize 'minimumAvailability'")
|
||||
})
|
||||
.to_string();
|
||||
let quality_profile_id = edit_collection_params.quality_profile_id.unwrap_or_else(|| {
|
||||
detailed_collection_body["qualityProfileId"]
|
||||
.as_i64()
|
||||
.expect("Unable to deserialize 'qualityProfileId'")
|
||||
});
|
||||
let root_folder_path = edit_collection_params.root_folder_path.unwrap_or_else(|| {
|
||||
detailed_collection_body["rootFolderPath"]
|
||||
.as_str()
|
||||
.expect("Unable to deserialize 'rootFolderPath'")
|
||||
.to_owned()
|
||||
});
|
||||
let search_on_add = edit_collection_params.search_on_add.unwrap_or_else(|| {
|
||||
detailed_collection_body["searchOnAdd"]
|
||||
.as_bool()
|
||||
.expect("Unable to deserialize 'searchOnAdd'")
|
||||
});
|
||||
|
||||
(
|
||||
monitored,
|
||||
minimum_availability,
|
||||
quality_profile_id,
|
||||
root_folder_path,
|
||||
search_on_add,
|
||||
)
|
||||
} else {
|
||||
let mut app = self.app.lock().await;
|
||||
let EditCollectionModal {
|
||||
path,
|
||||
search_on_add,
|
||||
minimum_availability_list,
|
||||
monitored,
|
||||
quality_profile_list,
|
||||
} = app.data.radarr_data.edit_collection_modal.as_ref().unwrap();
|
||||
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();
|
||||
(
|
||||
monitored,
|
||||
minimum_availability,
|
||||
quality_profile_id,
|
||||
root_folder_path,
|
||||
search_on_add,
|
||||
)
|
||||
};
|
||||
|
||||
let root_folder_path: String = path.text.clone();
|
||||
let monitored = monitored.unwrap_or_default();
|
||||
let search_on_add = search_on_add.unwrap_or_default();
|
||||
let minimum_availability = minimum_availability_list.current_selection().to_string();
|
||||
app.data.radarr_data.edit_collection_modal = None;
|
||||
|
||||
(
|
||||
monitored,
|
||||
minimum_availability,
|
||||
quality_profile_id,
|
||||
root_folder_path,
|
||||
search_on_add,
|
||||
)
|
||||
};
|
||||
|
||||
*detailed_collection_body.get_mut("monitored").unwrap() = json!(monitored);
|
||||
* detailed_collection_body.get_mut("monitored").unwrap() = json!(monitored);
|
||||
*detailed_collection_body
|
||||
.get_mut("minimumAvailability")
|
||||
.unwrap() = json!(minimum_availability);
|
||||
@@ -2069,18 +2025,6 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
};
|
||||
(movie_id, format!("movieId={movie_id}"))
|
||||
}
|
||||
|
||||
async fn extract_collection_id(&mut self) -> i64 {
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.id
|
||||
}
|
||||
}
|
||||
|
||||
fn get_movie_status(has_file: bool, downloads_vec: &[DownloadRecord], movie_id: i64) -> String {
|
||||
|
||||
@@ -15,8 +15,8 @@ mod test {
|
||||
|
||||
use crate::app::ServarrConfig;
|
||||
use crate::models::radarr_models::{
|
||||
AddMovieOptions, BlocklistItem, BlocklistItemMovie, CollectionMovie, IndexerSettings,
|
||||
MediaInfo, MinimumAvailability, MovieCollection, MovieFile, Rating, RatingsList
|
||||
AddMovieOptions, BlocklistItem, BlocklistItemMovie, CollectionMovie, EditCollectionParams,
|
||||
IndexerSettings, MediaInfo, MinimumAvailability, MovieCollection, MovieFile, Rating, RatingsList
|
||||
};
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::servarr_models::{
|
||||
@@ -130,7 +130,7 @@ mod test {
|
||||
|
||||
#[rstest]
|
||||
fn test_resource_collection(
|
||||
#[values(RadarrEvent::GetCollections, RadarrEvent::EditCollection(None))] event: RadarrEvent,
|
||||
#[values(RadarrEvent::GetCollections, RadarrEvent::EditCollection(EditCollectionParams::default()))] event: RadarrEvent,
|
||||
) {
|
||||
assert_str_eq!(event.resource(), "/collection");
|
||||
}
|
||||
@@ -3395,132 +3395,6 @@ mod test {
|
||||
*expected_body.get_mut("qualityProfileId").unwrap() = json!(1111);
|
||||
*expected_body.get_mut("rootFolderPath").unwrap() = json!("/nfs/Test Path");
|
||||
*expected_body.get_mut("searchOnAdd").unwrap() = json!(false);
|
||||
|
||||
let (async_details_server, app_arc, mut server) = mock_servarr_api(
|
||||
RequestMethod::Get,
|
||||
None,
|
||||
Some(detailed_collection_body),
|
||||
None,
|
||||
RadarrEvent::GetCollections,
|
||||
Some("/123"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let async_edit_server = server
|
||||
.mock(
|
||||
"PUT",
|
||||
format!(
|
||||
"/api/v3{}/123",
|
||||
RadarrEvent::EditCollection(None).resource()
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.with_status(202)
|
||||
.match_header("X-Api-Key", "test1234")
|
||||
.match_body(Matcher::Json(expected_body))
|
||||
.create_async()
|
||||
.await;
|
||||
{
|
||||
let mut app = app_arc.lock().await;
|
||||
let mut edit_collection_modal = EditCollectionModal {
|
||||
path: "/nfs/Test Path".into(),
|
||||
monitored: Some(false),
|
||||
search_on_add: Some(false),
|
||||
..EditCollectionModal::default()
|
||||
};
|
||||
edit_collection_modal
|
||||
.quality_profile_list
|
||||
.set_items(vec!["Any".to_owned(), "HD - 1080p".to_owned()]);
|
||||
edit_collection_modal
|
||||
.minimum_availability_list
|
||||
.set_items(Vec::from_iter(MinimumAvailability::iter()));
|
||||
app.data.radarr_data.edit_collection_modal = Some(edit_collection_modal);
|
||||
app.data.radarr_data.collections.set_items(vec![Collection {
|
||||
monitored: false,
|
||||
search_on_add: false,
|
||||
..collection()
|
||||
}]);
|
||||
app.data.radarr_data.quality_profile_map =
|
||||
BiMap::from_iter([(1111, "Any".to_owned()), (2222, "HD - 1080p".to_owned())]);
|
||||
}
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::EditCollection(None))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_details_server.assert_async().await;
|
||||
async_edit_server.assert_async().await;
|
||||
|
||||
let app = app_arc.lock().await;
|
||||
assert!(app.data.radarr_data.edit_collection_modal.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_edit_collection_event_uses_provided_parameters() {
|
||||
let detailed_collection_body = json!({
|
||||
"id": 123,
|
||||
"title": "Test Collection",
|
||||
"rootFolderPath": "/nfs/movies",
|
||||
"searchOnAdd": true,
|
||||
"monitored": true,
|
||||
"minimumAvailability": "released",
|
||||
"overview": "Collection blah blah blah",
|
||||
"qualityProfileId": 2222,
|
||||
"movies": [
|
||||
{
|
||||
"title": "Test",
|
||||
"overview": "Collection blah blah blah",
|
||||
"year": 2023,
|
||||
"runtime": 120,
|
||||
"tmdbId": 1234,
|
||||
"genres": ["cool", "family", "fun"],
|
||||
"ratings": {
|
||||
"imdb": {
|
||||
"value": 9.9
|
||||
},
|
||||
"tmdb": {
|
||||
"value": 9.9
|
||||
},
|
||||
"rottenTomatoes": {
|
||||
"value": 9.9
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
let mut expected_body = detailed_collection_body.clone();
|
||||
*expected_body.get_mut("monitored").unwrap() = json!(false);
|
||||
*expected_body.get_mut("minimumAvailability").unwrap() = json!("announced");
|
||||
*expected_body.get_mut("qualityProfileId").unwrap() = json!(1111);
|
||||
*expected_body.get_mut("rootFolderPath").unwrap() = json!("/nfs/Test Path");
|
||||
*expected_body.get_mut("searchOnAdd").unwrap() = json!(false);
|
||||
|
||||
let (async_details_server, app_arc, mut server) = mock_servarr_api(
|
||||
RequestMethod::Get,
|
||||
None,
|
||||
Some(detailed_collection_body),
|
||||
None,
|
||||
RadarrEvent::GetCollections,
|
||||
Some("/123"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let async_edit_server = server
|
||||
.mock(
|
||||
"PUT",
|
||||
format!(
|
||||
"/api/v3{}/123",
|
||||
RadarrEvent::EditCollection(None).resource()
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.with_status(202)
|
||||
.match_header("X-Api-Key", "test1234")
|
||||
.match_body(Matcher::Json(expected_body))
|
||||
.create_async()
|
||||
.await;
|
||||
let edit_collection_params = EditCollectionParams {
|
||||
collection_id: 123,
|
||||
monitored: Some(false),
|
||||
@@ -3529,10 +3403,35 @@ mod test {
|
||||
root_folder_path: Some("/nfs/Test Path".to_owned()),
|
||||
search_on_add: Some(false),
|
||||
};
|
||||
|
||||
let (async_details_server, app_arc, mut server) = mock_servarr_api(
|
||||
RequestMethod::Get,
|
||||
None,
|
||||
Some(detailed_collection_body),
|
||||
None,
|
||||
RadarrEvent::GetCollections,
|
||||
Some("/123"),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let async_edit_server = server
|
||||
.mock(
|
||||
"PUT",
|
||||
format!(
|
||||
"/api/v3{}/123",
|
||||
RadarrEvent::EditCollection(edit_collection_params.clone()).resource()
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.with_status(202)
|
||||
.match_header("X-Api-Key", "test1234")
|
||||
.match_body(Matcher::Json(expected_body))
|
||||
.create_async()
|
||||
.await;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::EditCollection(Some(edit_collection_params)))
|
||||
.handle_radarr_event(RadarrEvent::EditCollection(edit_collection_params))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
@@ -3541,7 +3440,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_edit_collection_event_uses_provided_parameters_defaults_to_previous_values_when_none(
|
||||
async fn test_handle_edit_collection_event_defaults_to_previous_values_when_no_params_are_provided(
|
||||
) {
|
||||
let detailed_collection_body = json!({
|
||||
"id": 123,
|
||||
@@ -3591,12 +3490,16 @@ mod test {
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let edit_collection_params = EditCollectionParams {
|
||||
collection_id: 123,
|
||||
..EditCollectionParams::default()
|
||||
};
|
||||
let async_edit_server = server
|
||||
.mock(
|
||||
"PUT",
|
||||
format!(
|
||||
"/api/v3{}/123",
|
||||
RadarrEvent::EditCollection(None).resource()
|
||||
RadarrEvent::EditCollection(edit_collection_params).resource()
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
@@ -3612,7 +3515,7 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_radarr_event(RadarrEvent::EditCollection(Some(edit_collection_params)))
|
||||
.handle_radarr_event(RadarrEvent::EditCollection(edit_collection_params))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
@@ -4526,38 +4429,6 @@ mod test {
|
||||
assert_str_eq!(movie_id_param, "movieId=1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_collection_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(vec![Collection {
|
||||
id: 1,
|
||||
..Collection::default()
|
||||
}]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert_eq!(network.extract_collection_id().await, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_collection_id_filtered_collection() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut filtered_collections = StatefulTable::default();
|
||||
filtered_collections.set_filtered_items(vec![Collection {
|
||||
id: 1,
|
||||
..Collection::default()
|
||||
}]);
|
||||
app_arc.lock().await.data.radarr_data.collections = filtered_collections;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert_eq!(network.extract_collection_id().await, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_movie_status_downloaded() {
|
||||
assert_str_eq!(get_movie_status(true, &[], 0), "Downloaded");
|
||||
|
||||
Reference in New Issue
Block a user