lib.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. pub mod builder;
  2. mod helper;
  3. pub mod workspace;
  4. use crate::helper::*;
  5. use flowy_net::config::ServerConfig;
  6. use flowy_sdk::{FlowySDK, FlowySDKConfig};
  7. use flowy_user::entities::UserProfile;
  8. pub mod prelude {
  9. pub use crate::{builder::*, helper::*, *};
  10. pub use flowy_dispatch::prelude::*;
  11. }
  12. pub type FlowyTestSDK = FlowySDK;
  13. #[derive(Clone)]
  14. pub struct FlowyTest {
  15. pub sdk: FlowyTestSDK,
  16. }
  17. impl FlowyTest {
  18. pub fn setup() -> Self {
  19. let server_config = ServerConfig::default();
  20. let test = Self::setup_with(server_config);
  21. std::mem::forget(test.sdk.dispatch());
  22. test
  23. }
  24. pub async fn sign_up(&self) -> SignUpContext {
  25. let context = async_sign_up(self.sdk.dispatch()).await;
  26. context
  27. }
  28. pub async fn init_user(&self) -> UserProfile {
  29. let context = async_sign_up(self.sdk.dispatch()).await;
  30. context.user_profile
  31. }
  32. pub fn setup_with(server_config: ServerConfig) -> Self {
  33. let config = FlowySDKConfig::new(&root_dir(), server_config).log_filter("debug");
  34. let sdk = FlowySDK::new(config);
  35. let _ = sdk.workspace.init().unwrap();
  36. Self { sdk }
  37. }
  38. pub fn sdk(&self) -> FlowyTestSDK { self.sdk.clone() }
  39. }