2021-12-08 09:33:22 +00:00
|
|
|
pub mod event_builder;
|
|
|
|
pub mod helper;
|
2021-07-16 15:18:12 +00:00
|
|
|
|
2021-09-04 08:12:48 +00:00
|
|
|
use crate::helper::*;
|
2022-10-20 03:35:11 +00:00
|
|
|
|
2023-01-08 04:10:53 +00:00
|
|
|
use flowy_core::{FlowySDK, FlowySDKConfig};
|
2022-10-22 13:57:44 +00:00
|
|
|
use flowy_document::entities::DocumentVersionPB;
|
2022-10-20 03:35:11 +00:00
|
|
|
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 {
|
2021-12-08 09:33:22 +00:00
|
|
|
pub use crate::{event_builder::*, helper::*, *};
|
2021-11-19 06:38:11 +00:00
|
|
|
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: FlowySDK,
|
|
|
|
}
|
2021-12-08 09:33:22 +00:00
|
|
|
|
|
|
|
impl std::ops::Deref for FlowySDKTest {
|
|
|
|
type Target = FlowySDK;
|
|
|
|
|
2022-01-23 04:14:00 +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 {
|
2022-10-22 13:57:44 +00:00
|
|
|
Self::new(DocumentVersionPB::V0)
|
2021-12-08 09:33:22 +00:00
|
|
|
}
|
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 {
|
2022-10-22 13:57:44 +00:00
|
|
|
pub fn new(document_version: DocumentVersionPB) -> Self {
|
2022-10-20 03:35:11 +00:00
|
|
|
let server_config = get_client_server_configuration().unwrap();
|
2022-12-20 03:14:42 +00:00
|
|
|
let config = FlowySDKConfig::new(&root_dir(), nanoid!(6), server_config)
|
2022-10-22 13:57:44 +00:00
|
|
|
.with_document_version(document_version)
|
2023-01-17 08:27:17 +00:00
|
|
|
.log_filter("info", vec![]);
|
2022-01-24 08:27:40 +00:00
|
|
|
let sdk = std::thread::spawn(|| FlowySDK::new(config)).join().unwrap();
|
2022-01-07 09:37:11 +00:00
|
|
|
std::mem::forget(sdk.dispatcher());
|
2022-01-08 10:21:13 +00:00
|
|
|
Self { inner: sdk }
|
2021-09-28 07:29:29 +00:00
|
|
|
}
|
2021-09-27 15:23:23 +00:00
|
|
|
|
2021-09-28 07:29:29 +00:00
|
|
|
pub async fn sign_up(&self) -> SignUpContext {
|
2023-01-12 05:09:08 +00:00
|
|
|
async_sign_up(self.inner.dispatcher()).await
|
2021-09-04 07:12:53 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 06:40:56 +00:00
|
|
|
pub async fn init_user(&self) -> UserProfilePB {
|
2022-01-07 09:37:11 +00:00
|
|
|
let context = async_sign_up(self.inner.dispatcher()).await;
|
|
|
|
init_user_setting(self.inner.dispatcher()).await;
|
2021-09-28 07:29:29 +00:00
|
|
|
context.user_profile
|
|
|
|
}
|
2022-10-22 13:57:44 +00:00
|
|
|
|
|
|
|
pub fn document_version(&self) -> DocumentVersionPB {
|
|
|
|
self.inner.config.document.version.clone()
|
|
|
|
}
|
2021-07-06 06:14:47 +00:00
|
|
|
}
|