refactor tests

This commit is contained in:
appflowy
2021-12-08 17:33:22 +08:00
parent 4450d4410b
commit 7ac55f29db
30 changed files with 467 additions and 454 deletions

View File

@ -1,6 +1,6 @@
pub mod builder;
mod helper;
pub mod workspace;
pub mod editor;
pub mod event_builder;
pub mod helper;
use crate::helper::*;
use backend_service::configuration::{get_client_server_configuration, ClientServerConfiguration};
@ -9,40 +9,40 @@ use flowy_user::entities::UserProfile;
use lib_infra::uuid;
pub mod prelude {
pub use crate::{builder::*, helper::*, *};
pub use crate::{event_builder::*, helper::*, *};
pub use lib_dispatch::prelude::*;
}
pub type FlowyTestSDK = FlowySDK;
#[derive(Clone)]
pub struct FlowyTest {
pub sdk: FlowyTestSDK,
pub struct FlowySDKTest(pub FlowySDK);
impl std::ops::Deref for FlowySDKTest {
type Target = FlowySDK;
fn deref(&self) -> &Self::Target { &self.0 }
}
impl FlowyTest {
impl FlowySDKTest {
pub fn setup() -> Self {
let server_config = get_client_server_configuration().unwrap();
let test = Self::setup_with(server_config);
std::mem::forget(test.sdk.dispatcher());
test
}
pub async fn sign_up(&self) -> SignUpContext {
let context = async_sign_up(self.sdk.dispatcher()).await;
context
}
pub async fn init_user(&self) -> UserProfile {
let context = async_sign_up(self.sdk.dispatcher()).await;
context.user_profile
let sdk = Self::setup_with(server_config);
std::mem::forget(sdk.dispatcher());
sdk
}
pub fn setup_with(server_config: ClientServerConfiguration) -> Self {
let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid()).log_filter("debug");
let sdk = FlowySDK::new(config);
Self { sdk }
Self(sdk)
}
pub fn sdk(&self) -> FlowyTestSDK { self.sdk.clone() }
pub async fn sign_up(&self) -> SignUpContext {
let context = async_sign_up(self.0.dispatcher()).await;
context
}
pub async fn init_user(&self) -> UserProfile {
let context = async_sign_up(self.0.dispatcher()).await;
context.user_profile
}
}