use super::{prepare, prompt};
use crate::reply::start::Prepared;
use serde_json::json;
fn staged(workspace: &str) -> Prepared {
let body = json!({"workspace": workspace, "goal": "",
"binding": null, "lineage": null, "origin": "world"});
Prepared {
workspace: workspace.to_owned(),
goal: String::new(),
body,
}
}
#[test]
fn staging_names_the_workspace_and_the_bare_rung() {
assert_eq!(
prepare("home".to_owned(), None),
json!({"op": "prepare", "workspace": "home", "payload": {"rung": "bare"}})
);
}
#[test]
fn the_fire_hands_the_body_back_whole_and_re_addressed() {
let fired = prompt(&staged("personal"), "home".to_owned(), "do it".to_owned());
assert_eq!(
fired,
json!({"op": "prompt", "goal": "do it", "seed": null,
"prepared": {"workspace": "home", "goal": "",
"binding": null, "lineage": null, "origin": "world"}})
);
}
#[test]
fn the_fire_is_addressed_where_the_seat_can_route_it() {
let fired = prompt(&staged("personal"), "home".to_owned(), "do it".to_owned());
assert_eq!(
crate::envelope::workspace(&fired),
Some("home".to_owned()),
"the envelope's workspace is the one the router reads"
);
}
#[test]
fn both_envelopes_wear_the_boundary_s_own_op() {
assert_eq!(prepare(String::new(), None)["op"], json!(super::PREPARE));
assert_eq!(
prompt(&staged("home"), String::new(), String::new())["op"],
json!(super::PROMPT)
);
}
#[test]
fn staging_with_a_work_target_names_the_path_rung_and_the_directory() {
assert_eq!(
prepare("home".to_owned(), Some("/work/repo".to_owned())),
json!({"op": "prepare", "workspace": "home",
"payload": {"rung": "path", "dir": "/work/repo"}})
);
}
#[test]
fn a_rung_with_a_prefill_fires_it_ahead_of_what_was_typed() {
assert_eq!(super::goal("", "do the thing"), "do the thing");
assert_eq!(super::goal(" \n ", "do the thing"), "do the thing");
assert_eq!(
super::goal("Working directory: /w\nDo all work there.", "do the thing"),
"Working directory: /w\nDo all work there.\n\ndo the thing"
);
}