lib.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pub mod event_builder;
  2. pub mod helper;
  3. use crate::helper::*;
  4. use backend_service::configuration::{get_client_server_configuration, ClientServerConfiguration};
  5. use flowy_sdk::{FlowySDK, FlowySDKConfig};
  6. use flowy_user::entities::UserProfile;
  7. use lib_infra::uuid_string;
  8. pub mod prelude {
  9. pub use crate::{event_builder::*, helper::*, *};
  10. pub use lib_dispatch::prelude::*;
  11. }
  12. #[derive(Clone)]
  13. pub struct FlowySDKTest {
  14. pub inner: FlowySDK,
  15. }
  16. impl std::ops::Deref for FlowySDKTest {
  17. type Target = FlowySDK;
  18. fn deref(&self) -> &Self::Target {
  19. &self.inner
  20. }
  21. }
  22. impl std::default::Default for FlowySDKTest {
  23. fn default() -> Self {
  24. let server_config = get_client_server_configuration().unwrap();
  25. let sdk = Self::new(server_config);
  26. std::mem::forget(sdk.dispatcher());
  27. sdk
  28. }
  29. }
  30. impl FlowySDKTest {
  31. pub fn new(server_config: ClientServerConfiguration) -> Self {
  32. let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid_string()).log_filter("trace");
  33. let sdk = std::thread::spawn(|| FlowySDK::new(config)).join().unwrap();
  34. std::mem::forget(sdk.dispatcher());
  35. Self { inner: sdk }
  36. }
  37. pub async fn sign_up(&self) -> SignUpContext {
  38. let context = async_sign_up(self.inner.dispatcher()).await;
  39. context
  40. }
  41. pub async fn init_user(&self) -> UserProfile {
  42. let context = async_sign_up(self.inner.dispatcher()).await;
  43. init_user_setting(self.inner.dispatcher()).await;
  44. context.user_profile
  45. }
  46. }