lib.rs 1.6 KB

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