use jazz_telepathy::{TelepathyNode, UpdateSource}; #[test] fn should_be_able_to_create_and_write_to_a_new_log() { let mut node = TelepathyNode::create(); let log_access = node.local_state.logs.create_log(); node.local_state.logs.append(&log_access, &[0, 1, 2, 3]).unwrap(); assert_eq!(node.local_state.logs.current_data(&log_access.id()), Some([0u8, 1, 2, 3].as_slice())); } #[test] fn should_get_notified_about_log_appends() { let mut node = TelepathyNode::create(); let log_access = node.local_state.logs.create_log(); node.local_state.logs.append(&log_access, &[0, 1, 2, 3]).unwrap(); assert_eq!(node.local_state.logs.current_data(&log_access.id()), Some([0u8, 1, 2, 3].as_slice())); let (listener, mut receiver) = futures::channel::mpsc::unbounded(); node.local_state.logs.add_listener(log_access.id(), Box::new(listener)); node.local_state.logs.append(&log_access, &[4, 5, 6]).unwrap(); let (received_msg, received_src) = receiver.try_next().unwrap().unwrap(); assert_eq!(received_msg.append, vec![0, 1, 2, 3]); assert_eq!(received_src, UpdateSource::CurrentState); let (received_msg, received_src) = receiver.try_next().unwrap().unwrap(); assert_eq!(received_msg.append, vec![4,5,6]); assert_eq!(received_src, UpdateSource::CreatedLocally); }