lib.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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)).join().unwrap();
  35. std::mem::forget(sdk.dispatcher());
  36. Self { inner: sdk }
  37. }
  38. pub async fn sign_up(&self) -> SignUpContext {
  39. async_sign_up(self.inner.dispatcher()).await
  40. }
  41. pub async fn init_user(&self) -> UserProfilePB {
  42. let context = async_sign_up(self.inner.dispatcher()).await;
  43. init_user_setting(self.inner.dispatcher()).await;
  44. context.user_profile
  45. }
  46. pub fn document_version(&self) -> DocumentVersionPB {
  47. self.inner.config.document.version.clone()
  48. }
  49. }