fix: delete workspace after deleting from remote (#4830)

This commit is contained in:
Zack 2024-03-06 17:27:52 +08:00 committed by GitHub
parent 66aea29ab7
commit 6e2caf3358
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -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;

View File

@ -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::<usize, FlowyError>(rows_affected)
})?;
assert_eq!(n, 1);
Ok(())
}