2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Resolvers.GroupTest do
|
|
|
|
use Mobilizon.Web.ConnCase
|
2020-08-27 11:53:24 +02:00
|
|
|
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2018-12-03 11:58:57 +01:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2021-10-22 11:40:47 +02:00
|
|
|
alias Mobilizon.Actors.{Actor, Follower}
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
|
|
|
|
2018-12-03 11:58:57 +01:00
|
|
|
@non_existent_username "nonexistent"
|
2022-05-06 19:30:52 +02:00
|
|
|
@new_group_params %{name: "new group", preferredUsername: "new_group"}
|
2018-12-03 11:58:57 +01:00
|
|
|
|
|
|
|
setup %{conn: conn} do
|
2019-01-25 13:59:58 +01:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
|
|
|
{:ok, conn: conn, actor: actor, user: user}
|
|
|
|
end
|
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
describe "create_group/3" do
|
|
|
|
@create_group_mutation """
|
|
|
|
mutation CreateGroup(
|
|
|
|
$preferredUsername: String!
|
|
|
|
$name: String!
|
|
|
|
$summary: String
|
|
|
|
$avatar: MediaInput
|
|
|
|
$banner: MediaInput
|
|
|
|
) {
|
|
|
|
createGroup(
|
|
|
|
preferredUsername: $preferredUsername
|
|
|
|
name: $name
|
|
|
|
summary: $summary
|
|
|
|
banner: $banner
|
|
|
|
avatar: $avatar
|
|
|
|
) {
|
|
|
|
preferredUsername
|
|
|
|
type
|
|
|
|
banner {
|
|
|
|
id
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
test "creates a group and check a group with this name does not already exist",
|
|
|
|
%{conn: conn, user: user} do
|
2018-12-03 11:58:57 +01:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2022-05-06 19:30:52 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_group_mutation,
|
|
|
|
variables: @new_group_params
|
|
|
|
)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
assert res["errors"] == nil
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
assert res["data"]["createGroup"]["preferredUsername"] ==
|
|
|
|
@new_group_params.preferredUsername
|
2018-12-03 12:08:18 +01:00
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
assert res["data"]["createGroup"]["type"] == "GROUP"
|
2018-12-03 11:58:57 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2022-05-06 19:30:52 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_group_mutation,
|
|
|
|
variables: @new_group_params
|
|
|
|
)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2022-05-06 19:30:52 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2021-09-28 19:40:37 +02:00
|
|
|
"A profile or group with that name already exists"
|
2018-12-03 11:58:57 +01:00
|
|
|
end
|
2022-05-06 19:30:52 +02:00
|
|
|
|
|
|
|
test "doesn't creates a group if the username doesn't match the requirements",
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_group_mutation,
|
|
|
|
variables: Map.put(@new_group_params, :preferredUsername, "no@way")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == [
|
|
|
|
"Username must only contain alphanumeric lowercased characters and underscores."
|
|
|
|
]
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "list groups" do
|
2020-08-27 11:53:24 +02:00
|
|
|
@list_groups_query """
|
|
|
|
{
|
2018-12-03 11:58:57 +01:00
|
|
|
groups {
|
2020-02-18 08:57:00 +01:00
|
|
|
elements {
|
|
|
|
preferredUsername,
|
|
|
|
},
|
|
|
|
total
|
2018-12-03 11:58:57 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 11:53:24 +02:00
|
|
|
"""
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
test "list_groups/3 doesn't returns all groups if not authenticated", %{conn: conn} do
|
|
|
|
insert(:group, visibility: :public)
|
|
|
|
insert(:group, visibility: :unlisted)
|
|
|
|
insert(:group, visibility: :private)
|
2019-04-25 19:05:05 +02:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
res = AbsintheHelpers.graphql_query(conn, query: @list_groups_query)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] == "You may not list groups unless moderator."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "list_groups/3 doesn't return all groups if not a moderator", %{conn: conn} do
|
|
|
|
insert(:group, visibility: :public)
|
|
|
|
insert(:group, visibility: :unlisted)
|
|
|
|
insert(:group, visibility: :private)
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @list_groups_query)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You may not list groups unless moderator."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "list_groups/3 returns all groups if a moderator", %{conn: conn} do
|
|
|
|
group_1 = insert(:group, visibility: :public)
|
|
|
|
group_2 = insert(:group, visibility: :unlisted)
|
|
|
|
group_3 = insert(:group, visibility: :private)
|
|
|
|
user = insert(:user, role: :moderator)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @list_groups_query)
|
|
|
|
|
|
|
|
assert res["data"]["groups"]["total"] == 3
|
|
|
|
|
|
|
|
assert res["data"]["groups"]["elements"]
|
|
|
|
|> Enum.map(& &1["preferredUsername"])
|
|
|
|
|> MapSet.new() ==
|
|
|
|
[group_1, group_2, group_3] |> Enum.map(& &1.preferred_username) |> MapSet.new()
|
2018-12-03 11:58:57 +01:00
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "find a group" do
|
|
|
|
@group_query """
|
|
|
|
query Group($preferredUsername: String!) {
|
|
|
|
group(preferredUsername: $preferredUsername) {
|
2018-12-03 11:58:57 +01:00
|
|
|
preferredUsername,
|
2020-02-18 08:57:00 +01:00
|
|
|
members {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-03 11:58:57 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
test "find_group/3 returns a group by its username", %{conn: conn, actor: actor, user: user} do
|
2021-01-14 19:18:14 +01:00
|
|
|
user2 = insert(:user)
|
|
|
|
insert(:actor, user: user2)
|
2020-02-18 08:57:00 +01:00
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :administrator)
|
|
|
|
insert(:member, parent: group, role: :member)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2021-01-14 19:18:14 +01:00
|
|
|
# Unlogged
|
2018-12-03 11:58:57 +01:00
|
|
|
res =
|
2020-02-18 08:57:00 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @group_query,
|
|
|
|
variables: %{
|
|
|
|
preferredUsername: group.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
assert res["data"]["group"]["preferredUsername"] ==
|
2018-12-03 11:58:57 +01:00
|
|
|
group.preferred_username
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
assert res["data"]["group"]["members"]["total"] == 2
|
2020-11-27 14:56:48 +01:00
|
|
|
assert res["data"]["group"]["members"]["elements"] == []
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2021-01-14 19:18:14 +01:00
|
|
|
# Login with non-member
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user2)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @group_query,
|
|
|
|
variables: %{
|
|
|
|
preferredUsername: group.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
|
|
|
|
assert res["data"]["group"]["preferredUsername"] ==
|
|
|
|
group.preferred_username
|
|
|
|
|
|
|
|
assert res["data"]["group"]["members"]["total"] == 2
|
|
|
|
assert res["data"]["group"]["members"]["elements"] == []
|
|
|
|
|
|
|
|
# Login with member
|
2018-12-03 11:58:57 +01:00
|
|
|
res =
|
2020-02-18 08:57:00 +01:00
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @group_query,
|
|
|
|
variables: %{
|
|
|
|
preferredUsername: group.preferred_username,
|
|
|
|
actorId: actor.id
|
|
|
|
}
|
|
|
|
)
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
assert res["errors"] == nil
|
2018-12-03 11:58:57 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
assert res["data"]["group"]["members"]["total"] == 2
|
|
|
|
|
2020-11-27 14:56:48 +01:00
|
|
|
admin =
|
|
|
|
res["data"]["group"]["members"]["elements"]
|
|
|
|
|> Enum.find(&(&1["role"] == "ADMINISTRATOR"))
|
|
|
|
|
|
|
|
assert admin["actor"]["preferredUsername"] ==
|
2020-02-18 08:57:00 +01:00
|
|
|
actor.preferred_username
|
|
|
|
|
2021-01-14 19:18:14 +01:00
|
|
|
# Non existent username
|
2020-02-18 08:57:00 +01:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @group_query,
|
|
|
|
variables: %{preferredUsername: @non_existent_username}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["data"]["group"] == nil
|
|
|
|
|
2020-10-12 12:16:36 +02:00
|
|
|
assert hd(res["errors"])["message"] == "Group not found"
|
2018-12-03 11:58:57 +01:00
|
|
|
end
|
2019-01-25 09:23:44 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
test "find_group doesn't list group members access if group is private", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
group = insert(:group, visibility: :private)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :administrator)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @group_query,
|
|
|
|
variables: %{
|
|
|
|
preferredUsername: group.preferred_username
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
|
|
|
|
assert res["data"]["group"]["preferredUsername"] ==
|
|
|
|
group.preferred_username
|
|
|
|
|
|
|
|
assert res["data"]["group"]["members"] == %{"elements" => [], "total" => 1}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-09 15:26:37 +02:00
|
|
|
describe "update a group" do
|
|
|
|
@update_group_mutation """
|
|
|
|
mutation UpdateGroup(
|
|
|
|
$id: ID!
|
|
|
|
$name: String
|
|
|
|
$summary: String
|
2020-11-26 11:41:13 +01:00
|
|
|
$avatar: MediaInput
|
|
|
|
$banner: MediaInput
|
2020-10-09 15:26:37 +02:00
|
|
|
$visibility: GroupVisibility
|
|
|
|
$physicalAddress: AddressInput
|
|
|
|
) {
|
|
|
|
updateGroup(
|
|
|
|
id: $id
|
|
|
|
name: $name
|
|
|
|
summary: $summary
|
|
|
|
banner: $banner
|
|
|
|
avatar: $avatar
|
|
|
|
visibility: $visibility
|
|
|
|
physicalAddress: $physicalAddress
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
preferredUsername
|
|
|
|
name
|
|
|
|
summary
|
|
|
|
visibility
|
|
|
|
avatar {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
banner {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
@new_group_name "new name for group"
|
|
|
|
|
|
|
|
test "update_group/3 updates a group", %{conn: conn, user: user, actor: actor} do
|
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :administrator)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_mutation,
|
|
|
|
variables: %{
|
|
|
|
id: group.id,
|
|
|
|
name: @new_group_name,
|
|
|
|
visibility: "UNLISTED"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
|
|
|
assert res["data"]["updateGroup"]["name"] == @new_group_name
|
|
|
|
assert res["data"]["updateGroup"]["visibility"] == "UNLISTED"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_group/3 requires to be logged-in to update a group", %{conn: conn} do
|
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_mutation,
|
|
|
|
variables: %{id: group.id, name: @new_group_name}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged-in to update a group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_group/3 requires to be an admin of the group to update a group", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
group = insert(:group)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :administrator)
|
|
|
|
user = insert(:user)
|
|
|
|
actor2 = insert(:actor, user: user)
|
|
|
|
|
|
|
|
# Actor not member
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_mutation,
|
|
|
|
variables: %{id: group.id, name: @new_group_name}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Profile is not administrator for the group"
|
|
|
|
|
|
|
|
# Actor member but not admin
|
|
|
|
insert(:member, parent: group, actor: actor2, role: :moderator)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_mutation,
|
|
|
|
variables: %{id: group.id, name: @new_group_name}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Profile is not administrator for the group"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
describe "delete a group" do
|
2020-08-27 11:53:24 +02:00
|
|
|
@delete_group_mutation """
|
|
|
|
mutation DeleteGroup($groupId: ID!) {
|
|
|
|
deleteGroup(
|
|
|
|
groupId: $groupId
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-01-25 09:23:44 +01:00
|
|
|
test "delete_group/3 deletes a group", %{conn: conn, user: user, actor: actor} do
|
|
|
|
group = insert(:group)
|
2019-03-01 17:11:28 +01:00
|
|
|
insert(:member, parent: group, actor: actor, role: :administrator)
|
2019-01-25 09:23:44 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @delete_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-01-25 09:23:44 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["deleteGroup"]["id"] == to_string(group.id)
|
|
|
|
|
|
|
|
assert_enqueued(
|
|
|
|
worker: Mobilizon.Service.Workers.Background,
|
|
|
|
args: %{
|
|
|
|
"actor_id" => group.id,
|
|
|
|
"author_id" => actor.id,
|
|
|
|
"op" => "delete_actor",
|
|
|
|
"reserve_username" => true,
|
|
|
|
"suspension" => false
|
|
|
|
}
|
|
|
|
)
|
2019-01-25 09:23:44 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
# Can't be used right now, probably because we try to run a transaction in a Oban Job while using Ecto Sandbox
|
2019-01-25 09:23:44 +01:00
|
|
|
|
2022-03-23 11:38:25 +01:00
|
|
|
# assert %{success: 1, snoozed: 0, failure: 0, discard: 0} == Oban.drain_queue(queue: :background)
|
2020-08-27 11:53:24 +02:00
|
|
|
|
|
|
|
# res =
|
|
|
|
# conn
|
|
|
|
# |> auth_conn(user)
|
|
|
|
# |> AbsintheHelpers.graphql_query(
|
|
|
|
# query: @delete_group_mutation,
|
|
|
|
# variables: %{groupId: group.id}
|
|
|
|
# )
|
|
|
|
|
|
|
|
# assert res["data"] == "tt"
|
|
|
|
# assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
2019-01-25 09:23:44 +01:00
|
|
|
end
|
2019-02-01 09:42:31 +01:00
|
|
|
|
|
|
|
test "delete_group/3 should check user authentication", %{conn: conn, actor: actor} do
|
|
|
|
group = insert(:group)
|
2019-03-01 17:11:28 +01:00
|
|
|
insert(:member, parent: group, actor: actor, role: :member)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @delete_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "logged-in"
|
2019-02-01 09:42:31 +01:00
|
|
|
end
|
|
|
|
|
2019-02-01 09:52:36 +01:00
|
|
|
test "delete_group/3 should check the actor is owned by the user", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
2019-02-01 09:42:31 +01:00
|
|
|
group = insert(:group)
|
2019-03-01 17:11:28 +01:00
|
|
|
insert(:member, parent: group, actor: actor, role: :member)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @delete_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2020-09-29 09:53:48 +02:00
|
|
|
"Current profile is not an administrator of the selected group"
|
2019-02-01 09:42:31 +01:00
|
|
|
end
|
|
|
|
|
2019-02-01 09:52:36 +01:00
|
|
|
test "delete_group/3 should check the actor is a member of this group", %{
|
|
|
|
conn: conn,
|
2020-08-27 11:53:24 +02:00
|
|
|
user: user
|
2019-02-01 09:52:36 +01:00
|
|
|
} do
|
2019-02-01 09:42:31 +01:00
|
|
|
group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @delete_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "not a member"
|
2019-02-01 09:42:31 +01:00
|
|
|
end
|
|
|
|
|
2019-02-01 09:52:36 +01:00
|
|
|
test "delete_group/3 should check the actor is an administrator of this group", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
2019-02-01 09:42:31 +01:00
|
|
|
group = insert(:group)
|
2019-03-01 17:11:28 +01:00
|
|
|
insert(:member, parent: group, actor: actor, role: :member)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-08-27 11:53:24 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @delete_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
2019-02-01 09:42:31 +01:00
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "not an administrator"
|
2019-02-01 09:42:31 +01:00
|
|
|
end
|
2018-12-03 11:58:57 +01:00
|
|
|
end
|
2021-10-22 11:40:47 +02:00
|
|
|
|
|
|
|
describe "follow a group" do
|
|
|
|
@follow_group_mutation """
|
|
|
|
mutation FollowGroup($groupId: ID!, $notify: Boolean) {
|
|
|
|
followGroup(groupId: $groupId, notify: $notify) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
test "when not authenticated", %{conn: conn, user: _user} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @follow_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged-in to follow a group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when group doesn't exist", %{conn: conn, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @follow_group_mutation,
|
|
|
|
variables: %{groupId: "89542"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Group not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "success", %{conn: conn, user: user} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @follow_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "unfollow a group" do
|
|
|
|
@unfollow_group_mutation """
|
|
|
|
mutation UnfollowGroup($groupId: ID!) {
|
|
|
|
unfollowGroup(groupId: $groupId) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
test "when not authenticated", %{conn: conn, user: _user} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @unfollow_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged-in to unfollow a group"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when group doesn't exist", %{conn: conn, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @unfollow_group_mutation,
|
|
|
|
variables: %{groupId: "89542"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Group not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when the profile is not following the group", %{conn: conn, user: user} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @unfollow_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] =~ "Could not unfollow actor: you are not following"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "success", %{conn: conn, user: user, actor: actor} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
|
|
|
|
Mobilizon.Actors.follow(group, actor)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @unfollow_group_mutation,
|
|
|
|
variables: %{groupId: group.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert Mobilizon.Actors.get_follower_by_followed_and_following(group, actor) == nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update a group follow" do
|
|
|
|
@update_group_follow_mutation """
|
|
|
|
mutation UpdateGroupFollow($followId: ID!, $notify: Boolean) {
|
|
|
|
updateGroupFollow(followId: $followId, notify: $notify) {
|
|
|
|
id
|
|
|
|
notify
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
test "when not authenticated", %{conn: conn, user: _user, actor: actor} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
follow = insert(:follower, target_actor: group, actor: actor)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_follow_mutation,
|
|
|
|
variables: %{followId: follow.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You need to be logged-in to update a group follow"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when follow doesn't exist", %{conn: conn, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_follow_mutation,
|
|
|
|
variables: %{followId: "d7c83493-e4a0-42a2-a15d-a469e955e80a"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Follow not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when follow does not match the current actor", %{conn: conn, user: user} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
follow = insert(:follower, target_actor: group)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_follow_mutation,
|
|
|
|
variables: %{followId: follow.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Follow does not match your account"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "success", %{conn: conn, user: user, actor: actor} do
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
follow = insert(:follower, target_actor: group, actor: actor)
|
|
|
|
|
|
|
|
assert %Follower{notify: true} =
|
|
|
|
Mobilizon.Actors.get_follower_by_followed_and_following(group, actor)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_group_follow_mutation,
|
|
|
|
variables: %{followId: follow.id, notify: false}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["updateGroupFollow"]["notify"] == false
|
|
|
|
|
|
|
|
assert %Follower{notify: false} =
|
|
|
|
Mobilizon.Actors.get_follower_by_followed_and_following(group, actor)
|
|
|
|
end
|
|
|
|
end
|
2018-12-03 11:58:57 +01:00
|
|
|
end
|