test.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. use std::time::Duration;
  2. use flowy_database2::entities::{
  3. DatabaseSnapshotStatePB, DatabaseSyncStatePB, FieldChangesetPB, FieldType,
  4. };
  5. use crate::database::supabase_test::helper::{
  6. assert_database_collab_content, FlowySupabaseDatabaseTest,
  7. };
  8. use crate::util::receive_with_timeout;
  9. #[tokio::test]
  10. async fn cloud_test_supabase_initial_database_snapshot_test() {
  11. if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
  12. let (view, database) = test.create_database().await;
  13. let mut rx = test
  14. .notification_sender
  15. .subscribe::<DatabaseSnapshotStatePB>(&database.id);
  16. receive_with_timeout(&mut rx, Duration::from_secs(30))
  17. .await
  18. .unwrap();
  19. let expected = test.get_collab_json(&database.id).await;
  20. let snapshots = test.get_database_snapshots(&view.id).await;
  21. assert_eq!(snapshots.items.len(), 1);
  22. assert_database_collab_content(&database.id, &snapshots.items[0].data, expected);
  23. }
  24. }
  25. #[tokio::test]
  26. async fn cloud_test_supabase_edit_database_test() {
  27. if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
  28. let (view, database) = test.create_database().await;
  29. let existing_fields = test.get_all_database_fields(&view.id).await;
  30. for field in existing_fields.items {
  31. if !field.is_primary {
  32. test.delete_field(&view.id, &field.id).await;
  33. }
  34. }
  35. let field = test.create_field(&view.id, FieldType::Checklist).await;
  36. test
  37. .update_field(FieldChangesetPB {
  38. field_id: field.id.clone(),
  39. view_id: view.id.clone(),
  40. name: Some("hello world".to_string()),
  41. ..Default::default()
  42. })
  43. .await;
  44. // wait all updates are send to the remote
  45. let mut rx = test
  46. .notification_sender
  47. .subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
  48. receive_with_timeout(&mut rx, Duration::from_secs(30))
  49. .await
  50. .unwrap();
  51. assert_eq!(test.get_all_database_fields(&view.id).await.items.len(), 2);
  52. let expected = test.get_collab_json(&database.id).await;
  53. let update = test.get_collab_update(&database.id).await;
  54. assert_database_collab_content(&database.id, &update, expected);
  55. }
  56. }
  57. // #[tokio::test]
  58. // async fn cloud_test_supabase_login_sync_database_test() {
  59. // if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
  60. // let uuid = test.uuid.clone();
  61. // let (view, database) = test.create_database().await;
  62. // // wait all updates are send to the remote
  63. // let mut rx = test
  64. // .notification_sender
  65. // .subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
  66. // receive_with_timeout(&mut rx, Duration::from_secs(30))
  67. // .await
  68. // .unwrap();
  69. // let expected = test.get_collab_json(&database.id).await;
  70. // test.sign_out().await;
  71. // // Drop the test will cause the test resources to be dropped, which will
  72. // // delete the user data folder.
  73. // drop(test);
  74. //
  75. // let new_test = FlowySupabaseDatabaseTest::new_with_user(uuid)
  76. // .await
  77. // .unwrap();
  78. // // let actual = new_test.get_collab_json(&database.id).await;
  79. // // assert_json_eq!(actual, json!(""));
  80. //
  81. // new_test.open_database(&view.id).await;
  82. //
  83. // // wait all updates are synced from the remote
  84. // let mut rx = new_test
  85. // .notification_sender
  86. // .subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
  87. // receive_with_timeout(&mut rx, Duration::from_secs(30))
  88. // .await
  89. // .unwrap();
  90. //
  91. // // when the new sync is finished, the database should be the same as the old one
  92. // let actual = new_test.get_collab_json(&database.id).await;
  93. // assert_json_eq!(actual, expected);
  94. // }
  95. // }