use crate::model::Clip;
pub(crate) const EXCLUDED_TASKS: [&str; 2] = ["infill", "fixed_infill"];
pub(crate) const EXCLUDED_TYPES: [&str; 1] = ["rendered_context_window"];
pub fn is_downloadable(clip: &Clip) -> bool {
clip.status == "complete"
&& !EXCLUDED_TYPES.contains(&clip.clip_type.as_str())
&& !EXCLUDED_TASKS.contains(&clip.task.as_str())
}
#[cfg(test)]
mod tests {
use super::*;
fn clip(status: &str, clip_type: &str, task: &str) -> Clip {
Clip {
id: "x".to_owned(),
status: status.to_owned(),
clip_type: clip_type.to_owned(),
task: task.to_owned(),
..Default::default()
}
}
#[test]
fn complete_track_is_downloadable() {
assert!(is_downloadable(&clip("complete", "gen", "")));
}
#[test]
fn streaming_clip_is_not_downloadable() {
assert!(!is_downloadable(&clip("streaming", "", "")));
}
#[test]
fn infill_tasks_are_not_downloadable() {
assert!(!is_downloadable(&clip("complete", "gen", "infill")));
assert!(!is_downloadable(&clip("complete", "gen", "fixed_infill")));
}
#[test]
fn context_window_artefact_is_not_downloadable() {
assert!(!is_downloadable(&clip(
"complete",
"rendered_context_window",
""
)));
}
#[test]
fn trashed_but_complete_clip_is_still_downloadable() {
let mut trashed = clip("complete", "gen", "");
trashed.is_trashed = true;
assert!(is_downloadable(&trashed));
}
}