use crate::{
CounterProgram, counting,
pipes::{CounterAuthority, Counting, Reply, Request},
};
use app_core::{domain_primitives::Count, state_machines::Counter};
use pipecircuit::{Inline, InstalledPipe, Switchboard as _};
#[test]
fn routed_read_steps_the_core_and_routes_its_exact_reply() -> Result<(), &'static str> {
let mut board = CounterProgram;
let mut pipe = InstalledPipe::<Counting, _>::new(Inline::for_pipe::<Counting>(
CounterAuthority::new(Counter::new(Count::new(9))),
));
let request = match board.route(counting::From::Client(Request::Read)) {
counting::To::Counter(request) => request,
counting::To::Client(_) => return Err("request returned to client without authority"),
};
let reply = pipe.send(request);
match board.route(counting::From::Counter(reply)) {
counting::To::Client(reply) => assert_eq!(reply, Reply::Snapshot(Count::new(9))),
counting::To::Counter(_) => return Err("reply sent back to authority"),
}
Ok(())
}