lib.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. pub mod event_builder;
  2. pub mod helper;
  3. use crate::helper::*;
  4. use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
  5. use flowy_document::entities::DocumentVersionPB;
  6. use flowy_net::get_client_server_configuration;
  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: AppFlowyCore,
  16. }
  17. impl std::ops::Deref for FlowySDKTest {
  18. type Target = AppFlowyCore;
  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 = AppFlowyCoreConfig::new(&root_dir(), nanoid!(6), server_config)
  32. .with_document_version(document_version)
  33. .log_filter("info", vec![]);
  34. let sdk = std::thread::spawn(|| AppFlowyCore::new(config))
  35. .join()
  36. .unwrap();
  37. std::mem::forget(sdk.dispatcher());
  38. Self { inner: sdk }
  39. }
  40. pub async fn sign_up(&self) -> SignUpContext {
  41. async_sign_up(self.inner.dispatcher()).await
  42. }
  43. pub async fn init_user(&self) -> UserProfilePB {
  44. let context = async_sign_up(self.inner.dispatcher()).await;
  45. init_user_setting(self.inner.dispatcher()).await;
  46. context.user_profile
  47. }
  48. pub fn document_version(&self) -> DocumentVersionPB {
  49. self.inner.config.document.version.clone()
  50. }
  51. }