style: Clean up all remaining unused test helper functions
This commit is contained in:
@@ -5,10 +5,9 @@ pub(in crate::handlers::sonarr_handlers) mod utils {
|
||||
Indexer, IndexerField, Language, Quality, QualityWrapper, RootFolder,
|
||||
};
|
||||
use crate::models::sonarr_models::{
|
||||
AddSeriesSearchResult, AddSeriesSearchResultStatistics, BlocklistItem, DownloadRecord,
|
||||
DownloadStatus, DownloadsResponse, Episode, EpisodeFile, IndexerSettings, MediaInfo, Rating,
|
||||
Season, SeasonStatistics, Series, SeriesStatistics, SeriesStatus, SeriesType,
|
||||
SonarrHistoryData, SonarrHistoryEventType, SonarrHistoryItem, SonarrRelease,
|
||||
AddSeriesSearchResult, AddSeriesSearchResultStatistics, DownloadRecord, DownloadStatus,
|
||||
Episode, EpisodeFile, IndexerSettings, MediaInfo, Rating, Season, SeasonStatistics, Series,
|
||||
SeriesStatistics, SeriesStatus, SeriesType,
|
||||
};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use chrono::DateTime;
|
||||
@@ -187,22 +186,6 @@ pub(in crate::handlers::sonarr_handlers) mod utils {
|
||||
AddSeriesSearchResultStatistics { season_count: 3 }
|
||||
}
|
||||
|
||||
pub fn blocklist_item() -> BlocklistItem {
|
||||
BlocklistItem {
|
||||
id: 1,
|
||||
series_id: 1,
|
||||
series_title: None,
|
||||
episode_ids: vec![Number::from(1)],
|
||||
source_title: "Test Source Title".to_owned(),
|
||||
languages: vec![language()],
|
||||
quality: quality_wrapper(),
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-02-10T07:28:45Z").unwrap()),
|
||||
protocol: "usenet".to_owned(),
|
||||
indexer: "NZBgeek (Prowlarr)".to_owned(),
|
||||
message: "test message".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn download_record() -> DownloadRecord {
|
||||
DownloadRecord {
|
||||
title: "Test Download Title".to_owned(),
|
||||
@@ -219,12 +202,6 @@ pub(in crate::handlers::sonarr_handlers) mod utils {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn downloads_response() -> DownloadsResponse {
|
||||
DownloadsResponse {
|
||||
records: vec![download_record()],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn episode() -> Episode {
|
||||
Episode {
|
||||
id: 1,
|
||||
@@ -261,29 +238,6 @@ pub(in crate::handlers::sonarr_handlers) mod utils {
|
||||
vec!["cool".to_owned(), "family".to_owned(), "fun".to_owned()]
|
||||
}
|
||||
|
||||
pub fn history_data() -> SonarrHistoryData {
|
||||
SonarrHistoryData {
|
||||
dropped_path: Some("/nfs/nzbget/completed/series/Coolness/something.cool.mkv".to_owned()),
|
||||
imported_path: Some(
|
||||
"/nfs/tv/Coolness/Season 1/Coolness - S01E01 - Something Cool Bluray-1080p.mkv".to_owned(),
|
||||
),
|
||||
..SonarrHistoryData::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn history_item() -> SonarrHistoryItem {
|
||||
SonarrHistoryItem {
|
||||
id: 1,
|
||||
source_title: "Test source".into(),
|
||||
episode_id: 1,
|
||||
quality: quality_wrapper(),
|
||||
languages: vec![language()],
|
||||
date: DateTime::from(DateTime::parse_from_rfc3339("2024-02-10T07:28:45Z").unwrap()),
|
||||
event_type: SonarrHistoryEventType::Grabbed,
|
||||
data: history_data(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn indexer() -> Indexer {
|
||||
Indexer {
|
||||
enable_rss: true,
|
||||
@@ -428,32 +382,6 @@ pub(in crate::handlers::sonarr_handlers) mod utils {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rejections() -> Vec<String> {
|
||||
vec![
|
||||
"Unknown quality profile".to_owned(),
|
||||
"Release is already mapped".to_owned(),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn release() -> SonarrRelease {
|
||||
SonarrRelease {
|
||||
guid: "1234".to_owned(),
|
||||
protocol: "torrent".to_owned(),
|
||||
age: 1,
|
||||
title: HorizontallyScrollableText::from("Test Release"),
|
||||
indexer: "kickass torrents".to_owned(),
|
||||
indexer_id: 2,
|
||||
size: 1234,
|
||||
rejected: true,
|
||||
rejections: Some(rejections()),
|
||||
seeders: Some(Number::from(2)),
|
||||
leechers: Some(Number::from(1)),
|
||||
languages: Some(vec![language()]),
|
||||
quality: quality_wrapper(),
|
||||
full_season: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn root_folder() -> RootFolder {
|
||||
RootFolder {
|
||||
id: 1,
|
||||
|
||||
@@ -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