Added tests for radarr models and refactored get_movie_status to live inside the radarr_network module

This commit is contained in:
2023-08-08 10:50:05 -06:00
parent 4962f3d5c3
commit f38de0a6c3
3 changed files with 67 additions and 25 deletions
+47 -1
View File
@@ -321,10 +321,10 @@ impl Display for MinimumAvailability {
impl MinimumAvailability {
pub fn to_display_str(&self) -> &str {
match self {
MinimumAvailability::Tba => "TBA",
MinimumAvailability::Announced => "Announced",
MinimumAvailability::InCinemas => "In Cinemas",
MinimumAvailability::Released => "Released",
MinimumAvailability::Tba => "TBA",
}
}
}
@@ -357,3 +357,49 @@ impl Monitor {
}
}
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_str_eq;
use crate::models::radarr_models::{MinimumAvailability, Monitor};
#[test]
fn test_minimum_availability_display() {
assert_str_eq!(MinimumAvailability::Tba.to_string(), "tba");
assert_str_eq!(MinimumAvailability::Announced.to_string(), "announced");
assert_str_eq!(MinimumAvailability::InCinemas.to_string(), "inCinemas");
assert_str_eq!(MinimumAvailability::Released.to_string(), "released");
}
#[test]
fn test_minimum_availability_to_display_str() {
assert_str_eq!(MinimumAvailability::Tba.to_display_str(), "TBA");
assert_str_eq!(MinimumAvailability::Announced.to_display_str(), "Announced");
assert_str_eq!(
MinimumAvailability::InCinemas.to_display_str(),
"In Cinemas"
);
assert_str_eq!(MinimumAvailability::Released.to_display_str(), "Released");
}
#[test]
fn test_monitor_display() {
assert_str_eq!(Monitor::MovieOnly.to_string(), "movieOnly");
assert_str_eq!(
Monitor::MovieAndCollection.to_string(),
"movieAndCollection"
);
assert_str_eq!(Monitor::None.to_string(), "none");
}
#[test]
fn test_monitor_to_display_str() {
assert_str_eq!(Monitor::MovieOnly.to_display_str(), "Movie only");
assert_str_eq!(
Monitor::MovieAndCollection.to_display_str(),
"Movie and Collection"
);
assert_str_eq!(Monitor::None.to_display_str(), "None");
}
}
+20 -3
View File
@@ -3,16 +3,16 @@ use std::fmt::Debug;
use indoc::formatdoc;
use log::{debug, info};
use serde::Serialize;
use serde_json::Number;
use urlencoding::encode;
use crate::app::RadarrConfig;
use crate::models::radarr_models::{
AddMovieBody, AddMovieSearchResult, AddOptions, Collection, CommandBody, Credit, CreditType,
DiskSpace, DownloadsResponse, Movie, MovieCommandBody, MovieHistoryItem, QualityProfile, Release,
ReleaseDownloadBody, RootFolder, SystemStatus,
DiskSpace, DownloadRecord, DownloadsResponse, Movie, MovieCommandBody, MovieHistoryItem,
QualityProfile, Release, ReleaseDownloadBody, RootFolder, SystemStatus,
};
use crate::models::ScrollableText;
use crate::network::utils::get_movie_status;
use crate::network::{Network, NetworkEvent, RequestMethod, RequestProps};
use crate::utils::{convert_runtime, convert_to_gb};
@@ -846,3 +846,20 @@ impl<'a> Network<'a> {
}
}
}
fn get_movie_status(has_file: bool, downloads_vec: &[DownloadRecord], movie_id: Number) -> String {
if !has_file {
if let Some(download) = downloads_vec
.iter()
.find(|&download| download.id.as_u64().unwrap() == movie_id.as_u64().unwrap())
{
if download.status == "downloading" {
return "Downloading".to_owned();
}
}
return "Missing".to_owned();
}
"Downloaded".to_owned()
}
-21
View File
@@ -7,24 +7,3 @@ use crate::models::radarr_models::DownloadRecord;
pub async fn parse_response<T: DeserializeOwned>(response: Response) -> Result<T, reqwest::Error> {
response.json::<T>().await
}
pub fn get_movie_status(
has_file: bool,
downloads_vec: &[DownloadRecord],
movie_id: Number,
) -> String {
if !has_file {
if let Some(download) = downloads_vec
.iter()
.find(|&download| download.id.as_u64().unwrap() == movie_id.as_u64().unwrap())
{
if download.status == "downloading" {
return "Downloading".to_owned();
}
}
return "Missing".to_owned();
}
"Downloaded".to_owned()
}