lib.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 { &self.inner }
  19. }
  20. impl std::default::Default for FlowySDKTest {
  21. fn default() -> Self {
  22. let server_config = get_client_server_configuration().unwrap();
  23. let sdk = Self::new(server_config);
  24. std::mem::forget(sdk.dispatcher());
  25. sdk
  26. }
  27. }
  28. impl FlowySDKTest {
  29. pub fn new(server_config: ClientServerConfiguration) -> Self {
  30. let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid_string()).log_filter("trace");
  31. let sdk = FlowySDK::new(config);
  32. std::mem::forget(sdk.dispatcher());
  33. Self { inner: sdk }
  34. }
  35. pub async fn sign_up(&self) -> SignUpContext {
  36. let context = async_sign_up(self.inner.dispatcher()).await;
  37. context
  38. }
  39. pub async fn init_user(&self) -> UserProfile {
  40. let context = async_sign_up(self.inner.dispatcher()).await;
  41. init_user_setting(self.inner.dispatcher()).await;
  42. context.user_profile
  43. }
  44. }