feat(network): Support for updating and scanning a series in Sonarr
This commit is contained in:
@@ -269,7 +269,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.map(RadarrSerdeable::from),
|
||||
RadarrEvent::UpdateAllMovies => self.update_all_movies().await.map(RadarrSerdeable::from),
|
||||
RadarrEvent::UpdateAndScan(movie_id) => self
|
||||
.update_and_scan(movie_id)
|
||||
.update_and_scan_movie(movie_id)
|
||||
.await
|
||||
.map(RadarrSerdeable::from),
|
||||
RadarrEvent::UpdateCollections => self.update_collections().await.map(RadarrSerdeable::from),
|
||||
@@ -2180,7 +2180,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update_and_scan(&mut self, movie_id: Option<i64>) -> Result<Value> {
|
||||
async fn update_and_scan_movie(&mut self, movie_id: Option<i64>) -> Result<Value> {
|
||||
let (id, _) = self.extract_movie_id(movie_id).await;
|
||||
let event = RadarrEvent::UpdateAndScan(None);
|
||||
info!("Updating and scanning movie with ID: {id}");
|
||||
|
||||
@@ -1219,7 +1219,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_update_and_scan_event() {
|
||||
async fn test_handle_update_and_scan_movie_event() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
@@ -1251,7 +1251,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_update_and_scan_event_uses_provied_movie_id() {
|
||||
async fn test_handle_update_and_scan_movie_event_uses_provied_movie_id() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
|
||||
@@ -77,6 +77,7 @@ pub enum SonarrEvent {
|
||||
TriggerAutomaticSeasonSearch(Option<(i64, i64)>),
|
||||
TriggerAutomaticSeriesSearch(Option<i64>),
|
||||
UpdateAllSeries,
|
||||
UpdateAndScanSeries(Option<i64>),
|
||||
}
|
||||
|
||||
impl NetworkResource for SonarrEvent {
|
||||
@@ -100,7 +101,8 @@ impl NetworkResource for SonarrEvent {
|
||||
| SonarrEvent::TriggerAutomaticSeriesSearch(_)
|
||||
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
||||
| SonarrEvent::TriggerAutomaticEpisodeSearch(_)
|
||||
| SonarrEvent::UpdateAllSeries => "/command",
|
||||
| SonarrEvent::UpdateAllSeries
|
||||
| SonarrEvent::UpdateAndScanSeries(_) => "/command",
|
||||
SonarrEvent::GetRootFolders
|
||||
| SonarrEvent::DeleteRootFolder(_)
|
||||
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
||||
@@ -261,6 +263,10 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::UpdateAllSeries => self.update_all_series().await.map(SonarrSerdeable::from),
|
||||
SonarrEvent::UpdateAndScanSeries(series_id) => self
|
||||
.update_and_scan_series(series_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1543,6 +1549,25 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn update_and_scan_series(&mut self, series_id: Option<i64>) -> Result<Value> {
|
||||
let (id, _) = self.extract_series_id(series_id).await;
|
||||
let event = SonarrEvent::UpdateAndScanSeries(None);
|
||||
info!("Updating and scanning series with ID: {id}");
|
||||
let body = SonarrCommandBody {
|
||||
name: "RefreshSeries".to_owned(),
|
||||
series_id: Some(id),
|
||||
..SonarrCommandBody::default()
|
||||
};
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(event, RequestMethod::Post, Some(body), None, None)
|
||||
.await;
|
||||
|
||||
self
|
||||
.handle_request::<SonarrCommandBody, Value>(request_props, |_, _| ())
|
||||
.await
|
||||
}
|
||||
|
||||
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
||||
let series_id = if let Some(id) = series_id {
|
||||
id
|
||||
|
||||
@@ -169,7 +169,8 @@ mod test {
|
||||
SonarrEvent::TriggerAutomaticEpisodeSearch(None),
|
||||
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
||||
SonarrEvent::UpdateAllSeries
|
||||
SonarrEvent::UpdateAllSeries,
|
||||
SonarrEvent::UpdateAndScanSeries(None)
|
||||
)]
|
||||
event: SonarrEvent,
|
||||
) {
|
||||
@@ -4520,6 +4521,63 @@ mod test {
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_update_and_scan_series_event() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
"name": "RefreshSeries",
|
||||
"seriesId": 1,
|
||||
})),
|
||||
Some(json!({})),
|
||||
None,
|
||||
SonarrEvent::UpdateAndScanSeries(None),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.set_items(vec![series()]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_sonarr_event(SonarrEvent::UpdateAndScanSeries(None))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_update_and_scan_series_event_uses_provied_series_id() {
|
||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||
RequestMethod::Post,
|
||||
Some(json!({
|
||||
"name": "RefreshSeries",
|
||||
"seriesId": 1
|
||||
})),
|
||||
Some(json!({})),
|
||||
None,
|
||||
SonarrEvent::UpdateAndScanSeries(Some(1)),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
assert!(network
|
||||
.handle_sonarr_event(SonarrEvent::UpdateAndScanSeries(Some(1)))
|
||||
.await
|
||||
.is_ok());
|
||||
|
||||
async_server.assert_async().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
|
||||
Reference in New Issue
Block a user