Skip to content

Commit

Permalink
Merge pull request AppFlowy-IO#444 from AppFlowy-IO/test-invite-works…
Browse files Browse the repository at this point in the history
…pace

chore: replace test using invite and accept workspace
  • Loading branch information
speed2exe authored Apr 3, 2024
2 parents ac62258 + 8e27e94 commit 6657b62
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 108 deletions.
23 changes: 1 addition & 22 deletions libs/client-api-test-util/src/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion libs/client-api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<CreateWorkspaceMembers>, W: AsRef<str>>(
&self,
Expand Down
5 changes: 3 additions & 2 deletions tests/collab/awareness_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions tests/collab/edit_permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions tests/workspace/edit_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
85 changes: 51 additions & 34 deletions tests/workspace/member_crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 0 additions & 43 deletions tests/workspace/workspace_crud.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6657b62

Please sign in to comment.