2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
2020-01-26 21:36:50 +01:00
|
|
|
use Mobilizon.Web.ConnCase
|
2021-11-14 16:27:53 +01:00
|
|
|
import Mox
|
2019-03-01 17:11:28 +01:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
alias Mobilizon.Actors.Member
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
2021-11-14 16:27:53 +01:00
|
|
|
alias Mobilizon.Service.HTTP.HostMetaClient.Mock, as: HostMetaClientMock
|
|
|
|
alias Mobilizon.Service.HTTP.WebfingerClient.Mock, as: WebfingerClientMock
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2019-03-01 17:11:28 +01:00
|
|
|
setup %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user, preferred_username: "test")
|
|
|
|
|
|
|
|
{:ok, conn: conn, actor: actor, user: user}
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "Member Resolver to join a group" do
|
2020-11-06 11:34:32 +01:00
|
|
|
@join_group_mutation """
|
|
|
|
mutation JoinGroup($groupId: ID!) {
|
|
|
|
joinGroup(groupId: $groupId) {
|
|
|
|
id
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
parent {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-03-01 17:11:28 +01:00
|
|
|
test "join_group/3 should create a member", %{conn: conn, user: user, actor: actor} do
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-11-06 11:34:32 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @join_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["joinGroup"]["role"] == "NOT_APPROVED"
|
|
|
|
assert res["data"]["joinGroup"]["parent"]["id"] == to_string(group.id)
|
|
|
|
assert res["data"]["joinGroup"]["actor"]["id"] == to_string(actor.id)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-11-06 11:34:32 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @join_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
assert hd(res["errors"])["message"] =~ "already a member"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "join_group/3 should check the group is not invite only", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
group = insert(:group, %{openness: :invite_only})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-11-06 11:34:32 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @join_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
assert hd(res["errors"])["message"] =~ "cannot join this group"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "join_group/3 should check the group exists", %{
|
|
|
|
conn: conn,
|
2020-11-06 11:34:32 +01:00
|
|
|
user: user
|
2019-03-01 17:11:28 +01:00
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-11-06 11:34:32 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @join_group_mutation,
|
|
|
|
variables: %{groupId: 1042}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
assert hd(res["errors"])["message"] =~ "Group not found"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "Member Resolver to leave from a group" do
|
2020-08-27 11:53:24 +02:00
|
|
|
@leave_group_mutation """
|
|
|
|
mutation LeaveGroup($groupId: ID!) {
|
|
|
|
leaveGroup(groupId: $groupId) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-03-01 17:11:28 +01:00
|
|
|
test "leave_group/3 should delete a member from a group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
group = insert(:group)
|
2020-08-14 11:32:23 +02:00
|
|
|
insert(:member, role: :administrator, parent: group)
|
|
|
|
%Member{id: member_id} = insert(:member, %{actor: actor, parent: group})
|
2019-03-01 17:11:28 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @leave_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["leaveGroup"]["id"] == to_string(member_id)
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "leave_group/3 should check if the member is the only administrator", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, %{actor: actor, role: :creator, parent: group})
|
|
|
|
insert(:member, %{parent: group})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @leave_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "only administrator"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "leave_group/3 should check the user is logged in", %{conn: conn, actor: actor} do
|
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, %{actor: actor, parent: group})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @leave_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged in"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
test "leave_group/3 should check the group exists", %{
|
2019-03-01 17:11:28 +01:00
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, %{actor: actor, parent: group})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @leave_group_mutation,
|
|
|
|
variables: %{groupId: 1042}
|
|
|
|
)
|
2019-03-01 17:11:28 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "Group not found"
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
describe "Member Resolver to invite to a group" do
|
|
|
|
@invite_member_mutation """
|
|
|
|
mutation InviteMember($groupId: ID!, $targetActorUsername: String!) {
|
|
|
|
inviteMember(groupId: $groupId, targetActorUsername: $targetActorUsername) {
|
|
|
|
parent {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
setup %{conn: conn, actor: actor, user: user} do
|
|
|
|
group = insert(:group)
|
|
|
|
target_actor = insert(:actor, user: user)
|
|
|
|
|
2024-08-20 21:43:41 +02:00
|
|
|
Mox.expect(Mobilizon.Service.HTTP.ActivityPub.Mock, :call, fn _req, _opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 200, body: %{"role" => "INVITED"}}}
|
|
|
|
end)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
{:ok, conn: conn, actor: actor, user: user, group: group, target_actor: target_actor}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 invites a local actor to a group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
_admin_member = insert(:member, %{actor: actor, parent: group, role: :creator})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: target_actor.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["inviteMember"]["role"] == "INVITED"
|
|
|
|
assert res["data"]["inviteMember"]["parent"]["id"] == to_string(group.id)
|
|
|
|
assert res["data"]["inviteMember"]["actor"]["id"] == to_string(target_actor.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 invites a remote actor to a group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group
|
|
|
|
} do
|
|
|
|
_admin_member = insert(:member, %{actor: actor, parent: group, role: :creator})
|
|
|
|
target_actor = insert(:actor, domain: "remote.tld")
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: "#{target_actor.preferred_username}@#{target_actor.domain}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["inviteMember"]["role"] == "INVITED"
|
|
|
|
assert res["data"]["inviteMember"]["parent"]["id"] == to_string(group.id)
|
|
|
|
assert res["data"]["inviteMember"]["actor"]["id"] == to_string(target_actor.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a local actor to a group that invitor isn't in", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: target_actor.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You are not a member of this group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a non existing local actor", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group
|
|
|
|
} do
|
|
|
|
insert(:member, %{actor: actor, parent: group, role: :administrator})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: "not_existing"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
assert hd(res["errors"])["message"] == "Profile invited doesn't exist"
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a non existing remote actor", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group
|
|
|
|
} do
|
|
|
|
insert(:member, %{actor: actor, parent: group, role: :administrator})
|
|
|
|
|
2021-11-14 16:27:53 +01:00
|
|
|
HostMetaClientMock
|
|
|
|
|> expect(:call, fn
|
2022-01-06 18:48:48 +01:00
|
|
|
%{method: :get, url: "https://nowhere.absolute/.well-known/host-meta"}, _opts ->
|
2021-11-14 16:27:53 +01:00
|
|
|
{:ok, %Tesla.Env{status: 404, body: ""}}
|
|
|
|
end)
|
|
|
|
|
|
|
|
WebfingerClientMock
|
|
|
|
|> expect(:call, fn
|
|
|
|
%{
|
|
|
|
method: :get,
|
|
|
|
url:
|
2022-01-06 18:48:48 +01:00
|
|
|
"https://nowhere.absolute/.well-known/webfinger?resource=acct:not_existing@nowhere.absolute"
|
2021-11-14 16:27:53 +01:00
|
|
|
},
|
|
|
|
_opts ->
|
|
|
|
{:ok, %Tesla.Env{status: 404, body: ""}}
|
|
|
|
end)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: "not_existing@nowhere.absolute"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
assert hd(res["errors"])["message"] == "Profile invited doesn't exist"
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a actor for a non-existing group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: "780907988778",
|
|
|
|
targetActorUsername: target_actor.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
assert hd(res["errors"])["message"] == "Group not found"
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a actor if we are not an admin for the group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
_admin_member = insert(:member, %{actor: actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: target_actor.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You cannot invite to this group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invite_member/3 fails to invite a actor if it's already a member of the group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
insert(:member, %{actor: actor, parent: group, role: :member})
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @invite_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
groupId: group.id,
|
|
|
|
targetActorUsername: target_actor.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You cannot invite to this group"
|
|
|
|
end
|
|
|
|
end
|
2020-08-20 10:54:58 +02:00
|
|
|
|
|
|
|
describe "Member resolver to update a group member" do
|
|
|
|
@update_member_mutation """
|
|
|
|
mutation UpdateMember($memberId: ID!, $role: MemberRoleEnum!) {
|
|
|
|
updateMember(memberId: $memberId, role: $role) {
|
|
|
|
id
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
setup %{conn: conn, actor: actor, user: user} do
|
|
|
|
group = insert(:group)
|
|
|
|
target_actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
{:ok, conn: conn, actor: actor, user: user, group: group, target_actor: target_actor}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_member/3 fails when not connected", %{
|
|
|
|
conn: conn,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "MODERATOR"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged in"
|
2020-08-20 10:54:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "update_member/3 fails when not a member of the group", %{
|
|
|
|
conn: conn,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2021-11-03 08:50:28 +01:00
|
|
|
Mobilizon.Users.update_user_default_actor(user, actor)
|
2020-08-20 10:54:58 +02:00
|
|
|
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "MODERATOR"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You are not a moderator or admin for this group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_member/3 updates the member role", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
2021-11-03 08:50:28 +01:00
|
|
|
Mobilizon.Users.update_user_default_actor(user, actor)
|
2020-08-20 10:54:58 +02:00
|
|
|
insert(:member, actor: actor, parent: group, role: :administrator)
|
|
|
|
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "MODERATOR"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["updateMember"]["role"] == "MODERATOR"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "ADMINISTRATOR"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["updateMember"]["role"] == "ADMINISTRATOR"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "MEMBER"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["updateMember"]["role"] == "MEMBER"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_member/3 prevents to downgrade the member role if there's no admin left", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group
|
|
|
|
} do
|
2021-11-03 08:50:28 +01:00
|
|
|
Mobilizon.Users.update_user_default_actor(user, actor)
|
2020-08-20 10:54:58 +02:00
|
|
|
%Member{id: member_id} = insert(:member, actor: actor, parent: group, role: :administrator)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id,
|
|
|
|
role: "MEMBER"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"You can't set yourself to a lower member role for this group because you are the only administrator"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Member resolver to remove a member from a group" do
|
2021-11-12 15:42:52 +01:00
|
|
|
@remove_member_mutation """
|
|
|
|
mutation RemoveMember($memberId: ID!) {
|
|
|
|
removeMember(memberId: $memberId) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
setup %{conn: conn, actor: actor, user: user} do
|
|
|
|
group = insert(:group)
|
|
|
|
target_actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
{:ok, conn: conn, actor: actor, user: user, group: group, target_actor: target_actor}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "remove_member/3 fails when not connected", %{
|
|
|
|
conn: conn,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @remove_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged in"
|
2021-11-12 15:42:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "remove_member/3 fails when not a member of the group", %{
|
|
|
|
conn: conn,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
Mobilizon.Users.update_user_default_actor(user, actor)
|
|
|
|
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @remove_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You don't have the right to remove this member."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "remove_member/3 removes a member", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor,
|
|
|
|
group: group,
|
|
|
|
target_actor: target_actor
|
|
|
|
} do
|
|
|
|
Mobilizon.Users.update_user_default_actor(user, actor)
|
|
|
|
insert(:member, actor: actor, parent: group, role: :administrator)
|
|
|
|
|
|
|
|
%Member{id: member_id} =
|
|
|
|
insert(:member, %{actor: target_actor, parent: group, role: :member})
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @remove_member_mutation,
|
|
|
|
variables: %{
|
|
|
|
memberId: member_id
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["removeMember"]["id"] == member_id
|
|
|
|
|
|
|
|
assert Mobilizon.Actors.get_member(member_id) == nil
|
|
|
|
end
|
2020-08-20 10:54:58 +02:00
|
|
|
end
|
2019-03-01 17:11:28 +01:00
|
|
|
end
|