Add group resolver tests
This commit is contained in:
parent
665e27e485
commit
e4c8222833
@ -98,7 +98,7 @@ defmodule MobilizonWeb.Resolvers.Group do
|
|||||||
{:error, "Actor id is not a member of this group"}
|
{:error, "Actor id is not a member of this group"}
|
||||||
|
|
||||||
{:is_admin, false} ->
|
{:is_admin, false} ->
|
||||||
{:error, "User is not an administrator of the selected group"}
|
{:error, "Actor id is not an administrator of the selected group"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,5 +143,96 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
|||||||
|
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "delete_group/3 should check user authentication", %{conn: conn, actor: actor} do
|
||||||
|
group = insert(:group)
|
||||||
|
insert(:member, parent: group, actor: actor, role: 2)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteGroup(
|
||||||
|
actor_id: #{actor.id},
|
||||||
|
group_id: #{group.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_group/3 should checks the actor is owned by the user", %{conn: conn, user: user, actor: actor} do
|
||||||
|
group = insert(:group)
|
||||||
|
insert(:member, parent: group, actor: actor, role: 2)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteGroup(
|
||||||
|
actor_id: 159,
|
||||||
|
group_id: #{group.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> auth_conn(user)
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_group/3 should checks the actor is a member of this group", %{conn: conn, user: user, actor: actor} do
|
||||||
|
group = insert(:group)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteGroup(
|
||||||
|
actor_id: #{actor.id},
|
||||||
|
group_id: #{group.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> auth_conn(user)
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not a member"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_group/3 should checks the actor is an administrator of this group", %{conn: conn, user: user, actor: actor} do
|
||||||
|
group = insert(:group)
|
||||||
|
insert(:member, parent: group, actor: actor, role: 1)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteGroup(
|
||||||
|
actor_id: #{actor.id},
|
||||||
|
group_id: #{group.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> auth_conn(user)
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not an administrator"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user