lib.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. use lib_infra::uuid;
  9. pub mod prelude {
  10. pub use crate::{builder::*, helper::*, *};
  11. pub use lib_dispatch::prelude::*;
  12. }
  13. pub type FlowyTestSDK = FlowySDK;
  14. #[derive(Clone)]
  15. pub struct FlowyTest {
  16. pub sdk: FlowyTestSDK,
  17. }
  18. impl FlowyTest {
  19. pub fn setup() -> Self {
  20. let server_config = ServerConfig::default();
  21. let test = Self::setup_with(server_config);
  22. std::mem::forget(test.sdk.dispatch());
  23. test
  24. }
  25. pub async fn sign_up(&self) -> SignUpContext {
  26. let context = async_sign_up(self.sdk.dispatch()).await;
  27. context
  28. }
  29. pub async fn init_user(&self) -> UserProfile {
  30. let context = async_sign_up(self.sdk.dispatch()).await;
  31. context.user_profile
  32. }
  33. pub fn setup_with(server_config: ServerConfig) -> Self {
  34. let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid().to_string()).log_filter("debug");
  35. let sdk = FlowySDK::new(config);
  36. Self { sdk }
  37. }
  38. pub fn sdk(&self) -> FlowyTestSDK { self.sdk.clone() }
  39. }