2023-05-17 01:49:39 +00:00
|
|
|
use nanoid::nanoid;
|
2023-05-21 03:13:22 +00:00
|
|
|
use std::env::temp_dir;
|
2022-10-20 03:35:11 +00:00
|
|
|
|
2023-02-02 15:02:49 +00:00
|
|
|
use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
|
2023-05-17 01:49:39 +00:00
|
|
|
use flowy_net::http_server::self_host::configuration::get_client_server_configuration;
|
2022-07-19 06:40:56 +00:00
|
|
|
use flowy_user::entities::UserProfilePB;
|
2023-05-17 01:49:39 +00:00
|
|
|
|
|
|
|
use crate::helper::*;
|
|
|
|
|
|
|
|
pub mod event_builder;
|
|
|
|
pub mod helper;
|
2021-07-06 06:14:47 +00:00
|
|
|
|
|
|
|
pub mod prelude {
|
2023-02-13 01:29:49 +00:00
|
|
|
pub use lib_dispatch::prelude::*;
|
2023-05-17 01:49:39 +00:00
|
|
|
|
|
|
|
pub use crate::{event_builder::*, helper::*, *};
|
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 {
|
2023-02-13 01:29:49 +00:00
|
|
|
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 {
|
2023-02-13 01:29:49 +00:00
|
|
|
type Target = AppFlowyCore;
|
2021-12-08 09:33:22 +00:00
|
|
|
|
2023-02-13 01:29:49 +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 {
|
2023-02-13 01:29:49 +00:00
|
|
|
fn default() -> Self {
|
2023-05-17 01:49:39 +00:00
|
|
|
Self::new()
|
2023-02-13 01:29:49 +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 {
|
2023-05-17 01:49:39 +00:00
|
|
|
pub fn new() -> Self {
|
2023-02-13 01:29:49 +00:00
|
|
|
let server_config = get_client_server_configuration().unwrap();
|
2023-05-21 03:13:22 +00:00
|
|
|
let config = AppFlowyCoreConfig::new(temp_dir().to_str().unwrap(), nanoid!(6), server_config)
|
|
|
|
.log_filter("info", vec![]);
|
2023-02-13 01:29:49 +00:00
|
|
|
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
|
|
|
|
}
|
2021-07-06 06:14:47 +00:00
|
|
|
}
|