helper.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use std::ops::Deref;
  2. use event_integration::event_builder::EventBuilder;
  3. use flowy_document2::entities::{OpenDocumentPayloadPB, RepeatedDocumentSnapshotPB};
  4. use flowy_document2::event_map::DocumentEvent::GetDocumentSnapshots;
  5. use flowy_folder2::entities::ViewPB;
  6. use crate::util::FlowySupabaseTest;
  7. pub struct FlowySupabaseDocumentTest {
  8. inner: FlowySupabaseTest,
  9. }
  10. impl FlowySupabaseDocumentTest {
  11. pub async fn new() -> Option<Self> {
  12. let inner = FlowySupabaseTest::new()?;
  13. let uuid = uuid::Uuid::new_v4().to_string();
  14. let _ = inner.supabase_sign_up_with_uuid(&uuid, None).await;
  15. Some(Self { inner })
  16. }
  17. pub async fn create_document(&self) -> ViewPB {
  18. let current_workspace = self.inner.get_current_workspace().await;
  19. self
  20. .inner
  21. .create_document(
  22. &current_workspace.workspace.id,
  23. "my document".to_string(),
  24. vec![],
  25. )
  26. .await
  27. }
  28. #[allow(dead_code)]
  29. pub async fn get_document_snapshots(&self, view_id: &str) -> RepeatedDocumentSnapshotPB {
  30. EventBuilder::new(self.inner.deref().clone())
  31. .event(GetDocumentSnapshots)
  32. .payload(OpenDocumentPayloadPB {
  33. document_id: view_id.to_string(),
  34. })
  35. .async_send()
  36. .await
  37. .parse::<RepeatedDocumentSnapshotPB>()
  38. }
  39. }
  40. impl Deref for FlowySupabaseDocumentTest {
  41. type Target = FlowySupabaseTest;
  42. fn deref(&self) -> &Self::Target {
  43. &self.inner
  44. }
  45. }