use pinto::backlog::{BacklogItem, ItemId, Status};
use pinto::rank::Rank;
use pinto::service::{Board, BoardColumn};
pub(super) fn item(id: &str, title: &str) -> BacklogItem {
BacklogItem::new(
id.parse::<ItemId>().unwrap(),
title.to_string(),
Status::new("todo"),
Rank::between(None, None).expect("open bounds produce a rank"),
chrono::Utc::now(),
)
.unwrap()
}
pub(super) fn item_with_parent(id: &str, title: &str, parent: &str) -> BacklogItem {
let mut it = item(id, title);
it.parent = Some(parent.parse::<ItemId>().unwrap());
it
}
pub(super) fn item_with_deps(id: &str, title: &str, deps: &[&str]) -> BacklogItem {
let mut it = item(id, title);
it.depends_on = deps.iter().map(|d| d.parse::<ItemId>().unwrap()).collect();
it
}
pub(super) fn item_with_points_assignee(
id: &str,
title: &str,
points: Option<u32>,
assignee: Option<&str>,
) -> BacklogItem {
let mut it = item(id, title);
it.points = points;
it.assignee = assignee.map(str::to_string);
it
}
pub(super) fn completed_item(id: &str, title: &str) -> BacklogItem {
let mut it = item(id, title);
it.done_at = Some(chrono::Utc::now());
it
}
pub(super) fn board(columns: &[(&str, &[&str])]) -> Board {
Board {
columns: columns
.iter()
.map(|(name, ids)| BoardColumn {
status: Status::new(*name),
items: ids
.iter()
.map(|id| item(id, &format!("title {id}")))
.collect(),
})
.collect(),
orphaned: Vec::new(),
}
}
pub(super) fn board_of(columns: &[(&str, Vec<BacklogItem>)]) -> Board {
Board {
columns: columns
.iter()
.map(|(name, items)| BoardColumn {
status: Status::new(*name),
items: items.clone(),
})
.collect(),
orphaned: Vec::new(),
}
}