style: Clean up all remaining unused test helper functions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
use indoc::formatdoc;
|
||||
use log::{debug, info, warn};
|
||||
use serde_json::{json, Value};
|
||||
@@ -2320,63 +2320,6 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
||||
let series_id = if let Some(id) = series_id {
|
||||
id
|
||||
} else {
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.current_selection()
|
||||
.id
|
||||
};
|
||||
(series_id, format!("seriesId={series_id}"))
|
||||
}
|
||||
|
||||
async fn extract_season_number(&mut self, season_number: Option<i64>) -> Result<(i64, String)> {
|
||||
if let Some(number) = season_number {
|
||||
Ok((number, format!("seasonNumber={number}")))
|
||||
} else if !self.app.lock().await.data.sonarr_data.seasons.is_empty() {
|
||||
let season_number = self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.seasons
|
||||
.current_selection()
|
||||
.season_number;
|
||||
Ok((season_number, format!("seasonNumber={season_number}")))
|
||||
} else {
|
||||
Err(anyhow!("No season number provided"))
|
||||
}
|
||||
}
|
||||
|
||||
async fn extract_episode_id(&mut self, episode_id: Option<i64>) -> i64 {
|
||||
let episode_id = if let Some(id) = episode_id {
|
||||
id
|
||||
} else {
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.season_details_modal
|
||||
.as_ref()
|
||||
.expect("Season details have not been loaded")
|
||||
.episodes
|
||||
.current_selection()
|
||||
.id
|
||||
};
|
||||
|
||||
episode_id
|
||||
}
|
||||
}
|
||||
|
||||
fn get_episode_status(has_file: bool, downloads_vec: &[DownloadRecord], episode_id: i64) -> String {
|
||||
|
||||
@@ -5345,197 +5345,6 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.set_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let (id, series_id_param) = network.extract_series_id(None).await;
|
||||
|
||||
assert_eq!(id, 1);
|
||||
assert_str_eq!(series_id_param, "seriesId=1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id_uses_provided_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.series
|
||||
.set_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let (id, series_id_param) = network.extract_series_id(Some(2)).await;
|
||||
|
||||
assert_eq!(id, 2);
|
||||
assert_str_eq!(series_id_param, "seriesId=2");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_series_id_filtered_series() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut filtered_series = StatefulTable::default();
|
||||
filtered_series.set_filtered_items(vec![Series {
|
||||
id: 1,
|
||||
..Series::default()
|
||||
}]);
|
||||
app_arc.lock().await.data.sonarr_data.series = filtered_series;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let (id, series_id_param) = network.extract_series_id(None).await;
|
||||
|
||||
assert_eq!(id, 1);
|
||||
assert_str_eq!(series_id_param, "seriesId=1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_season_number() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.seasons
|
||||
.set_items(vec![Season {
|
||||
season_number: 1,
|
||||
..Season::default()
|
||||
}]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let (id, season_number_param) = network.extract_season_number(None).await.unwrap();
|
||||
|
||||
assert_eq!(id, 1);
|
||||
assert_str_eq!(season_number_param, "seasonNumber=1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_season_number_uses_provided_season_number() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.seasons
|
||||
.set_items(vec![Season {
|
||||
season_number: 1,
|
||||
..Season::default()
|
||||
}]);
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
let (id, season_number_param) = network.extract_season_number(Some(2)).await.unwrap();
|
||||
|
||||
assert_eq!(id, 2);
|
||||
assert_str_eq!(season_number_param, "seasonNumber=2");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_season_number_filtered_seasons() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut filtered_seasons = StatefulTable::default();
|
||||
filtered_seasons.set_items(vec![Season::default()]);
|
||||
filtered_seasons.set_filtered_items(vec![Season {
|
||||
season_number: 1,
|
||||
..Season::default()
|
||||
}]);
|
||||
app_arc.lock().await.data.sonarr_data.seasons = filtered_seasons;
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let (id, season_number_param) = network.extract_season_number(None).await.unwrap();
|
||||
|
||||
assert_eq!(id, 1);
|
||||
assert_str_eq!(season_number_param, "seasonNumber=1");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_season_number_empty_seasons_table() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
let season_number = network.extract_season_number(None).await;
|
||||
|
||||
assert!(season_number.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_episode_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut season_details_modal = SeasonDetailsModal::default();
|
||||
season_details_modal.episodes.set_items(vec![Episode {
|
||||
id: 1,
|
||||
..Episode::default()
|
||||
}]);
|
||||
app_arc.lock().await.data.sonarr_data.season_details_modal = Some(season_details_modal);
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.push_navigation_stack(ActiveSonarrBlock::EpisodeDetails.into());
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let id = network.extract_episode_id(None).await;
|
||||
|
||||
assert_eq!(id, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_episode_id_uses_provided_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut season_details_modal = SeasonDetailsModal::default();
|
||||
season_details_modal.episodes.set_items(vec![Episode {
|
||||
id: 1,
|
||||
..Episode::default()
|
||||
}]);
|
||||
app_arc.lock().await.data.sonarr_data.season_details_modal = Some(season_details_modal);
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.push_navigation_stack(ActiveSonarrBlock::EpisodeDetails.into());
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let id = network.extract_episode_id(Some(2)).await;
|
||||
|
||||
assert_eq!(id, 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_extract_episode_id_filtered_series() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
let mut filtered_episodes = StatefulTable::default();
|
||||
filtered_episodes.set_filtered_items(vec![Episode {
|
||||
id: 1,
|
||||
..Episode::default()
|
||||
}]);
|
||||
let season_details_modal = SeasonDetailsModal {
|
||||
episodes: filtered_episodes,
|
||||
..SeasonDetailsModal::default()
|
||||
};
|
||||
app_arc.lock().await.data.sonarr_data.season_details_modal = Some(season_details_modal);
|
||||
app_arc
|
||||
.lock()
|
||||
.await
|
||||
.push_navigation_stack(ActiveSonarrBlock::EpisodeDetails.into());
|
||||
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||
|
||||
let id = network.extract_episode_id(None).await;
|
||||
|
||||
assert_eq!(id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_episode_status_downloaded() {
|
||||
assert_str_eq!(get_episode_status(true, &[], 0), "Downloaded");
|
||||
|
||||
Reference in New Issue
Block a user