use endr::{Remote, MemoryStorageBackend}; use futures::StreamExt; use jmbl::{Input, Value}; use litl::Val; use mofo::Mofo; use tlpt::{JMBLContent, Tlpt}; use tracing::trace; #[tokio::test] async fn can_create_doc_with_new_account_and_then_re_access_it_elsewhere() { // traceful::init_test_trace(); let background = Mofo::new(); background .clone() .run_until(async { let (tlpt1_remotes_tx, tlpt1_remotes_rx) = futures::channel::mpsc::unbounded(); let (tlpt1, account_id, account_credential) = Tlpt::new_with_create_account( "tlpt1".to_string(), background.clone(), |mut view| view.create_plain_text("tlpt1 profile"), MemoryStorageBackend::new(), tlpt1_remotes_rx ) .await; let (team, _) = tlpt1.create_team(None).await; let doc = tlpt1 .create_document( &team, JMBLContent::create( |mut view| view.create_map([( "test", Value::str("Hello World"), )]) ), ) .await; assert_eq!( doc.content() .expect_jmbl() .current_root() .if_map() .unwrap() .val_to_litl(), Val::object([("test", Val::str("Hello World"))]) ); let (tlpt2_remotes_tx, tlpt2_remotes_rx) = futures::channel::mpsc::unbounded(); let (tlpt1_as_remote, tlpt2_as_remote) = Remote::new_connected_test_pair("tlpt1", "tlpt2"); tlpt1_remotes_tx.unbounded_send(tlpt2_as_remote).unwrap(); tlpt2_remotes_tx.unbounded_send(tlpt1_as_remote).unwrap(); let tlpt2 = Tlpt::new_with_account( "tlpt2".to_string(), background, account_id, account_credential, MemoryStorageBackend::new(), tlpt2_remotes_rx ) .await; let managed_doc2 = tlpt2.load_doc(doc.id()).await.content().expect_jmbl(); let doc2_updates = managed_doc2.updates("test2".to_string()); let (first_root, _) = doc2_updates .filter(|(root, _)| { let is_null = root.if_plain() == Ok(&Val::null()); trace!(root = ?root, is_null = is_null, "Got root"); futures::future::ready(!is_null) }) .next() .await .unwrap(); assert_eq!( first_root.if_map().unwrap().val_to_litl(), Val::object([("test", Val::str("Hello World"))]) ); }) .await; }