Add event resolver tests
This commit is contained in:
parent
ec961aa5e6
commit
d0c1d6f41f
|
@ -333,5 +333,79 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest 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_event/3 should check the user is authenticated", %{conn: conn, actor: actor} do
|
||||||
|
event = insert(:event, organizer_actor: actor)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteEvent(
|
||||||
|
actor_id: #{actor.id},
|
||||||
|
event_id: #{event.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_event/3 should check the actor id is owned by the user", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user,
|
||||||
|
actor: actor
|
||||||
|
} do
|
||||||
|
event = insert(:event, organizer_actor: actor)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteEvent(
|
||||||
|
actor_id: 1042,
|
||||||
|
event_id: #{event.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_event/3 should check the event can be deleted by the user", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user,
|
||||||
|
actor: actor
|
||||||
|
} do
|
||||||
|
actor2 = insert(:actor)
|
||||||
|
event = insert(:event, organizer_actor: actor2)
|
||||||
|
|
||||||
|
mutation = """
|
||||||
|
mutation {
|
||||||
|
deleteEvent(
|
||||||
|
actor_id: #{actor.id},
|
||||||
|
event_id: #{event.id}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
res =
|
||||||
|
conn
|
||||||
|
|> auth_conn(user)
|
||||||
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "cannot delete"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -166,7 +166,11 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_group/3 should checks the actor is owned by the user", %{conn: conn, user: user, actor: actor} do
|
test "delete_group/3 should check the actor is owned by the user", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user,
|
||||||
|
actor: actor
|
||||||
|
} do
|
||||||
group = insert(:group)
|
group = insert(:group)
|
||||||
insert(:member, parent: group, actor: actor, role: 2)
|
insert(:member, parent: group, actor: actor, role: 2)
|
||||||
|
|
||||||
|
@ -189,7 +193,11 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_group/3 should checks the actor is a member of this group", %{conn: conn, user: user, actor: actor} do
|
test "delete_group/3 should check the actor is a member of this group", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user,
|
||||||
|
actor: actor
|
||||||
|
} do
|
||||||
group = insert(:group)
|
group = insert(:group)
|
||||||
|
|
||||||
mutation = """
|
mutation = """
|
||||||
|
@ -211,7 +219,11 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not a member"
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not a member"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_group/3 should checks the actor is an administrator of this group", %{conn: conn, user: user, actor: actor} do
|
test "delete_group/3 should check the actor is an administrator of this group", %{
|
||||||
|
conn: conn,
|
||||||
|
user: user,
|
||||||
|
actor: actor
|
||||||
|
} do
|
||||||
group = insert(:group)
|
group = insert(:group)
|
||||||
insert(:member, parent: group, actor: actor, role: 1)
|
insert(:member, parent: group, actor: actor, role: 1)
|
||||||
|
|
||||||
|
@ -233,6 +245,5 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||||
|
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not an administrator"
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not an administrator"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -165,8 +165,7 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||||
context.conn
|
context.conn
|
||||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||||
|
|
||||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
assert hd(json_response(res, 200)["errors"])["message"] == "User with email not found"
|
||||||
"User with email not found"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "register_person/3 can't be called with an existing profile", context do
|
test "register_person/3 can't be called with an existing profile", context do
|
||||||
|
|
Loading…
Reference in a new issue