mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
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:
@ -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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user