Events with only one event creator participant can't be left

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-07 17:57:49 +01:00
parent d1d3beeb35
commit dfa25e0d21
3 changed files with 119 additions and 7 deletions

View File

@@ -46,7 +46,7 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["joinEvent"]["role"] == 1
assert json_response(res, 200)["data"]["joinEvent"]["role"] == "participant"
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == event.id
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == actor.id
@@ -122,6 +122,63 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
conn: conn,
user: user,
actor: actor
} do
event = insert(:event, %{organizer_actor: actor})
participant = insert(:participant, %{actor: actor, event: event})
participant2 = insert(:participant, %{event: event})
mutation = """
mutation {
leaveEvent(
actor_id: #{participant.actor.id},
event_id: #{event.id}
) {
actor {
id
},
event {
id
}
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["leaveEvent"]["event"]["id"] == event.id
assert json_response(res, 200)["data"]["leaveEvent"]["actor"]["id"] == participant.actor.id
query = """
{
participants(uuid: "#{event.uuid}") {
role,
actor {
preferredUsername
}
}
}
"""
res =
conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
assert json_response(res, 200)["data"]["participants"] == [
%{
"actor" => %{"preferredUsername" => participant2.actor.preferred_username},
"role" => "creator"
}
]
end
test "actor_leave_event/3 should check if the participant is the only creator", %{
conn: conn,
actor: actor,
user: user
} do
participant = insert(:participant, %{actor: actor})
@@ -146,9 +203,35 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["leaveEvent"]["event"]["id"] == participant.event.id
assert json_response(res, 200)["data"]["leaveEvent"]["actor"]["id"] == participant.actor.id
assert hd(json_response(res, 200)["errors"])["message"] ==
"You can't leave event because you're the only event creator participant"
# If we have a second participant but not an event creator
insert(:participant, %{event: participant.event, role: :participant})
mutation = """
mutation {
leaveEvent(
actor_id: #{participant.actor.id},
event_id: #{participant.event.id}
) {
actor {
id
},
event {
id
}
}
}
"""
res =
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] ==
"You can't leave event because you're the only event creator participant"
end
test "actor_leave_event/3 should check the user is logged in", %{conn: conn, actor: actor} do
@@ -258,7 +341,7 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
assert json_response(res, 200)["data"]["participants"] == [
%{
"actor" => %{"preferredUsername" => context.actor.preferred_username},
"role" => 4
"role" => "creator"
}
]
@@ -266,7 +349,7 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
actor2 = insert(:actor)
actor3 = insert(:actor)
# This one won't get listed (as not approved)
participant = insert(:participant, event: event, actor: actor2, role: :not_approved)
insert(:participant, event: event, actor: actor2, role: :not_approved)
# This one will (as a participant)
participant2 = insert(:participant, event: event, actor: actor3, role: :participant)