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

48 lines
1.2 KiB
Rust
Raw Normal View History

2021-07-17 00:24:17 +00:00
pub mod builder;
2021-07-16 15:18:12 +00:00
mod helper;
pub mod workspace;
2021-07-16 15:18:12 +00:00
use crate::helper::*;
use flowy_net::config::ServerConfig;
2021-09-05 05:50:23 +00:00
use flowy_sdk::{FlowySDK, FlowySDKConfig};
2021-09-04 08:53:58 +00:00
use flowy_user::entities::UserProfile;
2021-07-06 06:14:47 +00:00
pub mod prelude {
2021-09-04 07:12:53 +00:00
pub use crate::{builder::*, helper::*, *};
2021-07-08 13:23:44 +00:00
pub use flowy_dispatch::prelude::*;
2021-07-06 06:14:47 +00:00
}
2021-09-04 07:12:53 +00:00
pub type FlowyTestSDK = FlowySDK;
#[derive(Clone)]
pub struct FlowyTest {
pub sdk: FlowyTestSDK,
2021-09-04 07:12:53 +00:00
}
impl FlowyTest {
pub fn setup() -> Self {
let server_config = ServerConfig::default();
let test = Self::setup_with(server_config);
std::mem::forget(test.sdk.dispatch());
test
}
2021-09-27 15:23:23 +00:00
pub async fn sign_up(&self) -> SignUpContext {
let context = async_sign_up(self.sdk.dispatch()).await;
context
2021-09-04 07:12:53 +00:00
}
pub async fn init_user(&self) -> UserProfile {
let context = async_sign_up(self.sdk.dispatch()).await;
context.user_profile
}
2021-09-04 07:12:53 +00:00
pub fn setup_with(server_config: ServerConfig) -> Self {
let config = FlowySDKConfig::new(&root_dir(), server_config).log_filter("debug");
let sdk = FlowySDK::new(config);
Self { sdk }
}
2021-09-27 15:23:23 +00:00
pub fn sdk(&self) -> FlowyTestSDK { self.sdk.clone() }
2021-07-06 06:14:47 +00:00
}