fix(sonarr): Pass the episode ID alongside all GetEpisodeHistory events when publishing to the networking channel
This commit is contained in:
@@ -78,7 +78,9 @@ impl<'a> App<'a> {
|
|||||||
}
|
}
|
||||||
ActiveSonarrBlock::EpisodeHistory => {
|
ActiveSonarrBlock::EpisodeHistory => {
|
||||||
self
|
self
|
||||||
.dispatch_network_event(SonarrEvent::GetEpisodeHistory(None).into())
|
.dispatch_network_event(
|
||||||
|
SonarrEvent::GetEpisodeHistory(self.extract_episode_id().await).into(),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
ActiveSonarrBlock::ManualEpisodeSearch => {
|
ActiveSonarrBlock::ManualEpisodeSearch => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ mod tests {
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::sonarr_test_utils::utils::create_test_sonarr_data;
|
use crate::models::servarr_data::sonarr::sonarr_data::sonarr_test_utils::utils::create_test_sonarr_data;
|
||||||
|
use crate::models::sonarr_models::Episode;
|
||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::App,
|
||||||
models::{
|
models::{
|
||||||
@@ -215,6 +216,12 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_dispatch_by_episode_history_block() {
|
async fn test_dispatch_by_episode_history_block() {
|
||||||
let (mut app, mut sync_network_rx) = construct_app_unit();
|
let (mut app, mut sync_network_rx) = construct_app_unit();
|
||||||
|
let mut season_details_modal = SeasonDetailsModal::default();
|
||||||
|
season_details_modal.episodes.set_items(vec![Episode {
|
||||||
|
id: 1,
|
||||||
|
..Episode::default()
|
||||||
|
}]);
|
||||||
|
app.data.sonarr_data.season_details_modal = Some(season_details_modal);
|
||||||
|
|
||||||
app
|
app
|
||||||
.dispatch_by_sonarr_block(&ActiveSonarrBlock::EpisodeHistory)
|
.dispatch_by_sonarr_block(&ActiveSonarrBlock::EpisodeHistory)
|
||||||
@@ -223,7 +230,7 @@ mod tests {
|
|||||||
assert!(app.is_loading);
|
assert!(app.is_loading);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sync_network_rx.recv().await.unwrap(),
|
sync_network_rx.recv().await.unwrap(),
|
||||||
SonarrEvent::GetEpisodeHistory(None).into()
|
SonarrEvent::GetEpisodeHistory(1).into()
|
||||||
);
|
);
|
||||||
assert!(!app.data.sonarr_data.prompt_confirm);
|
assert!(!app.data.sonarr_data.prompt_confirm);
|
||||||
assert_eq!(app.tick_count, 0);
|
assert_eq!(app.tick_count, 0);
|
||||||
@@ -737,9 +744,14 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_extract_episode_id() {
|
async fn test_extract_episode_id() {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
app.data.sonarr_data = create_test_sonarr_data();
|
let mut season_details_modal = SeasonDetailsModal::default();
|
||||||
|
season_details_modal.episodes.set_items(vec![Episode {
|
||||||
|
id: 1,
|
||||||
|
..Episode::default()
|
||||||
|
}]);
|
||||||
|
app.data.sonarr_data.season_details_modal = Some(season_details_modal);
|
||||||
|
|
||||||
assert_eq!(app.extract_episode_id().await, 0);
|
assert_eq!(app.extract_episode_id().await, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
|
|||||||
SonarrListCommand::EpisodeHistory { episode_id } => {
|
SonarrListCommand::EpisodeHistory { episode_id } => {
|
||||||
let resp = self
|
let resp = self
|
||||||
.network
|
.network
|
||||||
.handle_network_event(SonarrEvent::GetEpisodeHistory(Some(episode_id)).into())
|
.handle_network_event(SonarrEvent::GetEpisodeHistory(episode_id).into())
|
||||||
.await?;
|
.await?;
|
||||||
serde_json::to_string_pretty(&resp)?
|
serde_json::to_string_pretty(&resp)?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ mod tests {
|
|||||||
mock_network
|
mock_network
|
||||||
.expect_handle_network_event()
|
.expect_handle_network_event()
|
||||||
.with(eq::<NetworkEvent>(
|
.with(eq::<NetworkEvent>(
|
||||||
SonarrEvent::GetEpisodeHistory(Some(expected_episode_id)).into(),
|
SonarrEvent::GetEpisodeHistory(expected_episode_id).into(),
|
||||||
))
|
))
|
||||||
.times(1)
|
.times(1)
|
||||||
.returning(|_| {
|
.returning(|_| {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ pub enum SonarrEvent {
|
|||||||
GetEpisodeDetails(i64),
|
GetEpisodeDetails(i64),
|
||||||
GetEpisodes(i64),
|
GetEpisodes(i64),
|
||||||
GetEpisodeFiles(i64),
|
GetEpisodeFiles(i64),
|
||||||
GetEpisodeHistory(Option<i64>),
|
GetEpisodeHistory(i64),
|
||||||
GetLanguageProfiles,
|
GetLanguageProfiles,
|
||||||
GetLogs(Option<u64>),
|
GetLogs(Option<u64>),
|
||||||
GetDiskSpace,
|
GetDiskSpace,
|
||||||
@@ -1238,15 +1238,12 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_sonarr_episode_history(
|
async fn get_sonarr_episode_history(&mut self, episode_id: i64) -> Result<SonarrHistoryWrapper> {
|
||||||
&mut self,
|
info!("Fetching Sonarr history for episode with ID: {episode_id}");
|
||||||
episode_id: Option<i64>,
|
|
||||||
) -> Result<SonarrHistoryWrapper> {
|
|
||||||
let id = self.extract_episode_id(episode_id).await;
|
|
||||||
info!("Fetching Sonarr history for episode with ID: {id}");
|
|
||||||
let event = SonarrEvent::GetEpisodeHistory(episode_id);
|
let event = SonarrEvent::GetEpisodeHistory(episode_id);
|
||||||
|
|
||||||
let params = format!("episodeId={id}&pageSize=1000&sortDirection=descending&sortKey=date",);
|
let params =
|
||||||
|
format!("episodeId={episode_id}&pageSize=1000&sortDirection=descending&sortKey=date");
|
||||||
let request_props = self
|
let request_props = self
|
||||||
.request_props_from(event, RequestMethod::Get, None::<()>, None, Some(params))
|
.request_props_from(event, RequestMethod::Get, None::<()>, None, Some(params))
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ mod test {
|
|||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn test_resource_history(
|
fn test_resource_history(
|
||||||
#[values(SonarrEvent::GetHistory(0), SonarrEvent::GetEpisodeHistory(None))] event: SonarrEvent,
|
#[values(SonarrEvent::GetHistory(0), SonarrEvent::GetEpisodeHistory(0))] event: SonarrEvent,
|
||||||
) {
|
) {
|
||||||
assert_str_eq!(event.resource(), "/history");
|
assert_str_eq!(event.resource(), "/history");
|
||||||
}
|
}
|
||||||
@@ -2783,7 +2783,7 @@ mod test {
|
|||||||
None,
|
None,
|
||||||
Some(history_json),
|
Some(history_json),
|
||||||
None,
|
None,
|
||||||
SonarrEvent::GetEpisodeHistory(None),
|
SonarrEvent::GetEpisodeHistory(1),
|
||||||
None,
|
None,
|
||||||
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
||||||
)
|
)
|
||||||
@@ -2825,137 +2825,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());
|
||||||
|
|
||||||
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
||||||
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(None))
|
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(1))
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
{
|
|
||||||
async_server.assert_async().await;
|
|
||||||
assert_eq!(
|
|
||||||
app_arc
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.data
|
|
||||||
.sonarr_data
|
|
||||||
.season_details_modal
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.episode_details_modal
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.episode_history
|
|
||||||
.items,
|
|
||||||
expected_history_items
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
app_arc
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.data
|
|
||||||
.sonarr_data
|
|
||||||
.season_details_modal
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.episode_details_modal
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.episode_history
|
|
||||||
.sort_asc
|
|
||||||
);
|
|
||||||
assert_eq!(history, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_handle_get_sonarr_episode_history_event_uses_provided_episode_id() {
|
|
||||||
let history_json = json!({"records": [{
|
|
||||||
"id": 123,
|
|
||||||
"sourceTitle": "z episode",
|
|
||||||
"episodeId": 1007,
|
|
||||||
"quality": { "quality": { "name": "Bluray-1080p" } },
|
|
||||||
"languages": [{ "id": 1, "name": "English" }],
|
|
||||||
"date": "2024-02-10T07:28:45Z",
|
|
||||||
"eventType": "grabbed",
|
|
||||||
"data": {
|
|
||||||
"droppedPath": "/nfs/nzbget/completed/series/Coolness/something.cool.mkv",
|
|
||||||
"importedPath": "/nfs/tv/Coolness/Season 1/Coolness - S01E01 - Something Cool Bluray-1080p.mkv"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 456,
|
|
||||||
"sourceTitle": "A Episode",
|
|
||||||
"episodeId": 2001,
|
|
||||||
"quality": { "quality": { "name": "Bluray-1080p" } },
|
|
||||||
"languages": [{ "id": 1, "name": "English" }],
|
|
||||||
"date": "2024-02-10T07:28:45Z",
|
|
||||||
"eventType": "grabbed",
|
|
||||||
"data": {
|
|
||||||
"droppedPath": "/nfs/nzbget/completed/series/Coolness/something.cool.mkv",
|
|
||||||
"importedPath": "/nfs/tv/Coolness/Season 1/Coolness - S01E01 - Something Cool Bluray-1080p.mkv"
|
|
||||||
}
|
|
||||||
}]});
|
|
||||||
let response: SonarrHistoryWrapper = serde_json::from_value(history_json.clone()).unwrap();
|
|
||||||
let expected_history_items = vec![
|
|
||||||
SonarrHistoryItem {
|
|
||||||
id: 123,
|
|
||||||
episode_id: 1007,
|
|
||||||
source_title: "z episode".into(),
|
|
||||||
..history_item()
|
|
||||||
},
|
|
||||||
SonarrHistoryItem {
|
|
||||||
id: 456,
|
|
||||||
episode_id: 2001,
|
|
||||||
source_title: "A Episode".into(),
|
|
||||||
..history_item()
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
|
||||||
RequestMethod::Get,
|
|
||||||
None,
|
|
||||||
Some(history_json),
|
|
||||||
None,
|
|
||||||
SonarrEvent::GetEpisodeHistory(Some(2)),
|
|
||||||
None,
|
|
||||||
Some("episodeId=2&pageSize=1000&sortDirection=descending&sortKey=date"),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
app_arc.lock().await.data.sonarr_data.season_details_modal =
|
|
||||||
Some(SeasonDetailsModal::default());
|
|
||||||
app_arc
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.data
|
|
||||||
.sonarr_data
|
|
||||||
.season_details_modal
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.episodes
|
|
||||||
.set_items(vec![episode()]);
|
|
||||||
app_arc
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.data
|
|
||||||
.sonarr_data
|
|
||||||
.season_details_modal
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.episode_details_modal = Some(EpisodeDetailsModal::default());
|
|
||||||
app_arc
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.data
|
|
||||||
.sonarr_data
|
|
||||||
.season_details_modal
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.episode_details_modal
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.episode_history
|
|
||||||
.sort_asc = true;
|
|
||||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
|
||||||
|
|
||||||
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
|
||||||
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(Some(2)))
|
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
@@ -3043,7 +2913,7 @@ mod test {
|
|||||||
None,
|
None,
|
||||||
Some(history_json),
|
Some(history_json),
|
||||||
None,
|
None,
|
||||||
SonarrEvent::GetEpisodeHistory(None),
|
SonarrEvent::GetEpisodeHistory(1),
|
||||||
None,
|
None,
|
||||||
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
||||||
)
|
)
|
||||||
@@ -3063,7 +2933,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());
|
||||||
|
|
||||||
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
||||||
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(None))
|
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(1))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
@@ -3151,7 +3021,7 @@ mod test {
|
|||||||
None,
|
None,
|
||||||
Some(history_json),
|
Some(history_json),
|
||||||
None,
|
None,
|
||||||
SonarrEvent::GetEpisodeHistory(Some(1)),
|
SonarrEvent::GetEpisodeHistory(1),
|
||||||
None,
|
None,
|
||||||
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
Some("episodeId=1&pageSize=1000&sortDirection=descending&sortKey=date"),
|
||||||
)
|
)
|
||||||
@@ -3159,7 +3029,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());
|
||||||
|
|
||||||
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
if let SonarrSerdeable::SonarrHistoryWrapper(history) = network
|
||||||
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(Some(1)))
|
.handle_sonarr_event(SonarrEvent::GetEpisodeHistory(1))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user