#[cfg(test)]
mod utils;
#[cfg(test)]
mod worktype_tests {
use predicates::boolean::PredicateBooleanExt;
use tempdir::TempDir;
use crate::utils::treeflow_command::TreeflowCommand;
#[test]
fn add_work_types_and_then_remove_one() {
let config_dir = TempDir::new("config_dir").expect("Temp dir");
let current_dir = TempDir::new("current_dir").expect("Temp dir");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/user/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("bugfix", "bugfix/user/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/user/\nbugfix bugfix/user/\n");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_remove("bugfix")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/user/\n");
}
#[test]
fn list_multiple_work_types() {
let config_dir = TempDir::new("config_dir").expect("Temp dir");
let current_dir = TempDir::new("current_dir").expect("Temp dir");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/user/feature-name/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("release", "release/v1.2.3/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/user/feature-name/\nrelease release/v1.2.3/\n");
}
#[test]
fn remove_work_type_updates_list() {
let config_dir = TempDir::new("config_dir").expect("Temp dir");
let current_dir = TempDir::new("current_dir").expect("Temp dir");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("bugfix", "bugfix/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_remove("bugfix")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/\n");
}
#[test]
fn worktype_add_duplicate_name_fails() {
let config_dir = TempDir::new("config_dir").expect("Temp dir");
let current_dir = TempDir::new("current_dir").expect("Temp dir");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/user/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/different/")
.current_dir(current_dir.path())
.cmd()
.assert()
.failure()
.stderr(predicates::str::contains("already exists").or(predicates::str::contains("duplicate")));
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/user/\n");
}
#[test]
fn worktype_add_duplicate_prefix_fails() {
let config_dir = TempDir::new("config_dir").expect("Temp dir");
let current_dir = TempDir::new("current_dir").expect("Temp dir");
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("feature", "feature/user/")
.current_dir(current_dir.path())
.cmd()
.assert()
.success();
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_add("bugfix", "feature/user/")
.current_dir(current_dir.path())
.cmd()
.assert()
.failure()
.stderr(predicates::str::contains("already exists").or(predicates::str::contains("duplicate")));
TreeflowCommand::new(config_dir.path().to_path_buf())
.worktype_list()
.cmd()
.assert()
.success()
.stdout("feature feature/user/\n");
}
}