diff --git a/libs/client-api-test-util/src/test_client.rs b/libs/client-api-test-util/src/test_client.rs index a00a847d92ad4..57c0692b949ba 100644 --- a/libs/client-api-test-util/src/test_client.rs +++ b/libs/client-api-test-util/src/test_client.rs @@ -23,8 +23,7 @@ use database_entity::dto::{ use mime::Mime; use serde_json::{json, Value}; use shared_entity::dto::workspace_dto::{ - BlobMetadata, CreateWorkspaceMember, WorkspaceMemberChangeset, WorkspaceMemberInvitation, - WorkspaceSpaceUsage, + BlobMetadata, WorkspaceMemberChangeset, WorkspaceMemberInvitation, WorkspaceSpaceUsage, }; use shared_entity::response::AppResponseError; use std::collections::HashMap; @@ -150,26 +149,6 @@ impl TestClient { Self::new(registered_user, true).await } - pub async fn add_workspace_member( - &self, - workspace_id: &str, - other_client: &TestClient, - role: AFRole, - ) { - // TODO(zack): replace with `invite_and_accepted_workspace_member`. Make sure running local test with `cargo run` - // and then all the local tasks should be passed. - // mark the create_workspace_members_handler with ` #[deprecated(note = "...")]` - let member = CreateWorkspaceMember { - email: other_client.email().await, - role, - }; - self - .api_client - .add_workspace_members(workspace_id, vec![member]) - .await - .unwrap(); - } - pub async fn get_user_workspace_info(&self) -> AFUserWorkspaceInfo { self.api_client.get_user_workspace_info().await.unwrap() } diff --git a/libs/client-api/src/http.rs b/libs/client-api/src/http.rs index 44f1e4c9e366e..1d095431eea27 100644 --- a/libs/client-api/src/http.rs +++ b/libs/client-api/src/http.rs @@ -669,7 +669,7 @@ impl Client { Ok(()) } - // deprecated + #[deprecated(note = "use invite_workspace_members instead")] #[instrument(level = "debug", skip_all, err)] pub async fn add_workspace_members, W: AsRef>( &self, diff --git a/tests/collab/awareness_test.rs b/tests/collab/awareness_test.rs index 379679ae96c55..3f461bcfb8714 100644 --- a/tests/collab/awareness_test.rs +++ b/tests/collab/awareness_test.rs @@ -12,8 +12,9 @@ async fn viewing_document_editing_users_test() { let workspace_id = owner.workspace_id().await; owner - .add_workspace_member(&workspace_id, &guest, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Member) + .await + .unwrap(); let object_id = owner .create_and_edit_collab(&workspace_id, collab_type.clone()) diff --git a/tests/collab/edit_permission.rs b/tests/collab/edit_permission.rs index 31cac3fae3074..e1bf11662fda3 100644 --- a/tests/collab/edit_permission.rs +++ b/tests/collab/edit_permission.rs @@ -431,8 +431,9 @@ async fn multiple_user_with_read_and_write_permission_edit_same_collab_test() { sleep(Duration::from_secs(i % 3)).await; owner - .add_workspace_member(&workspace_id, &new_member, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &new_member, AFRole::Member) + .await + .unwrap(); owner .add_collab_member( &workspace_id, diff --git a/tests/workspace/edit_workspace.rs b/tests/workspace/edit_workspace.rs index baf95314b003f..a390a46c8ea10 100644 --- a/tests/workspace/edit_workspace.rs +++ b/tests/workspace/edit_workspace.rs @@ -46,8 +46,9 @@ async fn init_sync_workspace_with_member_permission() { // TODO(nathan): write test for AFRole::Guest // add client 2 as the member of the workspace then the client 2 will receive the update. owner - .add_workspace_member(&workspace_id, &guest, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Member) + .await + .unwrap(); guest.open_workspace_collab(&workspace_id).await; owner @@ -89,8 +90,9 @@ async fn edit_workspace_with_guest_permission() { // add client 2 as the member of the workspace then the client 2 can receive the update. owner - .add_workspace_member(&workspace_id, &guest, AFRole::Guest) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Guest) + .await + .unwrap(); owner .collabs diff --git a/tests/workspace/member_crud.rs b/tests/workspace/member_crud.rs index de7d1ef32ec85..9d7c9188ab8be 100644 --- a/tests/workspace/member_crud.rs +++ b/tests/workspace/member_crud.rs @@ -41,8 +41,9 @@ async fn workspace_members_through_invite_or_direct_add() { let member_2 = TestClient::new_user_without_ws_conn().await; let workspace_id = owner.workspace_id().await; owner - .add_workspace_member(&workspace_id, &member_1, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &member_1, AFRole::Member) + .await + .unwrap(); // TODO(Zack): fix { code: OAuthError, message: "code: 500, msg:Error sending magic link, error_id: Some(\"3ec69543-e7b9-496d-92d8-f0b73ff09e0f\")" } owner @@ -68,8 +69,9 @@ async fn add_workspace_members_not_enough_permission() { // add client 2 to client 1's workspace owner - .add_workspace_member(&workspace_id, &member_1, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &member_1, AFRole::Member) + .await + .unwrap(); // client 2 add client 3 to client 1's workspace but permission denied let error = member_1 @@ -86,10 +88,12 @@ async fn add_duplicate_workspace_members() { let workspace_id = c1.workspace_id().await; - c1.add_workspace_member(&workspace_id, &c2, AFRole::Member) - .await; - c1.add_workspace_member(&workspace_id, &c2, AFRole::Member) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id, &c2, AFRole::Member) + .await + .unwrap(); + c1.invite_and_accepted_workspace_member(&workspace_id, &c2, AFRole::Member) + .await + .unwrap(); } #[tokio::test] @@ -132,8 +136,9 @@ async fn update_workspace_member_role_not_enough_permission() { let workspace_id = c1.workspace_id().await; // add client 2 to client 1's workspace - c1.add_workspace_member(&workspace_id, &c2, AFRole::Member) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id, &c2, AFRole::Member) + .await + .unwrap(); // client 2 want to update client 2's role to owner let error = c2 @@ -151,8 +156,9 @@ async fn update_workspace_member_role_from_guest_to_member() { // add client 2 to client 1's workspace owner - .add_workspace_member(&workspace_id, &guest, AFRole::Guest) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Guest) + .await + .unwrap(); let members = owner .api_client .get_workspace_members(&workspace_id) @@ -189,16 +195,19 @@ async fn workspace_add_member() { // add client 2 to client 1's workspace owner - .add_workspace_member(&workspace_id, &other_owner, AFRole::Owner) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &other_owner, AFRole::Owner) + .await + .unwrap(); // add client 3 to client 1's workspace other_owner - .add_workspace_member(&workspace_id, &member, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &member, AFRole::Member) + .await + .unwrap(); other_owner - .add_workspace_member(&workspace_id, &guest, AFRole::Guest) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Guest) + .await + .unwrap(); let members = owner .api_client @@ -270,11 +279,13 @@ async fn add_workspace_member_and_owner_then_delete_all() { let workspace_id = owner.workspace_id().await; // add client 2 to client 1's workspace owner - .add_workspace_member(&workspace_id, &member, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &member, AFRole::Member) + .await + .unwrap(); owner - .add_workspace_member(&workspace_id, &second_owner, AFRole::Owner) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &second_owner, AFRole::Owner) + .await + .unwrap(); let members = owner .api_client @@ -325,8 +336,9 @@ async fn workspace_second_owner_can_not_delete_origin_owner() { let c1 = TestClient::new_user_without_ws_conn().await; let c2 = TestClient::new_user_without_ws_conn().await; let workspace_id = c1.workspace_id().await; - c1.add_workspace_member(&workspace_id, &c2, AFRole::Owner) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id, &c2, AFRole::Owner) + .await + .unwrap(); let error = c2 .try_remove_workspace_member(&workspace_id, &c1) @@ -347,8 +359,9 @@ async fn user_workspace_info() { ); let c2 = TestClient::new_user_without_ws_conn().await; - c1.add_workspace_member(&workspace_id, &c2, AFRole::Owner) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id, &c2, AFRole::Owner) + .await + .unwrap(); // c2 should have 2 workspaces let info = c2.get_user_workspace_info().await; @@ -361,8 +374,9 @@ async fn get_user_workspace_info_after_open_workspace() { let workspace_id_c1 = c1.workspace_id().await; let c2 = TestClient::new_user_without_ws_conn().await; - c1.add_workspace_member(&workspace_id_c1, &c2, AFRole::Owner) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id_c1, &c2, AFRole::Owner) + .await + .unwrap(); let info = c2.get_user_workspace_info().await; let workspace_id_c2 = c1.workspace_id().await; @@ -386,8 +400,9 @@ async fn member_leave_workspace_test() { let workspace_id_c1 = c1.workspace_id().await; let c2 = TestClient::new_user().await; - c1.add_workspace_member(&workspace_id_c1, &c2, AFRole::Member) - .await; + c1.invite_and_accepted_workspace_member(&workspace_id_c1, &c2, AFRole::Member) + .await + .unwrap(); c2.api_client .leave_workspace(&workspace_id_c1) .await @@ -420,11 +435,13 @@ async fn add_workspace_member_and_then_member_get_member_list() { let workspace_id = owner.workspace_id().await; owner - .add_workspace_member(&workspace_id, &member, AFRole::Member) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &member, AFRole::Member) + .await + .unwrap(); owner - .add_workspace_member(&workspace_id, &guest, AFRole::Guest) - .await; + .invite_and_accepted_workspace_member(&workspace_id, &guest, AFRole::Guest) + .await + .unwrap(); // member should be able to get the member list of the workspace let members = member.get_workspace_members(&workspace_id).await; diff --git a/tests/workspace/workspace_crud.rs b/tests/workspace/workspace_crud.rs index ec449720c8188..ccc56db4bf701 100644 --- a/tests/workspace/workspace_crud.rs +++ b/tests/workspace/workspace_crud.rs @@ -1,8 +1,6 @@ use client_api_test_util::generate_unique_registered_user_client; use collab_entity::CollabType; -use database_entity::dto::AFRole; use database_entity::dto::QueryCollabParams; -use shared_entity::dto::workspace_dto::CreateWorkspaceMember; use shared_entity::dto::workspace_dto::CreateWorkspaceParam; use shared_entity::dto::workspace_dto::PatchWorkspaceParam; @@ -44,47 +42,6 @@ async fn add_and_delete_workspace_for_user() { assert_eq!(workspaces.0.len(), 1); } -#[tokio::test] -async fn add_and_delete_workspace_for_non_owner_user() { - let (member, member_user) = generate_unique_registered_user_client().await; - - // Owner added member to workspace - let (owner, _user) = generate_unique_registered_user_client().await; - let owner_workspace = owner - .create_workspace(CreateWorkspaceParam { - workspace_name: Some("owner_workspace".to_string()), - }) - .await - .unwrap(); - - owner - .add_workspace_members( - owner_workspace.workspace_id.to_string(), - vec![CreateWorkspaceMember { - email: member_user.email.clone(), - role: AFRole::Member, - }], - ) - .await - .unwrap(); - - // Member should have 2 workspaces - let member_workspaces = member.get_workspaces().await.unwrap(); - assert_eq!(member_workspaces.0.len(), 2); - - owner - .remove_workspace_members( - owner_workspace.workspace_id.to_string(), - vec![member_user.email], - ) - .await - .unwrap(); - - // Member should have 1 workspaces, because owner removed him - let member_workspaces = member.get_workspaces().await.unwrap(); - assert_eq!(member_workspaces.0.len(), 1); -} - #[tokio::test] async fn test_workspace_rename_and_icon_change() { let (c, _user) = generate_unique_registered_user_client().await;