2019-02-01 15:38:35 +01:00
|
|
|
defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
|
|
|
use MobilizonWeb.ConnCase
|
2019-09-30 13:48:47 +02:00
|
|
|
use Bamboo.Test
|
2019-02-01 15:38:35 +01:00
|
|
|
alias Mobilizon.Events
|
2019-09-30 13:48:47 +02:00
|
|
|
alias MobilizonWeb.{AbsintheHelpers, Email}
|
2019-02-01 15:38:35 +01:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-06 15:23:58 +02:00
|
|
|
person(id: "#{actor.id}") {
|
2019-09-26 16:38:58 +02:00
|
|
|
participations(eventId: "#{event.id}") {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
},
|
|
|
|
role
|
2019-09-20 18:22:03 +02:00
|
|
|
}
|
2019-02-07 17:57:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2019-09-26 16:38:58 +02:00
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2019-02-07 17:57:49 +01:00
|
|
|
|
2019-09-26 16:38:58 +02:00
|
|
|
assert json_response(res, 200)["data"]["person"]["participations"] == [
|
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
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-06 15:23:58 +02:00
|
|
|
person(id: "#{actor2.id}") {
|
2019-09-26 16:38:58 +02:00
|
|
|
participations(eventId: "#{event.id}") {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
},
|
|
|
|
role
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user2)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["person"]["participations"] == []
|
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}") {
|
2019-09-26 16:38:58 +02:00
|
|
|
participants(roles: "participant,moderator,administrator,creator", actor_id: "#{
|
|
|
|
actor.id
|
|
|
|
}") {
|
2019-09-20 18:22:03 +02:00
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
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
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
assert json_response(res, 200)["data"]["event"]["participants"] == [
|
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 = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
2019-11-04 15:10:58 +01:00
|
|
|
participants(page: 2, limit: 1, roles: "participant,moderator,administrator,creator", actorId: "#{
|
2019-09-26 16:38:58 +02:00
|
|
|
actor.id
|
|
|
|
}") {
|
2019-09-20 18:22:03 +02:00
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
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-02 10:50:00 +02:00
|
|
|
sorted_participants =
|
2019-09-20 18:22:03 +02:00
|
|
|
json_response(res, 200)["data"]["event"]["participants"]
|
2019-11-04 15:10:58 +01:00
|
|
|
|> Enum.filter(&(&1["role"] == "PARTICIPANT"))
|
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" => %{
|
2019-09-20 18:22:03 +02:00
|
|
|
"preferredUsername" => participant2.actor.preferred_username
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
2019-09-20 18:22:03 +02:00
|
|
|
"role" => "PARTICIPANT"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
2019-11-04 15:10:58 +01:00
|
|
|
participants(page: 1, limit: 1, roles: "participant,moderator,administrator,creator", actorId: "#{
|
2019-09-26 16:38:58 +02:00
|
|
|
actor.id
|
|
|
|
}") {
|
2019-09-20 18:22:03 +02:00
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
2019-09-26 16:38:58 +02:00
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2019-09-20 18:22:03 +02:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
|
|
|
|
|
|
|
|
sorted_participants =
|
|
|
|
json_response(res, 200)["data"]["event"]["participants"]
|
|
|
|
|> Enum.sort_by(
|
|
|
|
&(&1
|
|
|
|
|> Map.get("actor")
|
|
|
|
|> Map.get("preferredUsername"))
|
|
|
|
)
|
|
|
|
|
|
|
|
assert sorted_participants == [
|
2019-08-14 17:45:11 +02: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
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2019-09-11 16:37:30 +02:00
|
|
|
|
|
|
|
test "stats_participants_for_event/3 give the number of (un)approved participants", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor
|
|
|
|
} 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
|
|
|
|
|> 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
|
|
|
|
|> 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
|
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
|
|
|
moderator_actor_id: #{actor_creator.id}
|
|
|
|
) {
|
|
|
|
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-09-30 13:48:47 +02:00
|
|
|
participation = Mobilizon.Events.get_participant(participation_id)
|
|
|
|
|
|
|
|
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)
|
|
|
|
actor_creator = insert(:actor, user: user_creator)
|
|
|
|
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}",
|
2019-09-30 13:48:47 +02:00
|
|
|
role: PARTICIPANT,
|
2019-09-20 18:22:03 +02:00
|
|
|
moderator_actor_id: #{actor_creator.id}
|
|
|
|
) {
|
|
|
|
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"] ==
|
|
|
|
"Provided moderator actor ID doesn't have permission on this event"
|
|
|
|
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}",
|
2019-09-30 13:48:47 +02:00
|
|
|
role: REJECTED,
|
2019-09-20 18:22:03 +02:00
|
|
|
moderator_actor_id: #{actor_creator.id}
|
|
|
|
) {
|
|
|
|
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-09-30 13:48:47 +02:00
|
|
|
participation = Mobilizon.Events.get_participant(participation_id)
|
|
|
|
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)
|
|
|
|
actor_creator = insert(:actor, user: user_creator)
|
|
|
|
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}",
|
2019-09-30 13:48:47 +02:00
|
|
|
role: REJECTED,
|
2019-09-20 18:22:03 +02:00
|
|
|
moderator_actor_id: #{actor_creator.id}
|
|
|
|
) {
|
|
|
|
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"] ==
|
|
|
|
"Provided moderator actor ID doesn't have permission on this event"
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|