2023-05-17 01:49:39 +00:00
|
|
|
use nanoid::nanoid;
|
2023-05-23 15:55:21 +00:00
|
|
|
use parking_lot::RwLock;
|
2023-05-21 03:13:22 +00:00
|
|
|
use std::env::temp_dir;
|
2023-05-23 15:55:21 +00:00
|
|
|
use std::sync::Arc;
|
2022-10-20 03:35:11 +00:00
|
|
|
|
2023-02-02 15:02:49 +00:00
|
|
|
use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
|
2023-05-23 15:55:21 +00:00
|
|
|
use flowy_user::entities::{AuthTypePB, UserProfilePB};
|
2023-05-17 01:49:39 +00:00
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
use crate::user_event::{async_sign_up, init_user_setting, SignUpContext};
|
2023-05-17 01:49:39 +00:00
|
|
|
pub mod event_builder;
|
2023-05-23 15:55:21 +00:00
|
|
|
pub mod folder_event;
|
|
|
|
pub mod user_event;
|
2021-07-06 06:14:47 +00:00
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
#[derive(Clone)]
|
2023-05-23 15:55:21 +00:00
|
|
|
pub struct FlowyCoreTest {
|
|
|
|
auth_type: Arc<RwLock<AuthTypePB>>,
|
|
|
|
inner: AppFlowyCore,
|
2022-01-07 09:37:11 +00:00
|
|
|
}
|
2021-12-08 09:33:22 +00:00
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
impl Default for FlowyCoreTest {
|
2023-02-13 01:29:49 +00:00
|
|
|
fn default() -> Self {
|
2023-05-23 15:55:21 +00:00
|
|
|
let temp_dir = temp_dir();
|
|
|
|
let config =
|
|
|
|
AppFlowyCoreConfig::new(temp_dir.to_str().unwrap(), nanoid!(6)).log_filter("info", vec![]);
|
|
|
|
let inner = std::thread::spawn(|| AppFlowyCore::new(config))
|
|
|
|
.join()
|
|
|
|
.unwrap();
|
|
|
|
let auth_type = Arc::new(RwLock::new(AuthTypePB::Local));
|
|
|
|
std::mem::forget(inner.dispatcher());
|
|
|
|
Self { inner, auth_type }
|
2023-02-13 01:29:49 +00:00
|
|
|
}
|
2022-01-07 09:37:11 +00:00
|
|
|
}
|
2021-12-08 09:33:22 +00:00
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
impl FlowyCoreTest {
|
2023-05-17 01:49:39 +00:00
|
|
|
pub fn new() -> Self {
|
2023-05-23 15:55:21 +00:00
|
|
|
Self::default()
|
2023-02-13 01:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn sign_up(&self) -> SignUpContext {
|
2023-05-23 15:55:21 +00:00
|
|
|
let auth_type = self.auth_type.read().clone();
|
|
|
|
async_sign_up(self.inner.dispatcher(), auth_type).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_auth_type(&self, auth_type: AuthTypePB) {
|
|
|
|
*self.auth_type.write() = auth_type;
|
2023-02-13 01:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn init_user(&self) -> UserProfilePB {
|
2023-05-23 15:55:21 +00:00
|
|
|
let auth_type = self.auth_type.read().clone();
|
|
|
|
let context = async_sign_up(self.inner.dispatcher(), auth_type).await;
|
2023-02-13 01:29:49 +00:00
|
|
|
init_user_setting(self.inner.dispatcher()).await;
|
|
|
|
context.user_profile
|
|
|
|
}
|
2021-07-06 06:14:47 +00:00
|
|
|
}
|
2023-05-23 15:55:21 +00:00
|
|
|
|
|
|
|
impl std::ops::Deref for FlowyCoreTest {
|
|
|
|
type Target = AppFlowyCore;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.inner
|
|
|
|
}
|
|
|
|
}
|