chore: checking workspace state consistent after switching workspace (#5201)

* refactor: getting workspace id

* refactor: check workspace id is match for http response

* refactor: check http repsonse in valid by checing the workspace id

* chore: update log

* chore: fix test

* chore: fix test

* chore: add test

* chore: update test
This commit is contained in:
Nathan.fooo
2024-04-26 09:44:07 +08:00
committed by GitHub
parent 65a289648e
commit cc66147bc0
51 changed files with 980 additions and 575 deletions

View File

@ -9,11 +9,10 @@ use nanoid::nanoid;
use parking_lot::Once;
use tempfile::TempDir;
use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter};
use uuid::Uuid;
use collab_integrate::collab_builder::{
AppFlowyCollabBuilder, CollabCloudPluginProvider, CollabPluginProviderContext,
CollabPluginProviderType,
CollabPluginProviderType, WorkspaceCollabIntegrate,
};
use collab_integrate::CollabKVDB;
use flowy_document::document::MutexDocument;
@ -35,9 +34,17 @@ impl DocumentTest {
let cloud_service = Arc::new(LocalTestDocumentCloudServiceImpl());
let file_storage = Arc::new(DocumentTestFileStorageService) as Arc<dyn ObjectStorageService>;
let document_snapshot = Arc::new(DocumentTestSnapshot);
let builder = Arc::new(AppFlowyCollabBuilder::new(
DefaultCollabStorageProvider(),
WorkspaceCollabIntegrateImpl {
workspace_id: user.workspace_id.clone(),
},
));
let manager = DocumentManager::new(
Arc::new(user),
default_collab_builder(),
builder,
cloud_service,
Arc::downgrade(&file_storage),
document_snapshot,
@ -55,6 +62,7 @@ impl Deref for DocumentTest {
}
pub struct FakeUser {
workspace_id: String,
collab_db: Arc<CollabKVDB>,
}
@ -65,8 +73,12 @@ impl FakeUser {
let tempdir = TempDir::new().unwrap();
let path = tempdir.into_path();
let collab_db = Arc::new(CollabKVDB::open(path).unwrap());
let workspace_id = uuid::Uuid::new_v4().to_string();
Self { collab_db }
Self {
collab_db,
workspace_id,
}
}
}
@ -76,7 +88,7 @@ impl DocumentUserService for FakeUser {
}
fn workspace_id(&self) -> Result<String, FlowyError> {
Ok(Uuid::new_v4().to_string())
Ok(self.workspace_id.clone())
}
fn collab_db(&self, _uid: i64) -> Result<std::sync::Weak<CollabKVDB>, FlowyError> {
@ -100,13 +112,6 @@ pub fn setup_log() {
});
}
pub fn default_collab_builder() -> Arc<AppFlowyCollabBuilder> {
let builder =
AppFlowyCollabBuilder::new(DefaultCollabStorageProvider(), "fake_device_id".to_string());
builder.initialize(uuid::Uuid::new_v4().to_string());
Arc::new(builder)
}
pub async fn create_and_open_empty_document() -> (DocumentTest, Arc<MutexDocument>, String) {
let test = DocumentTest::new();
let doc_id: String = gen_document_id();
@ -222,3 +227,16 @@ impl DocumentSnapshotService for DocumentTestSnapshot {
todo!()
}
}
struct WorkspaceCollabIntegrateImpl {
workspace_id: String,
}
impl WorkspaceCollabIntegrate for WorkspaceCollabIntegrateImpl {
fn workspace_id(&self) -> Result<String, Error> {
Ok(self.workspace_id.clone())
}
fn device_id(&self) -> Result<String, Error> {
Ok("fake_device_id".to_string())
}
}