fix(sonarr): pass the series ID alongside all TriggerAutomaticSeriesSearch events when publishing to the networking channel
This commit is contained in:
@@ -83,7 +83,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrTriggerAutomaticSearchCommand>
|
|||||||
SonarrTriggerAutomaticSearchCommand::Series { series_id } => {
|
SonarrTriggerAutomaticSearchCommand::Series { series_id } => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
.handle_network_event(SonarrEvent::TriggerAutomaticSeriesSearch(Some(series_id)).into())
|
.handle_network_event(SonarrEvent::TriggerAutomaticSeriesSearch(series_id).into())
|
||||||
.await?;
|
.await?;
|
||||||
serde_json::to_string_pretty(&resp)?
|
serde_json::to_string_pretty(&resp)?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ mod tests {
|
|||||||
mock_network
|
mock_network
|
||||||
.expect_handle_network_event()
|
.expect_handle_network_event()
|
||||||
.with(eq::<NetworkEvent>(
|
.with(eq::<NetworkEvent>(
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(Some(expected_series_id)).into(),
|
SonarrEvent::TriggerAutomaticSeriesSearch(expected_series_id).into(),
|
||||||
))
|
))
|
||||||
.times(1)
|
.times(1)
|
||||||
.returning(|_| {
|
.returning(|_| {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ impl<'a, 'b> SeriesDetailsHandler<'a, 'b> {
|
|||||||
.expect("Series history is undefined"),
|
.expect("Series history is undefined"),
|
||||||
SonarrHistoryItem
|
SonarrHistoryItem
|
||||||
);
|
);
|
||||||
|
|
||||||
fn extract_series_id_season_number_tuple(&self) -> (i64, i64) {
|
fn extract_series_id_season_number_tuple(&self) -> (i64, i64) {
|
||||||
let series_id = self.app.data.sonarr_data.series.current_selection().id;
|
let series_id = self.app.data.sonarr_data.series.current_selection().id;
|
||||||
let season_number = self
|
let season_number = self
|
||||||
@@ -49,6 +50,10 @@ impl<'a, 'b> SeriesDetailsHandler<'a, 'b> {
|
|||||||
|
|
||||||
(series_id, season_number)
|
(series_id, season_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_series_id(&self) -> i64 {
|
||||||
|
self.app.data.sonarr_data.series.current_selection().id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler<'a, 'b> {
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler<'a, 'b> {
|
||||||
@@ -180,8 +185,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler
|
|||||||
}
|
}
|
||||||
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt => {
|
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt => {
|
||||||
if self.app.data.sonarr_data.prompt_confirm {
|
if self.app.data.sonarr_data.prompt_confirm {
|
||||||
self.app.data.sonarr_data.prompt_confirm_action =
|
self.app.data.sonarr_data.prompt_confirm_action = Some(
|
||||||
Some(SonarrEvent::TriggerAutomaticSeriesSearch(None));
|
SonarrEvent::TriggerAutomaticSeriesSearch(self.extract_series_id()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.app.pop_navigation_stack();
|
self.app.pop_navigation_stack();
|
||||||
@@ -312,8 +318,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for SeriesDetailsHandler
|
|||||||
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt => {
|
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt => {
|
||||||
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
if key == DEFAULT_KEYBINDINGS.confirm.key {
|
||||||
self.app.data.sonarr_data.prompt_confirm = true;
|
self.app.data.sonarr_data.prompt_confirm = true;
|
||||||
self.app.data.sonarr_data.prompt_confirm_action =
|
self.app.data.sonarr_data.prompt_confirm_action = Some(
|
||||||
Some(SonarrEvent::TriggerAutomaticSeriesSearch(None));
|
SonarrEvent::TriggerAutomaticSeriesSearch(self.extract_series_id()),
|
||||||
|
);
|
||||||
|
|
||||||
self.app.pop_navigation_stack();
|
self.app.pop_navigation_stack();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ mod tests {
|
|||||||
#[rstest]
|
#[rstest]
|
||||||
#[case(
|
#[case(
|
||||||
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt,
|
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt,
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None)
|
SonarrEvent::TriggerAutomaticSeriesSearch(1)
|
||||||
)]
|
)]
|
||||||
#[case(
|
#[case(
|
||||||
ActiveSonarrBlock::UpdateAndScanSeriesPrompt,
|
ActiveSonarrBlock::UpdateAndScanSeriesPrompt,
|
||||||
@@ -195,6 +195,7 @@ mod tests {
|
|||||||
) {
|
) {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
app.data.sonarr_data.prompt_confirm = true;
|
app.data.sonarr_data.prompt_confirm = true;
|
||||||
|
app.data.sonarr_data.series.set_items(vec![series()]);
|
||||||
app.push_navigation_stack(ActiveSonarrBlock::SeriesDetails.into());
|
app.push_navigation_stack(ActiveSonarrBlock::SeriesDetails.into());
|
||||||
app.push_navigation_stack(prompt_block.into());
|
app.push_navigation_stack(prompt_block.into());
|
||||||
|
|
||||||
@@ -567,7 +568,7 @@ mod tests {
|
|||||||
#[rstest]
|
#[rstest]
|
||||||
#[case(
|
#[case(
|
||||||
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt,
|
ActiveSonarrBlock::AutomaticallySearchSeriesPrompt,
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None)
|
SonarrEvent::TriggerAutomaticSeriesSearch(1)
|
||||||
)]
|
)]
|
||||||
#[case(
|
#[case(
|
||||||
ActiveSonarrBlock::UpdateAndScanSeriesPrompt,
|
ActiveSonarrBlock::UpdateAndScanSeriesPrompt,
|
||||||
@@ -581,6 +582,7 @@ mod tests {
|
|||||||
) {
|
) {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
app.data.sonarr_data.prompt_confirm = true;
|
app.data.sonarr_data.prompt_confirm = true;
|
||||||
|
app.data.sonarr_data.series.set_items(vec![series()]);
|
||||||
app.push_navigation_stack(active_sonarr_block.into());
|
app.push_navigation_stack(active_sonarr_block.into());
|
||||||
app.push_navigation_stack(prompt_block.into());
|
app.push_navigation_stack(prompt_block.into());
|
||||||
|
|
||||||
@@ -629,6 +631,22 @@ mod tests {
|
|||||||
assert_eq!(series_id_season_number_tuple, (1, 1));
|
assert_eq!(series_id_season_number_tuple, (1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extract_series_id() {
|
||||||
|
let mut app = App::default();
|
||||||
|
app.data.sonarr_data.series.set_items(vec![series()]);
|
||||||
|
|
||||||
|
let series_id = SeriesDetailsHandler::with(
|
||||||
|
DEFAULT_KEYBINDINGS.esc.key,
|
||||||
|
&mut app,
|
||||||
|
ActiveSonarrBlock::SeriesDetails,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.extract_series_id();
|
||||||
|
|
||||||
|
assert_eq!(series_id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_series_details_handler_is_not_ready_when_loading() {
|
fn test_series_details_handler_is_not_ready_when_loading() {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ pub enum SonarrEvent {
|
|||||||
ToggleEpisodeMonitoring(i64),
|
ToggleEpisodeMonitoring(i64),
|
||||||
TriggerAutomaticEpisodeSearch(i64),
|
TriggerAutomaticEpisodeSearch(i64),
|
||||||
TriggerAutomaticSeasonSearch((i64, i64)),
|
TriggerAutomaticSeasonSearch((i64, i64)),
|
||||||
TriggerAutomaticSeriesSearch(Option<i64>),
|
TriggerAutomaticSeriesSearch(i64),
|
||||||
UpdateAllSeries,
|
UpdateAllSeries,
|
||||||
UpdateAndScanSeries(Option<i64>),
|
UpdateAndScanSeries(Option<i64>),
|
||||||
UpdateDownloads,
|
UpdateDownloads,
|
||||||
@@ -2178,14 +2178,13 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn trigger_automatic_series_search(&mut self, series_id: Option<i64>) -> Result<Value> {
|
async fn trigger_automatic_series_search(&mut self, series_id: i64) -> Result<Value> {
|
||||||
let event = SonarrEvent::TriggerAutomaticSeriesSearch(series_id);
|
let event = SonarrEvent::TriggerAutomaticSeriesSearch(series_id);
|
||||||
let (id, _) = self.extract_series_id(series_id).await;
|
info!("Searching indexers for series with ID: {series_id}");
|
||||||
info!("Searching indexers for series with ID: {id}");
|
|
||||||
|
|
||||||
let body = SonarrCommandBody {
|
let body = SonarrCommandBody {
|
||||||
name: "SeriesSearch".to_owned(),
|
name: "SeriesSearch".to_owned(),
|
||||||
series_id: Some(id),
|
series_id: Some(series_id),
|
||||||
..SonarrCommandBody::default()
|
..SonarrCommandBody::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ mod test {
|
|||||||
SonarrEvent::StartTask(SonarrTaskName::default()),
|
SonarrEvent::StartTask(SonarrTaskName::default()),
|
||||||
SonarrEvent::TriggerAutomaticEpisodeSearch(0),
|
SonarrEvent::TriggerAutomaticEpisodeSearch(0),
|
||||||
SonarrEvent::TriggerAutomaticSeasonSearch((0, 0)),
|
SonarrEvent::TriggerAutomaticSeasonSearch((0, 0)),
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
SonarrEvent::TriggerAutomaticSeriesSearch(0),
|
||||||
SonarrEvent::UpdateAllSeries,
|
SonarrEvent::UpdateAllSeries,
|
||||||
SonarrEvent::UpdateAndScanSeries(None),
|
SonarrEvent::UpdateAndScanSeries(None),
|
||||||
SonarrEvent::UpdateDownloads
|
SonarrEvent::UpdateDownloads
|
||||||
@@ -5192,39 +5192,7 @@ mod test {
|
|||||||
})),
|
})),
|
||||||
Some(json!({})),
|
Some(json!({})),
|
||||||
None,
|
None,
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
SonarrEvent::TriggerAutomaticSeriesSearch(1),
|
||||||
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::TriggerAutomaticSeriesSearch(None))
|
|
||||||
.await
|
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
async_server.assert_async().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_handle_trigger_automatic_series_search_event_uses_provided_id() {
|
|
||||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
|
||||||
RequestMethod::Post,
|
|
||||||
Some(json!({
|
|
||||||
"name": "SeriesSearch",
|
|
||||||
"seriesId": 1
|
|
||||||
})),
|
|
||||||
Some(json!({})),
|
|
||||||
None,
|
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@@ -5232,7 +5200,7 @@ mod test {
|
|||||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||||
|
|
||||||
assert!(network
|
assert!(network
|
||||||
.handle_sonarr_event(SonarrEvent::TriggerAutomaticSeriesSearch(Some(1)))
|
.handle_sonarr_event(SonarrEvent::TriggerAutomaticSeriesSearch(1))
|
||||||
.await
|
.await
|
||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user