fix(sonarr): Pass the series ID alongside all GetSeriesHistory events when publishing to the networking channel
This commit is contained in:
@@ -74,7 +74,7 @@ pub enum SonarrEvent {
|
||||
GetSeasonReleases((i64, i64)),
|
||||
GetSecurityConfig,
|
||||
GetSeriesDetails(i64),
|
||||
GetSeriesHistory(Option<i64>),
|
||||
GetSeriesHistory(i64),
|
||||
GetStatus,
|
||||
GetUpdates,
|
||||
GetTags,
|
||||
@@ -1783,12 +1783,8 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_sonarr_series_history(
|
||||
&mut self,
|
||||
series_id: Option<i64>,
|
||||
) -> Result<Vec<SonarrHistoryItem>> {
|
||||
let (id, series_id_param) = self.extract_series_id(series_id).await;
|
||||
info!("Fetching Sonarr series history for series with ID: {id}");
|
||||
async fn get_sonarr_series_history(&mut self, series_id: i64) -> Result<Vec<SonarrHistoryItem>> {
|
||||
info!("Fetching Sonarr series history for series with ID: {series_id}");
|
||||
let event = SonarrEvent::GetSeriesHistory(series_id);
|
||||
|
||||
let request_props = self
|
||||
@@ -1797,7 +1793,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
RequestMethod::Get,
|
||||
None::<()>,
|
||||
None,
|
||||
Some(series_id_param),
|
||||
Some(format!("seriesId={series_id}")),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ mod test {
|
||||
#[rstest]
|
||||
fn test_resource_series_history(
|
||||
#[values(
|
||||
SonarrEvent::GetSeriesHistory(None),
|
||||
SonarrEvent::GetSeriesHistory(0),
|
||||
SonarrEvent::GetSeasonHistory((0, 0))
|
||||
)]
|
||||
event: SonarrEvent,
|
||||
@@ -4040,7 +4040,7 @@ mod test {
|
||||
None,
|
||||
Some(history_json),
|
||||
None,
|
||||
SonarrEvent::GetSeriesHistory(None),
|
||||
SonarrEvent::GetSeriesHistory(1),
|
||||
None,
|
||||
Some("seriesId=1"),
|
||||
)
|
||||
@@ -4075,113 +4075,7 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
if let SonarrSerdeable::SonarrHistoryItems(history_items) = network
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(None))
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
async_server.assert_async().await;
|
||||
assert!(app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series_history
|
||||
.is_some());
|
||||
assert_eq!(
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.items,
|
||||
expected_history_items
|
||||
);
|
||||
assert!(
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.sort_asc
|
||||
);
|
||||
assert_eq!(history_items, response);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_get_sonarr_series_history_event_uses_provided_series_id() {
|
||||
let history_json = json!([{
|
||||
"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: Vec<SonarrHistoryItem> = 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::GetSeriesHistory(Some(2)),
|
||||
None,
|
||||
Some("seriesId=2"),
|
||||
)
|
||||
.await;
|
||||
app_arc.lock().await.data.sonarr_data.series_history = Some(StatefulTable {
|
||||
sort_asc: true,
|
||||
..StatefulTable::default()
|
||||
});
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.set_items(vec![series()]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
if let SonarrSerdeable::SonarrHistoryItems(history_items) = network
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(Some(2)))
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(1))
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
@@ -4268,7 +4162,7 @@ mod test {
|
||||
None,
|
||||
Some(history_json),
|
||||
None,
|
||||
SonarrEvent::GetSeriesHistory(None),
|
||||
SonarrEvent::GetSeriesHistory(1),
|
||||
None,
|
||||
Some("seriesId=1"),
|
||||
)
|
||||
@@ -4283,7 +4177,7 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
if let SonarrSerdeable::SonarrHistoryItems(history_items) = network
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(None))
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(1))
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
@@ -4356,7 +4250,7 @@ mod test {
|
||||
None,
|
||||
Some(history_json),
|
||||
None,
|
||||
SonarrEvent::GetSeriesHistory(None),
|
||||
SonarrEvent::GetSeriesHistory(1),
|
||||
None,
|
||||
Some("seriesId=1"),
|
||||
)
|
||||
@@ -4391,7 +4285,7 @@ mod test {
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
if let SonarrSerdeable::SonarrHistoryItems(history_items) = network
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(None))
|
||||
.handle_sonarr_event(SonarrEvent::GetSeriesHistory(1))
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user