use super::Posted;
use serde_json::json;
#[test]
fn an_act_and_a_read_carry_the_same_envelope() {
let envelope = json!({"op": "nudge", "workspace": "home", "agent": "a"});
let act = Posted::act(envelope.clone());
let read = Posted::read(envelope.clone());
assert_eq!(act.envelope, envelope);
assert_eq!(read.envelope, envelope);
assert!(act.act);
assert!(!read.act);
}
#[test]
fn naming_no_workspace_does_not_make_a_gesture_a_read() {
let nameless: Vec<String> = crate::test_support::corpus::record()
.shapes
.into_iter()
.filter_map(|(name, signature)| {
let op = name.strip_prefix("request/")?;
let addressed = signature
.iter()
.any(|slot| slot.starts_with("/workspace") || slot.starts_with("/prepared"));
(!addressed).then(|| op.to_owned())
})
.collect();
for changes_the_world in ["create", "close", "complete", "deliver", "update", "retire"] {
assert!(
nameless.contains(&changes_the_world.to_owned()),
"{changes_the_world} is an act with no workspace slot, so the \
predicate cannot stand in for this field; nameless: {nameless:?}"
);
}
}
#[test]
fn a_gesture_names_the_channel_it_is_addressed_to_or_names_none() {
let bare = Posted::act(json!({"op": "config"}));
assert_eq!(bare.channel, None, "addressed to no channel in particular");
let addressed = bare.clone().down(crate::ui::Channel {
name: "b".to_owned(),
named_there: Some("b".to_owned()),
dials: None,
});
assert_eq!(
addressed.channel.map(|held| held.name),
Some("b".to_owned())
);
assert!(addressed.act, "and it is still the act it was");
assert_eq!(Posted::read(json!({"op": "help"})).channel, None);
}