use super::*;
use serde_json::json;
use tempfile::tempdir;
fn newborn_world(
root: &std::path::Path,
data: &std::path::Path,
bin: &std::path::Path,
) -> ConsumerCtx {
seed(data);
over(
root,
world_of(data, &[]),
data.to_path_buf(),
fake_lernie(bin),
)
}
fn prepare(ws: &str) -> serde_json::Value {
json!({"op": "prepare", "workspace": ws, "payload": {"rung": "bare"}})
}
#[test]
fn a_second_gesture_addresses_the_wall_the_first_founded() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let born = ctx.answer(&prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
crate::binding::workspace_path(data.path(), "home")
.join("repo.git")
.is_dir(),
"the raise founded the wall the reply named"
);
let again = ctx.answer(&prepare("home"));
assert_eq!(again["kind"], "prepared", "{again}");
let listed = ctx.answer(&json!({"op": "conversations", "workspace": "home"}));
assert_eq!(listed["ok"], true, "{listed}");
assert_eq!(listed["kind"], "conversations", "{listed}");
}
#[test]
fn the_windows_posted_receipt_addresses_the_wall_it_just_raised() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let window = crate::registry::window();
let born = ctx.answer_as(&window, &prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
crate::registry::registered(root.path(), &window).contains("home"),
"the create seated its creator (REMOTE §4)"
);
let listed = ctx.answer_as(
&window,
&json!({"op": "conversations", "workspace": "home"}),
);
assert_eq!(listed["kind"], "conversations", "{listed}");
let refusal = ctx.answer_as(
&client("stranger"),
&json!({"op": "conversations", "workspace": "home"}),
);
assert_eq!(refusal["error"], "unknown workspace \"home\"", "{refusal}");
}
#[test]
fn a_half_born_directory_is_resumed_not_wedged() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let debris = crate::binding::workspace_path(data.path(), "home");
std::fs::create_dir_all(&debris).unwrap();
let born = ctx.answer(&prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
debris.join("repo.git").is_dir(),
"the resume finished the dead birth"
);
}
#[test]
fn a_scoped_clients_prepare_never_joins_anothers_wall() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let window = crate::registry::window();
let born = ctx.answer_as(&window, &prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
let refusal = ctx.answer_as(&client("stranger"), &prepare("home"));
assert_eq!(refusal["error"], "unknown workspace \"home\"", "{refusal}");
}