diff --git a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs index 802349c512..176a39aa9a 100644 --- a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs +++ b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/workspace_test.rs @@ -7,6 +7,27 @@ use flowy_user::protobuf::UserNotification; use crate::util::receive_with_timeout; +#[tokio::test] +async fn af_cloud_workspace_delete() { + user_localhost_af_cloud().await; + let test = EventIntegrationTest::new().await; + let user_profile_pb = test.af_cloud_sign_up().await; + let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await; + assert_eq!(workspaces.len(), 1); + + let created_workspace = test.create_workspace("my second workspace").await; + assert_eq!(created_workspace.name, "my second workspace"); + let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await; + assert_eq!(workspaces.len(), 2); + + test.delete_workspace(&created_workspace.workspace_id).await; + let workspaces = get_synced_workspaces(&test, user_profile_pb.id).await; + assert_eq!(workspaces.len(), 1); + + let workspaces = test.get_all_workspaces().await.items; + assert_eq!(workspaces.len(), 1); +} + #[tokio::test] async fn af_cloud_workspace_name_change() { user_localhost_af_cloud().await; diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs index 1b3ea81533..dfed83ccfe 100644 --- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs +++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs @@ -188,6 +188,9 @@ impl UserManager { .get_user_service()? .delete_workspace(workspace_id) .await?; + let uid = self.user_id()?; + let conn = self.db_connection(uid)?; + delete_user_workspaces(conn, workspace_id)?; Ok(()) } @@ -325,3 +328,14 @@ pub fn save_user_workspaces( Ok::<(), FlowyError>(()) }) } + +pub fn delete_user_workspaces(mut conn: DBConnection, workspace_id: &str) -> FlowyResult<()> { + let n = conn.immediate_transaction(|conn| { + let rows_affected: usize = + diesel::delete(user_workspace_table::table.filter(user_workspace_table::id.eq(workspace_id))) + .execute(conn)?; + Ok::(rows_affected) + })?; + assert_eq!(n, 1); + Ok(()) +}