fix(radarr): model the download status as a DownloadStatus enum
Radarr was the only tree still holding DownloadRecord.status as a bare String and comparing it against literals. It now carries its own DownloadStatus enum, shaped exactly like the Sonarr, Lidarr and Readarr copies, and is guarded with from_json_or_default so an unrecognised status degrades to Unknown instead of failing the whole queue fetch. The row-style decorator and get_movie_status compare against the enum variants. The status cell is never rendered in the Radarr tree, so no snapshot changes; the CLI JSON output is unchanged for every real value since the enum serializes to the same camelCase strings.
This commit is contained in:
8 files changed
+126
-29
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use crate::app::App;
|
||||
use crate::logos::RADARR_LOGO;
|
||||
use crate::models::Route;
|
||||
use crate::models::radarr_models::{DownloadRecord, Movie};
|
||||
use crate::models::radarr_models::{DownloadRecord, DownloadStatus, Movie};
|
||||
use crate::models::servarr_data::radarr::radarr_data::RadarrData;
|
||||
use crate::models::servarr_models::{DiskSpace, RootFolder};
|
||||
use crate::ui::DrawUi;
|
||||
@@ -230,11 +230,11 @@ fn decorate_with_row_style<'a>(
|
||||
.iter()
|
||||
.find(|&download| download.movie_id == movie.id)
|
||||
{
|
||||
if download.status == "downloading" {
|
||||
if download.status == DownloadStatus::Downloading {
|
||||
return row.downloading();
|
||||
}
|
||||
|
||||
if download.status == "completed" {
|
||||
if download.status == DownloadStatus::Completed {
|
||||
return row.awaiting_import();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::models::radarr_models::{DownloadRecord, Movie};
|
||||
use crate::models::radarr_models::{DownloadRecord, DownloadStatus, Movie};
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use rstest::rstest;
|
||||
@@ -50,8 +50,20 @@ mod tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(false, Some("downloading"), false, "", RowStyle::Downloading)]
|
||||
#[case(false, Some("completed"), false, "", RowStyle::AwaitingImport)]
|
||||
#[case(
|
||||
false,
|
||||
Some(DownloadStatus::Downloading),
|
||||
false,
|
||||
"",
|
||||
RowStyle::Downloading
|
||||
)]
|
||||
#[case(
|
||||
false,
|
||||
Some(DownloadStatus::Completed),
|
||||
false,
|
||||
"",
|
||||
RowStyle::AwaitingImport
|
||||
)]
|
||||
#[case(false, None, false, "", RowStyle::UnmonitoredMissing)]
|
||||
#[case(false, None, true, "", RowStyle::Unreleased)]
|
||||
#[case(false, None, true, "released", RowStyle::Missing)]
|
||||
@@ -59,7 +71,7 @@ mod tests {
|
||||
#[case(true, None, true, "", RowStyle::Downloaded)]
|
||||
fn test_decorate_with_row_style(
|
||||
#[case] has_file: bool,
|
||||
#[case] download_status: Option<&str>,
|
||||
#[case] download_status: Option<DownloadStatus>,
|
||||
#[case] is_monitored: bool,
|
||||
#[case] movie_status: String,
|
||||
#[case] expected_style: RowStyle,
|
||||
@@ -67,7 +79,7 @@ mod tests {
|
||||
let downloads_vec = if let Some(download_status) = download_status {
|
||||
vec![DownloadRecord {
|
||||
movie_id: 1,
|
||||
status: download_status.to_owned(),
|
||||
status: download_status,
|
||||
..DownloadRecord::default()
|
||||
}]
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user