AppFlowy/frontend/rust-lib/flowy-test/src/lib.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

2021-12-08 09:33:22 +00:00
pub mod event_builder;
pub mod helper;
2021-07-16 15:18:12 +00:00
use crate::helper::*;
use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
2022-10-22 13:57:44 +00:00
use flowy_document::entities::DocumentVersionPB;
use flowy_net::get_client_server_configuration;
2022-07-19 06:40:56 +00:00
use flowy_user::entities::UserProfilePB;
2022-04-11 07:27:03 +00:00
use nanoid::nanoid;
2021-07-06 06:14:47 +00:00
pub mod prelude {
pub use crate::{event_builder::*, helper::*, *};
pub use lib_dispatch::prelude::*;
2021-07-06 06:14:47 +00:00
}
2021-09-04 07:12:53 +00:00
#[derive(Clone)]
2022-01-07 09:37:11 +00:00
pub struct FlowySDKTest {
pub inner: AppFlowyCore,
2022-01-07 09:37:11 +00:00
}
2021-12-08 09:33:22 +00:00
impl std::ops::Deref for FlowySDKTest {
type Target = AppFlowyCore;
2021-12-08 09:33:22 +00:00
fn deref(&self) -> &Self::Target {
&self.inner
}
2021-09-04 07:12:53 +00:00
}
2022-01-07 09:37:11 +00:00
impl std::default::Default for FlowySDKTest {
fn default() -> Self {
Self::new(DocumentVersionPB::V0)
}
2022-01-07 09:37:11 +00:00
}
2021-12-08 09:33:22 +00:00
2022-01-07 09:37:11 +00:00
impl FlowySDKTest {
pub fn new(document_version: DocumentVersionPB) -> Self {
let server_config = get_client_server_configuration().unwrap();
let config = AppFlowyCoreConfig::new(&root_dir(), nanoid!(6), server_config)
.with_document_version(document_version)
.log_filter("info", vec![]);
let sdk = std::thread::spawn(|| AppFlowyCore::new(config))
.join()
.unwrap();
std::mem::forget(sdk.dispatcher());
Self { inner: sdk }
}
pub async fn sign_up(&self) -> SignUpContext {
async_sign_up(self.inner.dispatcher()).await
}
pub async fn init_user(&self) -> UserProfilePB {
let context = async_sign_up(self.inner.dispatcher()).await;
init_user_setting(self.inner.dispatcher()).await;
context.user_profile
}
pub fn document_version(&self) -> DocumentVersionPB {
self.inner.config.document.version.clone()
}
2021-07-06 06:14:47 +00:00
}