Nathan.fooo edc7933c66
feat: support pg storage (#2935)
* refactor: using tokio-postgres

* chore: update

* chore: update env

* chore: update

* chore: upgrade supabase and add logout button

* refactor: update

* chore: update

* refactor: using message queue to handle the pg connection

* refactor: move test

* refactor: update sql

* chore: create pg database when user login

* chore: update scheme

* chore: generic user service

* chore: update

* chore: create statistics

* chore: create snapshot

* chore: add test

* chore: add database cloud service

* chore: add document cloud service

* chore: update interface

* test: add document test

* refactor: document interface

* chore: fix test

* chore: update

* chore: update test

* test: add test

* test: add test

* test: add test

* chore: update collab rev

* fix: flutter analyzer

* chore: update

* chore: update

* chore: update

* fix: tests

* chore: update

* chore: update collab rev

* ci: rust fmt

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2023-07-05 20:57:09 +08:00

106 lines
3.7 KiB
Rust

use std::time::Duration;
use flowy_database2::entities::{
DatabaseSnapshotStatePB, DatabaseSyncStatePB, FieldChangesetPB, FieldType,
};
use crate::database::supabase_test::helper::{
assert_database_collab_content, FlowySupabaseDatabaseTest,
};
use crate::util::receive_with_timeout;
#[tokio::test]
async fn cloud_test_supabase_initial_database_snapshot_test() {
if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
let (view, database) = test.create_database().await;
let mut rx = test
.notification_sender
.subscribe::<DatabaseSnapshotStatePB>(&database.id);
receive_with_timeout(&mut rx, Duration::from_secs(30))
.await
.unwrap();
let expected = test.get_collab_json(&database.id).await;
let snapshots = test.get_database_snapshots(&view.id).await;
assert_eq!(snapshots.items.len(), 1);
assert_database_collab_content(&database.id, &snapshots.items[0].data, expected);
}
}
#[tokio::test]
async fn cloud_test_supabase_edit_database_test() {
if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
let (view, database) = test.create_database().await;
let existing_fields = test.get_all_database_fields(&view.id).await;
for field in existing_fields.items {
if !field.is_primary {
test.delete_field(&view.id, &field.id).await;
}
}
let field = test.create_field(&view.id, FieldType::Checklist).await;
test
.update_field(FieldChangesetPB {
field_id: field.id.clone(),
view_id: view.id.clone(),
name: Some("hello world".to_string()),
..Default::default()
})
.await;
// wait all updates are send to the remote
let mut rx = test
.notification_sender
.subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
receive_with_timeout(&mut rx, Duration::from_secs(30))
.await
.unwrap();
assert_eq!(test.get_all_database_fields(&view.id).await.items.len(), 2);
let expected = test.get_collab_json(&database.id).await;
let update = test.get_collab_update(&database.id).await;
assert_database_collab_content(&database.id, &update, expected);
}
}
// #[tokio::test]
// async fn cloud_test_supabase_login_sync_database_test() {
// if let Some(test) = FlowySupabaseDatabaseTest::new_with_new_user().await {
// let uuid = test.uuid.clone();
// let (view, database) = test.create_database().await;
// // wait all updates are send to the remote
// let mut rx = test
// .notification_sender
// .subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
// receive_with_timeout(&mut rx, Duration::from_secs(30))
// .await
// .unwrap();
// let expected = test.get_collab_json(&database.id).await;
// test.sign_out().await;
// // Drop the test will cause the test resources to be dropped, which will
// // delete the user data folder.
// drop(test);
//
// let new_test = FlowySupabaseDatabaseTest::new_with_user(uuid)
// .await
// .unwrap();
// // let actual = new_test.get_collab_json(&database.id).await;
// // assert_json_eq!(actual, json!(""));
//
// new_test.open_database(&view.id).await;
//
// // wait all updates are synced from the remote
// let mut rx = new_test
// .notification_sender
// .subscribe_with_condition::<DatabaseSyncStatePB, _>(&database.id, |pb| pb.is_finish);
// receive_with_timeout(&mut rx, Duration::from_secs(30))
// .await
// .unwrap();
//
// // when the new sync is finished, the database should be the same as the old one
// let actual = new_test.get_collab_json(&database.id).await;
// assert_json_eq!(actual, expected);
// }
// }