2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
2020-01-26 21:36:50 +01:00
|
|
|
use Mobilizon.Web.ConnCase
|
2019-09-30 13:48:47 +02:00
|
|
|
use Bamboo.Test
|
2019-12-20 13:04:34 +01:00
|
|
|
use Mobilizon.Tests.Helpers
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
alias Mobilizon.Config
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.Events
|
2019-12-20 13:04:34 +01:00
|
|
|
alias Mobilizon.Events.{Event, EventParticipantStats, Participant}
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
2020-03-05 19:32:34 +01:00
|
|
|
alias Mobilizon.Storage.Page
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Email
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
@event %{
|
|
|
|
description: "some body",
|
|
|
|
title: "some title",
|
2019-09-02 10:50:00 +02:00
|
|
|
begins_on:
|
|
|
|
DateTime.utc_now()
|
|
|
|
|> DateTime.truncate(:second),
|
2019-02-01 15:38:35 +01:00
|
|
|
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
|
2019-02-22 16:54:01 +01:00
|
|
|
url: "some url",
|
2019-09-11 16:37:30 +02:00
|
|
|
category: "meeting",
|
|
|
|
options: %{}
|
2019-02-01 15:38:35 +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
|
|
|
|
|
|
|
|
describe "Participant Resolver" do
|
|
|
|
test "actor_join_event/3 should create a participant", %{conn: conn, user: user, actor: actor} do
|
|
|
|
event = insert(:event)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
2019-09-20 18:22:03 +02:00
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["role"] == "PARTICIPANT"
|
2019-09-09 09:31:08 +02:00
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == to_string(actor.id)
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "already a participant"
|
|
|
|
end
|
|
|
|
|
2019-10-11 11:50:06 +02:00
|
|
|
test "actor_join_event/3 doesn't work if the event already has too much participants", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
event = insert(:event, options: %{maximum_attendee_capacity: 2})
|
|
|
|
insert(:participant, event: event, actor: actor, role: :creator)
|
|
|
|
insert(:participant, event: event, role: :participant)
|
|
|
|
insert(:participant, event: event, role: :not_approved)
|
|
|
|
insert(:participant, event: event, role: :rejected)
|
|
|
|
user_participant = insert(:user)
|
|
|
|
actor_participant = insert(:actor, user: user_participant)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor_participant.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_participant)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["role"] == "PARTICIPANT"
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] ==
|
|
|
|
to_string(actor_participant.id)
|
|
|
|
|
|
|
|
user_participant_2 = insert(:user)
|
|
|
|
actor_participant_2 = insert(:actor, user: user_participant_2)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor_participant_2.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_participant_2)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2019-10-15 21:18:03 +02:00
|
|
|
"The event has already reached its maximum capacity"
|
2019-10-11 11:50:06 +02:00
|
|
|
end
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
test "actor_join_event/3 should check the actor is owned by the user", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: 1042,
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "actor_join_event/3 should check the event exists", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: 1042
|
|
|
|
) {
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-08-14 17:45:11 +02:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2019-09-09 09:31:08 +02:00
|
|
|
"Event with this ID \"1042\" doesn't exist"
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
@person_participations """
|
|
|
|
query PersonParticipations($actorId: ID!, $eventId: ID) {
|
|
|
|
person(id: $actorId) {
|
|
|
|
participations(eventId: $eventId) {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
},
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
test "actor_leave_event/3 should delete a participant from an event", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
2019-12-03 11:29:51 +01:00
|
|
|
event =
|
|
|
|
insert(:event, %{organizer_actor: actor, participant_stats: %{creator: 1, participant: 1}})
|
|
|
|
|
2019-09-26 16:38:58 +02:00
|
|
|
insert(:participant, %{actor: actor, event: event, role: :creator})
|
|
|
|
user2 = insert(:user)
|
|
|
|
actor2 = insert(:actor, user: user2)
|
|
|
|
participant2 = insert(:participant, %{event: event, actor: actor2, role: :participant})
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
leaveEvent(
|
2019-09-26 16:38:58 +02:00
|
|
|
actor_id: #{participant2.actor.id},
|
2019-02-07 17:57:49 +01:00
|
|
|
event_id: #{event.id}
|
2019-02-01 15:38:35 +01:00
|
|
|
) {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2019-09-26 16:38:58 +02:00
|
|
|
|> auth_conn(user2)
|
2019-02-01 15:38:35 +01:00
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
2019-09-09 09:31:08 +02:00
|
|
|
assert json_response(res, 200)["data"]["leaveEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["leaveEvent"]["actor"]["id"] ==
|
2019-09-26 16:38:58 +02:00
|
|
|
to_string(participant2.actor.id)
|
2019-02-07 17:57:49 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2019-09-26 16:38:58 +02:00
|
|
|
|> auth_conn(user)
|
2020-06-11 19:13:21 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @person_participations,
|
|
|
|
variables: %{actorId: actor.id, eventId: event.id}
|
|
|
|
)
|
2019-02-07 17:57:49 +01:00
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
assert res["data"]["person"]["participations"]["elements"] == [
|
2019-02-07 17:57:49 +01:00
|
|
|
%{
|
2019-09-26 16:38:58 +02:00
|
|
|
"event" => %{
|
|
|
|
"uuid" => event.uuid,
|
|
|
|
"title" => event.title
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
"role" => "CREATOR"
|
2019-02-07 17:57:49 +01:00
|
|
|
}
|
|
|
|
]
|
2019-09-26 16:38:58 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user2)
|
2020-06-11 19:13:21 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @person_participations,
|
|
|
|
variables: %{actorId: actor2.id, eventId: event.id}
|
|
|
|
)
|
2019-09-26 16:38:58 +02:00
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
assert res["data"]["person"]["participations"]["elements"] == []
|
2019-02-07 17:57:49 +01:00
|
|
|
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})
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
# 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"
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "actor_leave_event/3 should check the user is logged in", %{conn: conn, actor: actor} do
|
|
|
|
participant = insert(:participant, %{actor: actor})
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
leaveEvent(
|
|
|
|
actor_id: #{participant.actor.id},
|
|
|
|
event_id: #{participant.event.id}
|
|
|
|
) {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "actor_leave_event/3 should check the actor is owned by the user", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
participant = insert(:participant)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
leaveEvent(
|
|
|
|
actor_id: #{participant.actor.id},
|
|
|
|
event_id: #{participant.event.id}
|
|
|
|
) {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "actor_leave_event/3 should check the participant exists", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
|
|
|
actor: actor
|
|
|
|
} do
|
2019-08-14 17:45:11 +02:00
|
|
|
event = insert(:event)
|
2019-02-01 15:38:35 +01:00
|
|
|
participant = insert(:participant, %{actor: actor})
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
leaveEvent(
|
|
|
|
actor_id: #{participant.actor.id},
|
2019-08-14 17:45:11 +02:00
|
|
|
event_id: #{event.id}
|
2019-02-01 15:38:35 +01:00
|
|
|
) {
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "Participant not found"
|
|
|
|
end
|
|
|
|
|
2019-09-26 16:38:58 +02:00
|
|
|
test "list_participants_for_event/3 returns participants for an event", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
2019-02-01 15:38:35 +01:00
|
|
|
event =
|
|
|
|
@event
|
2019-09-26 16:38:58 +02:00
|
|
|
|> Map.put(:organizer_actor_id, actor.id)
|
2019-02-01 15:38:35 +01:00
|
|
|
|
|
|
|
{:ok, event} = Events.create_event(event)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-09-20 18:22:03 +02:00
|
|
|
event(uuid: "#{event.uuid}") {
|
2020-11-19 17:06:28 +01:00
|
|
|
participants(roles: "participant,moderator,administrator,creator") {
|
2020-03-05 19:32:34 +01:00
|
|
|
elements {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
2019-02-01 15:38:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
2019-09-26 16:38:58 +02:00
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2019-02-01 15:38:35 +01:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
|
|
|
|
|
2019-09-26 16:38:58 +02:00
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participants"]["elements"] == [
|
2019-02-01 15:38:35 +01:00
|
|
|
%{
|
2019-09-02 10:50:00 +02:00
|
|
|
"actor" => %{
|
2019-09-26 16:38:58 +02:00
|
|
|
"preferredUsername" => actor.preferred_username
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
"role" => "CREATOR"
|
2019-02-01 15:38:35 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
# Adding two participants
|
|
|
|
actor2 = insert(:actor)
|
|
|
|
actor3 = insert(:actor)
|
|
|
|
# This one won't get listed (as not approved)
|
2019-02-07 17:57:49 +01:00
|
|
|
insert(:participant, event: event, actor: actor2, role: :not_approved)
|
2019-02-01 15:38:35 +01:00
|
|
|
# This one will (as a participant)
|
|
|
|
participant2 = insert(:participant, event: event, actor: actor3, role: :participant)
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
query = """
|
2020-11-19 17:06:28 +01:00
|
|
|
query EventParticipants($uuid: UUID!, $roles: String, $page: Int, $limit: Int) {
|
2020-02-18 08:57:00 +01:00
|
|
|
event(uuid: $uuid) {
|
2020-11-19 17:06:28 +01:00
|
|
|
participants(page: $page, limit: $limit, roles: $roles) {
|
2020-02-18 08:57:00 +01:00
|
|
|
total,
|
2020-03-05 19:32:34 +01:00
|
|
|
elements {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
res =
|
2019-09-26 16:38:58 +02:00
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-02-18 08:57:00 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: query,
|
|
|
|
variables: %{
|
|
|
|
uuid: event.uuid,
|
|
|
|
roles: "participant,moderator,administrator,creator",
|
|
|
|
page: 1,
|
2020-06-03 15:33:50 +02:00
|
|
|
limit: 2
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
2019-02-01 15:38:35 +01:00
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
sorted_participants =
|
2020-02-18 08:57:00 +01:00
|
|
|
res["data"]["event"]["participants"]["elements"]
|
2020-06-03 15:33:50 +02:00
|
|
|
|> Enum.filter(&(&1["role"] == "CREATOR"))
|
2019-09-02 10:50:00 +02:00
|
|
|
|
|
|
|
assert sorted_participants == [
|
2019-02-01 15:38:35 +01:00
|
|
|
%{
|
2019-09-02 10:50:00 +02:00
|
|
|
"actor" => %{
|
2020-02-18 08:57:00 +01:00
|
|
|
"preferredUsername" => actor.preferred_username
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
"role" => "CREATOR"
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
res =
|
2019-09-26 16:38:58 +02:00
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-02-18 08:57:00 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: query,
|
|
|
|
variables: %{
|
|
|
|
uuid: event.uuid,
|
|
|
|
actorId: actor.id,
|
|
|
|
roles: "participant,moderator,administrator,creator",
|
2020-06-03 15:33:50 +02:00
|
|
|
page: 1,
|
|
|
|
limit: 2
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
2019-09-20 18:22:03 +02:00
|
|
|
|
|
|
|
sorted_participants =
|
2020-02-18 08:57:00 +01:00
|
|
|
res["data"]["event"]["participants"]["elements"]
|
|
|
|
|> Enum.filter(&(&1["role"] == "PARTICIPANT"))
|
2019-09-20 18:22:03 +02:00
|
|
|
|
|
|
|
assert sorted_participants == [
|
2019-08-14 17:45:11 +02:00
|
|
|
%{
|
2019-09-02 10:50:00 +02:00
|
|
|
"actor" => %{
|
2020-02-18 08:57:00 +01:00
|
|
|
"preferredUsername" => participant2.actor.preferred_username
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
"role" => "PARTICIPANT"
|
2019-02-01 15:38:35 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2019-09-11 16:37:30 +02:00
|
|
|
|
|
|
|
test "stats_participants_for_event/3 give the number of (un)approved participants", %{
|
|
|
|
conn: conn,
|
2020-06-15 19:41:11 +02:00
|
|
|
actor: actor,
|
|
|
|
user: user
|
2019-09-11 16:37:30 +02:00
|
|
|
} do
|
|
|
|
event =
|
|
|
|
@event
|
|
|
|
|> Map.put(:organizer_actor_id, actor.id)
|
|
|
|
|
|
|
|
{:ok, event} = Events.create_event(event)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
|
|
|
uuid,
|
|
|
|
participantStats {
|
2019-10-25 17:43:37 +02:00
|
|
|
going,
|
|
|
|
notApproved,
|
2019-09-30 13:48:47 +02:00
|
|
|
rejected
|
2019-09-11 16:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-06-15 19:41:11 +02:00
|
|
|
|> auth_conn(user)
|
2019-09-11 16:37:30 +02:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
2019-10-25 17:43:37 +02:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["going"] == 1
|
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["notApproved"] == 0
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["rejected"] == 0
|
2019-09-11 16:37:30 +02:00
|
|
|
|
|
|
|
moderator = insert(:actor)
|
|
|
|
|
|
|
|
Events.create_participant(%{
|
|
|
|
role: :moderator,
|
|
|
|
event_id: event.id,
|
|
|
|
actor_id: moderator.id
|
|
|
|
})
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
not_approved = insert(:actor)
|
2019-09-11 16:37:30 +02:00
|
|
|
|
|
|
|
Events.create_participant(%{
|
|
|
|
role: :not_approved,
|
|
|
|
event_id: event.id,
|
2019-10-25 17:43:37 +02:00
|
|
|
actor_id: not_approved.id
|
2019-09-11 16:37:30 +02:00
|
|
|
})
|
|
|
|
|
2019-11-04 15:10:58 +01:00
|
|
|
rejected = insert(:actor)
|
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
Events.create_participant(%{
|
|
|
|
role: :rejected,
|
|
|
|
event_id: event.id,
|
2019-11-04 15:10:58 +01:00
|
|
|
actor_id: rejected.id
|
2019-09-30 13:48:47 +02:00
|
|
|
})
|
|
|
|
|
2019-09-11 16:37:30 +02:00
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
|
|
|
uuid,
|
|
|
|
participantStats {
|
2019-10-25 17:43:37 +02:00
|
|
|
going,
|
|
|
|
notApproved,
|
2019-09-30 13:48:47 +02:00
|
|
|
rejected
|
2019-09-11 16:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-06-15 19:41:11 +02:00
|
|
|
|> auth_conn(user)
|
2019-09-11 16:37:30 +02:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
2019-10-25 17:43:37 +02:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["going"] == 2
|
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["notApproved"] == 1
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participantStats"]["rejected"] == 1
|
2020-06-15 19:41:11 +02:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
|
|
|
uuid,
|
|
|
|
participantStats {
|
|
|
|
going,
|
|
|
|
notApproved,
|
|
|
|
rejected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
|
|
|
|
assert is_nil(json_response(res, 200)["errors"])
|
|
|
|
assert json_response(res, 200)["data"]["event"]["going"] == nil
|
2019-09-11 16:37:30 +02:00
|
|
|
end
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
describe "Participation role status update" do
|
|
|
|
test "update_participation/3", %{conn: conn, actor: actor, user: user} do
|
2019-09-20 18:22:03 +02:00
|
|
|
user_creator = insert(:user)
|
|
|
|
actor_creator = insert(:actor, user: user_creator)
|
|
|
|
event = insert(:event, join_options: :restricted, organizer_actor: actor_creator)
|
|
|
|
insert(:participant, event: event, actor: actor_creator, role: :creator)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
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"]["joinEvent"]["role"] == "NOT_APPROVED"
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == to_string(actor.id)
|
|
|
|
participation_id = json_response(res, 200)["data"]["joinEvent"]["id"]
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-09-30 13:48:47 +02:00
|
|
|
updateParticipation(
|
2019-09-20 18:22:03 +02:00
|
|
|
id: "#{participation_id}",
|
2019-09-30 13:48:47 +02:00
|
|
|
role: PARTICIPANT,
|
2019-09-20 18:22:03 +02:00
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["role"] == "PARTICIPANT"
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["event"]["id"] ==
|
2019-09-20 18:22:03 +02:00
|
|
|
to_string(event.id)
|
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["actor"]["id"] ==
|
2019-09-20 18:22:03 +02:00
|
|
|
to_string(actor.id)
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
participation = Events.get_participant(participation_id)
|
2019-09-30 13:48:47 +02:00
|
|
|
|
|
|
|
assert_delivered_email(Email.Participation.participation_updated(user, participation))
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Participant already has role participant"
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "accept_participation/3 with bad parameters", %{conn: conn, actor: actor, user: user} do
|
|
|
|
user_creator = insert(:user)
|
2020-11-19 17:06:28 +01:00
|
|
|
_actor_creator = insert(:actor, user: user_creator)
|
2019-09-20 18:22:03 +02:00
|
|
|
event = insert(:event, join_options: :restricted)
|
|
|
|
insert(:participant, event: event, role: :creator)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
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"]["joinEvent"]["role"] == "NOT_APPROVED"
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == to_string(actor.id)
|
|
|
|
participation_id = json_response(res, 200)["data"]["joinEvent"]["id"]
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-09-30 13:48:47 +02:00
|
|
|
updateParticipation (
|
2019-09-20 18:22:03 +02:00
|
|
|
id: "#{participation_id}",
|
2020-11-19 17:06:28 +01:00
|
|
|
role: PARTICIPANT
|
2019-09-20 18:22:03 +02:00
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2020-09-29 09:53:48 +02:00
|
|
|
"Provided moderator profile doesn't have permission on this event"
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "reject participation" do
|
|
|
|
test "reject_participation/3", %{conn: conn, actor: actor, user: user} do
|
|
|
|
user_creator = insert(:user)
|
|
|
|
actor_creator = insert(:actor, user: user_creator)
|
|
|
|
event = insert(:event, join_options: :restricted, organizer_actor: actor_creator)
|
|
|
|
insert(:participant, event: event, actor: actor_creator, role: :creator)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
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"]["joinEvent"]["role"] == "NOT_APPROVED"
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == to_string(actor.id)
|
|
|
|
participation_id = json_response(res, 200)["data"]["joinEvent"]["id"]
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-09-30 13:48:47 +02:00
|
|
|
updateParticipation(
|
2019-09-20 18:22:03 +02:00
|
|
|
id: "#{participation_id}",
|
2020-11-19 17:06:28 +01:00
|
|
|
role: REJECTED
|
2019-09-20 18:22:03 +02:00
|
|
|
) {
|
|
|
|
id,
|
2019-09-30 13:48:47 +02:00
|
|
|
role,
|
2019-09-20 18:22:03 +02:00
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["id"] == participation_id
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["event"]["id"] ==
|
2019-09-20 18:22:03 +02:00
|
|
|
to_string(event.id)
|
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert json_response(res, 200)["data"]["updateParticipation"]["actor"]["id"] ==
|
2019-09-20 18:22:03 +02:00
|
|
|
to_string(actor.id)
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
participation = Events.get_participant(participation_id)
|
2019-09-30 13:48:47 +02:00
|
|
|
assert_delivered_email(Email.Participation.participation_updated(user, participation))
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-09-30 13:48:47 +02:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Participant already has role rejected"
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "reject_participation/3 with bad parameters", %{conn: conn, actor: actor, user: user} do
|
|
|
|
user_creator = insert(:user)
|
2020-11-19 17:06:28 +01:00
|
|
|
_actor_creator = insert(:actor, user: user_creator)
|
2019-09-20 18:22:03 +02:00
|
|
|
event = insert(:event, join_options: :restricted)
|
|
|
|
insert(:participant, event: event, role: :creator)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
joinEvent(
|
|
|
|
actor_id: #{actor.id},
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
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"]["joinEvent"]["role"] == "NOT_APPROVED"
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert json_response(res, 200)["data"]["joinEvent"]["actor"]["id"] == to_string(actor.id)
|
|
|
|
participation_id = json_response(res, 200)["data"]["joinEvent"]["id"]
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-09-30 13:48:47 +02:00
|
|
|
updateParticipation (
|
2019-09-20 18:22:03 +02:00
|
|
|
id: "#{participation_id}",
|
2020-11-19 17:06:28 +01:00
|
|
|
role: REJECTED
|
2019-09-20 18:22:03 +02:00
|
|
|
) {
|
|
|
|
id,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_creator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2020-09-29 09:53:48 +02:00
|
|
|
"Provided moderator profile doesn't have permission on this event"
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
|
|
|
end
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
describe "Participate with anonymous user" do
|
|
|
|
@email "test@test.tld"
|
|
|
|
@mutation """
|
|
|
|
mutation JoinEvent($actorId: ID!, $eventId: ID!, $email: String) {
|
|
|
|
joinEvent(
|
|
|
|
actorId: $actorId,
|
|
|
|
eventId: $eventId,
|
|
|
|
email: $email
|
|
|
|
) {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
@confirmation_mutation """
|
|
|
|
mutation ConfirmParticipation($confirmationToken: String!) {
|
|
|
|
confirmParticipation(confirmationToken: $confirmationToken) {
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
@cancel_participation_mutation """
|
|
|
|
mutation LeaveEvent($actorId: ID!, $eventId: ID!, $token: String) {
|
|
|
|
leaveEvent(
|
|
|
|
actorId: $actorId,
|
|
|
|
eventId: $eventId,
|
|
|
|
token: $token
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2020-06-27 19:12:45 +02:00
|
|
|
setup do: clear_config([:anonymous, :participation])
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
setup %{conn: conn, actor: actor, user: user} do
|
|
|
|
Mobilizon.Config.clear_config_cache()
|
|
|
|
anonymous_actor_id = Config.anonymous_actor_id()
|
|
|
|
{:ok, conn: conn, actor: actor, user: user, anonymous_actor_id: anonymous_actor_id}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "I can't participate if anonymous participation is enabled on the server but disabled for this event",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: false})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], false)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Anonymous participation is not enabled"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "I can't participate if anonymous participation is enabled on the server and enabled for the event but the event is remote",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true}, local: false)
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], false)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Anonymous participation is not enabled"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "I can't participate without being logged in when using anonymous user and providing no email when required",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], false)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "A valid email is required by your instance"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: "bad_email"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "A valid email is required by your instance"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "I can participate without being logged in when using anonymous user when providing email",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], false)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["joinEvent"]["role"] == "PARTICIPANT"
|
|
|
|
assert res["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert res["data"]["joinEvent"]["actor"]["id"] == to_string(actor_id)
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
%Participant{} =
|
|
|
|
participant = event.id |> Events.list_participants_for_event() |> Map.get(:elements) |> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
assert participant.metadata.email == @email
|
|
|
|
|
|
|
|
# When confirmation_required is false, participant has already the participant role
|
|
|
|
assert participant.role == :participant
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You are already a participant of this event"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Participating without being logged in when using anonymous user and providing email sends a confirmation email",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], true)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
# Not approved until email confirmation
|
|
|
|
assert res["data"]["joinEvent"]["role"] == "NOT_CONFIRMED"
|
|
|
|
assert res["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert res["data"]["joinEvent"]["actor"]["id"] == to_string(actor_id)
|
|
|
|
|
|
|
|
assert %Participant{
|
|
|
|
metadata: %{confirmation_token: confirmation_token},
|
|
|
|
role: :not_confirmed
|
2020-03-05 19:32:34 +01:00
|
|
|
} =
|
|
|
|
participant =
|
|
|
|
event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd()
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
# hack to avoid preloading event in participant
|
|
|
|
participant = Map.put(participant, :event, event)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "You are already a participant of this event"
|
|
|
|
|
|
|
|
assert_delivered_email(
|
|
|
|
Email.Participation.anonymous_participation_confirmation(@email, participant)
|
|
|
|
)
|
|
|
|
|
2020-09-30 10:44:01 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @confirmation_mutation,
|
|
|
|
variables: %{confirmationToken: confirmation_token}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert is_nil(res["errors"])
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
assert %Participant{role: :participant} =
|
2020-09-30 10:44:01 +02:00
|
|
|
participant =
|
2020-03-05 19:32:34 +01:00
|
|
|
event.id |> Events.list_participants_for_event() |> Map.get(:elements) |> hd()
|
2020-09-30 10:44:01 +02:00
|
|
|
|
|
|
|
assert_delivered_email(Email.Participation.participation_updated(@email, participant))
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "I can participate anonymously and and confirm my participation with bad token",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], true)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["joinEvent"]["role"] == "NOT_CONFIRMED"
|
|
|
|
assert res["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert res["data"]["joinEvent"]["actor"]["id"] == to_string(actor_id)
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
%Participant{} =
|
|
|
|
participant =
|
|
|
|
event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
assert participant.metadata.email == @email
|
|
|
|
|
|
|
|
# When confirmation_required is false, participant has already the participant role
|
|
|
|
assert participant.role == :not_confirmed
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @confirmation_mutation,
|
|
|
|
variables: %{confirmationToken: "bad token"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "This token is invalid"
|
|
|
|
|
|
|
|
assert %Participant{role: :not_confirmed} =
|
2020-03-05 19:32:34 +01:00
|
|
|
event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd()
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "I can participate anonymously but change my mind and cancel my participation",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id} do
|
|
|
|
event = insert(:event, options: %{anonymous_participation: true})
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], true)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["joinEvent"]["role"] == "NOT_CONFIRMED"
|
|
|
|
assert res["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert res["data"]["joinEvent"]["actor"]["id"] == to_string(actor_id)
|
|
|
|
|
|
|
|
{:ok, %Event{participant_stats: %{not_confirmed: 1}}} = Events.get_event(event.id)
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
%Participant{} =
|
|
|
|
participant =
|
|
|
|
event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
assert participant.metadata.email == @email
|
|
|
|
|
|
|
|
# When confirmation_required is false, participant has already the participant role
|
|
|
|
assert participant.role == :not_confirmed
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @cancel_participation_mutation,
|
|
|
|
variables: %{
|
|
|
|
actorId: actor_id,
|
|
|
|
eventId: event.id,
|
|
|
|
token: "bad token"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] == "Participant not found"
|
|
|
|
|
|
|
|
assert %Participant{
|
|
|
|
id: participant_id,
|
|
|
|
role: :not_confirmed,
|
|
|
|
metadata: %{cancellation_token: cancellation_token}
|
2020-03-05 19:32:34 +01:00
|
|
|
} = event.id |> Events.list_participants_for_event([]) |> Map.get(:elements) |> hd()
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @cancel_participation_mutation,
|
|
|
|
variables: %{
|
|
|
|
actorId: actor_id,
|
|
|
|
eventId: event.id,
|
|
|
|
token: cancellation_token
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["data"]["leaveEvent"]["id"] == participant_id
|
|
|
|
|
|
|
|
{:ok, %Event{participant_stats: %{not_confirmed: 0}}} = Events.get_event(event.id)
|
2020-03-05 19:32:34 +01:00
|
|
|
assert Events.list_participants_for_event(event.id, []) == %Page{elements: [], total: 0}
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "I can participate anonymously, confirm my participation and then be confirmed by the organizer",
|
|
|
|
%{conn: conn, anonymous_actor_id: actor_id, actor: event_creator_actor, user: user} do
|
|
|
|
event =
|
|
|
|
insert(:event,
|
|
|
|
options: %{anonymous_participation: true},
|
|
|
|
join_options: :restricted,
|
|
|
|
organizer_actor: event_creator_actor,
|
|
|
|
participant_stats: %{creator: 1}
|
|
|
|
)
|
|
|
|
|
|
|
|
insert(:participant, event: event, actor: event_creator_actor, role: :creator)
|
|
|
|
Config.put([:anonymous, :participation, :allowed], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :enabled], true)
|
|
|
|
Config.put([:anonymous, :participation, :validation, :email, :confirmation_required], true)
|
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%Event{
|
|
|
|
participant_stats: %EventParticipantStats{
|
|
|
|
not_confirmed: 0,
|
|
|
|
not_approved: 0,
|
|
|
|
creator: 1,
|
|
|
|
participant: 0
|
|
|
|
}
|
|
|
|
}} = Events.get_event(event.id)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @mutation,
|
|
|
|
variables: %{actorId: actor_id, eventId: event.id, email: @email}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["joinEvent"]["role"] == "NOT_CONFIRMED"
|
|
|
|
assert res["data"]["joinEvent"]["event"]["id"] == to_string(event.id)
|
|
|
|
assert res["data"]["joinEvent"]["actor"]["id"] == to_string(actor_id)
|
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%Event{
|
|
|
|
participant_stats: %EventParticipantStats{
|
|
|
|
not_confirmed: 1,
|
|
|
|
not_approved: 0,
|
|
|
|
creator: 1,
|
|
|
|
participant: 0
|
|
|
|
}
|
|
|
|
}} = Events.get_event(event.id)
|
|
|
|
|
|
|
|
assert %Participant{
|
|
|
|
role: :not_confirmed,
|
|
|
|
metadata: %{confirmation_token: confirmation_token, email: @email}
|
2020-02-18 08:57:00 +01:00
|
|
|
} =
|
|
|
|
event.id
|
|
|
|
|> Events.list_participants_for_event([:not_confirmed])
|
|
|
|
|> Map.get(:elements)
|
|
|
|
|> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @confirmation_mutation,
|
|
|
|
variables: %{confirmationToken: confirmation_token}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%Event{
|
|
|
|
participant_stats: %EventParticipantStats{
|
|
|
|
not_confirmed: 0,
|
|
|
|
not_approved: 1,
|
|
|
|
creator: 1,
|
|
|
|
participant: 0
|
|
|
|
}
|
|
|
|
}} = Events.get_event(event.id)
|
|
|
|
|
|
|
|
assert %Participant{role: :not_approved, id: participant_id} =
|
2020-02-18 08:57:00 +01:00
|
|
|
event.id
|
|
|
|
|> Events.list_participants_for_event([:not_approved])
|
|
|
|
|> Map.get(:elements)
|
|
|
|
|> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
update_participation_mutation = """
|
2020-11-19 17:06:28 +01:00
|
|
|
mutation UpdateParticipation($participantId: ID!, $role: ParticipantRoleEnum!) {
|
|
|
|
updateParticipation(id: $participantId, role: $role) {
|
2019-12-20 13:04:34 +01:00
|
|
|
id,
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: update_participation_mutation,
|
|
|
|
variables: %{
|
|
|
|
participantId: participant_id,
|
2020-11-19 17:06:28 +01:00
|
|
|
role: "PARTICIPANT"
|
2019-12-20 13:04:34 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
|
|
|
|
assert %Participant{role: :participant} =
|
2020-02-18 08:57:00 +01:00
|
|
|
event.id
|
|
|
|
|> Events.list_participants_for_event([:participant])
|
|
|
|
|> Map.get(:elements)
|
|
|
|
|> hd
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%Event{
|
|
|
|
participant_stats: %EventParticipantStats{
|
|
|
|
not_confirmed: 0,
|
|
|
|
not_approved: 0,
|
|
|
|
creator: 1,
|
|
|
|
participant: 1
|
|
|
|
}
|
|
|
|
}} = Events.get_event(event.id)
|
|
|
|
|
|
|
|
participant = Events.get_participant(participant_id)
|
|
|
|
assert_delivered_email(Email.Participation.participation_updated(@email, participant))
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|