lib.rs 1.7 KB

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