2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Resolvers.EventTest do
|
|
|
|
use Mobilizon.Web.ConnCase
|
2021-11-10 20:31:29 +01:00
|
|
|
use Bamboo.Test, shared: true
|
2019-11-04 15:10:58 +01:00
|
|
|
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
2020-01-23 00:55:07 +01:00
|
|
|
|
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.{Events, Users}
|
|
|
|
alias Mobilizon.Events.Event
|
2020-01-23 00:55:07 +01:00
|
|
|
alias Mobilizon.Service.Workers
|
2021-07-26 17:23:42 +02:00
|
|
|
alias Mobilizon.Users.User
|
2020-01-23 00:55:07 +01:00
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Email
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2019-01-24 15:23:27 +01:00
|
|
|
@event %{
|
|
|
|
description: "some body",
|
|
|
|
title: "some title",
|
2019-02-14 14:19:55 +01:00
|
|
|
begins_on: DateTime.utc_now() |> DateTime.truncate(:second),
|
2019-01-24 15:23:27 +01:00
|
|
|
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
|
2019-02-22 16:54:01 +01:00
|
|
|
url: "some url",
|
|
|
|
category: "meeting"
|
2019-01-24 15:23:27 +01:00
|
|
|
}
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
@find_event_query """
|
|
|
|
query Event($uuid: UUID!) {
|
|
|
|
event(uuid: $uuid) {
|
|
|
|
uuid,
|
|
|
|
draft
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
setup %{conn: conn} do
|
2019-01-25 13:59:58 +01:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user, preferred_username: "test")
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2018-11-29 17:43:22 +01:00
|
|
|
{:ok, conn: conn, actor: actor, user: user}
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "Find an event" do
|
2018-11-06 10:30:27 +01:00
|
|
|
test "find_event/3 returns an event", context do
|
|
|
|
event =
|
|
|
|
@event
|
|
|
|
|> Map.put(:organizer_actor_id, context.actor.id)
|
|
|
|
|
|
|
|
{:ok, event} = Events.create_event(event)
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(query: @find_event_query, variables: %{uuid: event.uuid})
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["data"]["event"]["uuid"] == to_string(event.uuid)
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @find_event_query, variables: %{uuid: "bad uuid"})
|
|
|
|
|
|
|
|
assert [%{"message" => "Argument \"uuid\" has invalid value $uuid."}] = res["errors"]
|
2018-11-06 10:30:27 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @find_event_query,
|
|
|
|
variables: %{uuid: "b5126423-f1af-43e4-a923-002a03003ba5"}
|
|
|
|
)
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2020-10-01 15:07:15 +02:00
|
|
|
assert [%{"message" => "Event not found"}] = res["errors"]
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|
2021-07-26 17:23:42 +02:00
|
|
|
end
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "create_event/3 for a regular profile" do
|
2020-06-05 11:38:49 +02:00
|
|
|
@create_event_mutation """
|
|
|
|
mutation CreateEvent(
|
|
|
|
$title: String!,
|
|
|
|
$description: String,
|
|
|
|
$begins_on: DateTime!,
|
|
|
|
$ends_on: DateTime,
|
|
|
|
$status: EventStatus,
|
|
|
|
$visibility: EventVisibility,
|
|
|
|
$organizer_actor_id: ID!,
|
2021-07-26 17:23:42 +02:00
|
|
|
$attributed_to_id: ID,
|
2020-06-05 11:38:49 +02:00
|
|
|
$online_address: String,
|
|
|
|
$options: EventOptionsInput,
|
2021-08-19 20:43:35 +02:00
|
|
|
$draft: Boolean,
|
|
|
|
$language: String
|
2020-06-05 11:38:49 +02:00
|
|
|
) {
|
|
|
|
createEvent(
|
|
|
|
title: $title,
|
|
|
|
description: $description,
|
|
|
|
begins_on: $begins_on,
|
|
|
|
ends_on: $ends_on,
|
|
|
|
status: $status,
|
|
|
|
visibility: $visibility,
|
|
|
|
organizer_actor_id: $organizer_actor_id,
|
2021-07-26 17:23:42 +02:00
|
|
|
attributed_to_id: $attributed_to_id,
|
2020-06-05 11:38:49 +02:00
|
|
|
online_address: $online_address,
|
|
|
|
options: $options,
|
2021-08-19 20:43:35 +02:00
|
|
|
draft: $draft,
|
|
|
|
language: $language
|
2020-06-05 11:38:49 +02:00
|
|
|
) {
|
|
|
|
id,
|
|
|
|
uuid,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
begins_on,
|
|
|
|
ends_on,
|
|
|
|
status,
|
|
|
|
visibility,
|
|
|
|
organizer_actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
online_address,
|
|
|
|
phone_address,
|
|
|
|
category,
|
2021-08-19 20:43:35 +02:00
|
|
|
draft
|
|
|
|
language
|
2020-06-05 11:38:49 +02:00
|
|
|
options {
|
|
|
|
maximumAttendeeCapacity,
|
|
|
|
showRemainingAttendeeCapacity,
|
|
|
|
showEndTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-09-02 17:23:00 +02:00
|
|
|
test "create_event/3 should check the organizer_actor_id is owned by the user", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
another_actor = insert(:actor)
|
|
|
|
|
|
|
|
begins_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "#{begins_on}",
|
|
|
|
organizer_actor_id: "#{another_actor.id}"
|
|
|
|
}
|
|
|
|
)
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["data"]["createEvent"] == nil
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2020-09-29 09:53:48 +02:00
|
|
|
"Organizer profile is not owned by the user"
|
2019-09-02 17:23:00 +02:00
|
|
|
end
|
|
|
|
|
2019-11-18 18:40:03 +01:00
|
|
|
test "create_event/3 should check that end time is after start time", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
begins_on = DateTime.utc_now() |> DateTime.truncate(:second)
|
2020-06-05 11:38:49 +02:00
|
|
|
ends_on = DateTime.add(begins_on, -2 * 3600)
|
2019-11-18 18:40:03 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "#{begins_on}",
|
|
|
|
ends_on: "#{ends_on}",
|
|
|
|
organizer_actor_id: "#{actor.id}"
|
|
|
|
}
|
|
|
|
)
|
2019-11-18 18:40:03 +01:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2020-10-01 15:07:15 +02:00
|
|
|
["ends_on cannot be set before begins_on"]
|
2019-11-18 18:40:03 +01:00
|
|
|
end
|
|
|
|
|
2018-11-29 17:43:22 +01:00
|
|
|
test "create_event/3 creates an event", %{conn: conn, actor: actor, user: user} do
|
2021-11-10 20:31:29 +01:00
|
|
|
begins_on = DateTime.utc_now()
|
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
res =
|
|
|
|
conn
|
2018-11-29 17:43:22 +01:00
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
2021-11-10 20:31:29 +01:00
|
|
|
begins_on: "#{DateTime.add(begins_on, 3600 * 24)}",
|
2020-06-05 11:38:49 +02:00
|
|
|
organizer_actor_id: "#{actor.id}"
|
|
|
|
}
|
|
|
|
)
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["data"]["createEvent"]["title"] == "come to my event"
|
2021-11-10 20:31:29 +01:00
|
|
|
id = String.to_integer(res["data"]["createEvent"]["id"])
|
|
|
|
uuid = res["data"]["createEvent"]["uuid"]
|
2020-01-23 21:59:50 +01:00
|
|
|
|
|
|
|
assert_enqueued(
|
|
|
|
worker: Workers.BuildSearch,
|
|
|
|
args: %{event_id: id, op: :insert_search_event}
|
|
|
|
)
|
2021-11-10 20:31:29 +01:00
|
|
|
|
|
|
|
assert_enqueued(
|
|
|
|
worker: Workers.EventDelayedNotificationWorker,
|
|
|
|
args: %{event_uuid: uuid, action: :notify_of_new_event},
|
|
|
|
scheduled_at: {DateTime.add(begins_on, 1800), delta: 5}
|
|
|
|
)
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|
|
|
|
|
2020-06-24 16:33:59 +02:00
|
|
|
test "create_event/3 creates an event and escapes title", %{
|
2019-10-16 19:03:31 +02:00
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
2020-06-05 11:38:49 +02:00
|
|
|
query: @create_event_mutation,
|
2019-10-16 19:03:31 +02:00
|
|
|
variables: %{
|
|
|
|
title:
|
|
|
|
"My Event title <img src=\"http://placekitten.com/g/200/300\" onclick=\"alert('aaa')\" >",
|
|
|
|
description:
|
|
|
|
"<b>My description</b> <img src=\"http://placekitten.com/g/200/300\" onclick=\"alert('aaa')\" >",
|
|
|
|
begins_on: DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601(),
|
|
|
|
organizer_actor_id: "#{actor.id}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
2020-06-24 16:33:59 +02:00
|
|
|
|
|
|
|
assert res["data"]["createEvent"]["title"] ==
|
|
|
|
"My Event title <img src=\"http://placekitten.com/g/200/300\" onclick=\"alert('aaa')\" >"
|
2019-10-16 19:03:31 +02:00
|
|
|
|
|
|
|
assert res["data"]["createEvent"]["description"] ==
|
2020-02-18 08:57:00 +01:00
|
|
|
"<b>My description</b> <img src=\"http://placekitten.com/g/200/300\"/>"
|
2019-11-04 15:10:58 +01:00
|
|
|
|
|
|
|
{id, ""} = res["data"]["createEvent"]["id"] |> Integer.parse()
|
2020-01-23 21:59:50 +01:00
|
|
|
|
|
|
|
assert_enqueued(
|
|
|
|
worker: Workers.BuildSearch,
|
|
|
|
args: %{event_id: id, op: :insert_search_event}
|
|
|
|
)
|
2019-10-16 19:03:31 +02:00
|
|
|
end
|
|
|
|
|
2019-10-02 17:59:07 +02:00
|
|
|
test "create_event/3 creates an event as a draft", %{conn: conn, actor: actor, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "#{DateTime.utc_now()}",
|
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
draft: true
|
|
|
|
}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["data"]["createEvent"]["title"] == "come to my event"
|
|
|
|
assert res["data"]["createEvent"]["draft"] == true
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
event_uuid = res["data"]["createEvent"]["uuid"]
|
|
|
|
event_id = res["data"]["createEvent"]["id"]
|
2019-11-04 15:10:58 +01:00
|
|
|
{event_id_int, ""} = Integer.parse(event_id)
|
|
|
|
|
|
|
|
refute_enqueued(
|
2020-01-23 00:55:07 +01:00
|
|
|
worker: Workers.BuildSearch,
|
2019-11-04 15:10:58 +01:00
|
|
|
args: %{event_id: event_id_int, op: :insert_search_event}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(query: @find_event_query, variables: %{uuid: event_uuid})
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert hd(res["errors"])["message"] =~ "not found"
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(query: @find_event_query, variables: %{uuid: event_uuid})
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["event"]["draft"] == true
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
query = """
|
2020-06-05 11:38:49 +02:00
|
|
|
query Person($actor_id: ID!, $event_id: ID) {
|
|
|
|
person(id: $actor_id) {
|
2019-10-02 17:59:07 +02:00
|
|
|
id,
|
2020-06-05 11:38:49 +02:00
|
|
|
participations(eventId: $event_id) {
|
2020-06-11 19:13:21 +02:00
|
|
|
elements {
|
|
|
|
id,
|
|
|
|
role,
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
2019-10-02 17:59:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-11 19:13:21 +02:00
|
|
|
}
|
2019-10-02 17:59:07 +02:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: query,
|
|
|
|
variables: %{actor_id: actor.id, event_id: event_id}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["errors"] == nil
|
2020-06-11 19:13:21 +02:00
|
|
|
assert res["data"]["person"]["participations"]["elements"] == []
|
2019-10-02 17:59:07 +02:00
|
|
|
end
|
|
|
|
|
2019-08-28 11:28:27 +02:00
|
|
|
test "create_event/3 creates an event with options", %{conn: conn, actor: actor, user: user} do
|
2019-09-16 15:11:43 +02:00
|
|
|
begins_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
|
|
|
ends_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
|
|
|
|
2019-08-28 11:28:27 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2020-06-05 11:38:49 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "#{begins_on}",
|
|
|
|
ends_on: "#{ends_on}",
|
|
|
|
status: "TENTATIVE",
|
|
|
|
visibility: "UNLISTED",
|
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
online_address: "toto@example.com",
|
|
|
|
options: %{
|
|
|
|
maximumAttendeeCapacity: 30,
|
|
|
|
showRemainingAttendeeCapacity: true,
|
|
|
|
showEndTime: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2019-08-28 11:28:27 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
assert res["errors"] == nil
|
2019-08-28 11:28:27 +02:00
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
event = res["data"]["createEvent"]
|
2019-09-16 15:11:43 +02:00
|
|
|
|
|
|
|
assert event["title"] == "come to my event"
|
|
|
|
assert event["description"] == "it will be fine"
|
|
|
|
assert event["begins_on"] == begins_on
|
|
|
|
assert event["ends_on"] == ends_on
|
2019-09-23 10:26:23 +02:00
|
|
|
assert event["status"] == "TENTATIVE"
|
|
|
|
assert event["visibility"] == "UNLISTED"
|
2019-09-16 15:11:43 +02:00
|
|
|
assert event["organizer_actor"]["id"] == "#{actor.id}"
|
2019-09-23 10:26:23 +02:00
|
|
|
assert event["online_address"] == "toto@example.com"
|
2019-09-16 15:11:43 +02:00
|
|
|
assert event["options"]["maximumAttendeeCapacity"] == 30
|
|
|
|
assert event["options"]["showRemainingAttendeeCapacity"] == true
|
2019-10-14 19:29:18 +02:00
|
|
|
assert event["options"]["showEndTime"] == false
|
2019-11-04 15:10:58 +01:00
|
|
|
{event_id_int, ""} = Integer.parse(event["id"])
|
|
|
|
|
|
|
|
assert_enqueued(
|
2020-01-23 00:55:07 +01:00
|
|
|
worker: Workers.BuildSearch,
|
2019-11-04 15:10:58 +01:00
|
|
|
args: %{event_id: event_id_int, op: :insert_search_event}
|
|
|
|
)
|
2019-08-28 11:28:27 +02:00
|
|
|
end
|
|
|
|
|
2020-06-05 11:38:49 +02:00
|
|
|
test "create_event/3 creates an event an invalid options", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
begins_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "#{begins_on}",
|
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
options: %{
|
|
|
|
maximumAttendeeCapacity: -5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-10-01 15:07:15 +02:00
|
|
|
assert hd(res["errors"])["message"] == %{
|
2021-07-27 19:47:54 +02:00
|
|
|
"maximum_attendee_capacity" => ["must be greater than or equal to 0"]
|
2020-10-01 15:07:15 +02:00
|
|
|
}
|
2020-06-05 11:38:49 +02:00
|
|
|
end
|
|
|
|
|
2019-07-26 11:30:28 +02:00
|
|
|
test "create_event/3 creates an event with tags", %{conn: conn, actor: actor, user: user} do
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createEvent(
|
|
|
|
title: "my event is referenced",
|
|
|
|
description: "with tags!",
|
2021-06-07 16:39:44 +02:00
|
|
|
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
|
2019-07-26 11:30:28 +02:00
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
category: "birthday",
|
|
|
|
tags: ["nicolas", "birthday", "bad tag"]
|
|
|
|
) {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
tags {
|
|
|
|
title,
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["tags"] == [
|
|
|
|
%{"slug" => "nicolas", "title" => "nicolas"},
|
|
|
|
%{"slug" => "birthday", "title" => "birthday"},
|
|
|
|
%{"slug" => "bad-tag", "title" => "bad tag"}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-07-30 10:35:29 +02:00
|
|
|
test "create_event/3 creates an event with an address", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
2019-10-25 17:43:37 +02:00
|
|
|
address = %{street: "I am a street, please believe me", locality: "Where ever"}
|
2019-07-30 10:35:29 +02:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createEvent(
|
|
|
|
title: "my event is referenced",
|
|
|
|
description: "with tags!",
|
2021-06-07 16:39:44 +02:00
|
|
|
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
|
2019-07-30 10:35:29 +02:00
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
category: "birthday",
|
|
|
|
physical_address: {
|
|
|
|
street: "#{address.street}",
|
|
|
|
locality: "#{address.locality}"
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
physicalAddress {
|
2019-10-25 17:43:37 +02:00
|
|
|
id,
|
2019-07-30 10:35:29 +02:00
|
|
|
url,
|
|
|
|
geom,
|
|
|
|
street
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] ==
|
|
|
|
address.street
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
address_url = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"]
|
|
|
|
address_id = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"]
|
2019-07-30 10:35:29 +02:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createEvent(
|
|
|
|
title: "my event is referenced",
|
|
|
|
description: "with tags!",
|
2021-06-07 16:39:44 +02:00
|
|
|
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
|
2019-07-30 10:35:29 +02:00
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
category: "birthday",
|
|
|
|
physical_address: {
|
2019-10-25 17:43:37 +02:00
|
|
|
id: "#{address_id}"
|
2019-07-30 10:35:29 +02:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
physicalAddress {
|
2019-10-25 17:43:37 +02:00
|
|
|
id,
|
2019-07-30 10:35:29 +02:00
|
|
|
url,
|
|
|
|
geom,
|
|
|
|
street
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] ==
|
|
|
|
address.street
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"] ==
|
|
|
|
address_id
|
|
|
|
|
2019-07-30 10:35:29 +02:00
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"] ==
|
2019-10-25 17:43:37 +02:00
|
|
|
address_url
|
2019-07-30 10:35:29 +02:00
|
|
|
end
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
test "create_event/3 creates an event with an attached picture", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createEvent(
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
2021-06-07 16:39:44 +02:00
|
|
|
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
|
2019-05-22 14:12:11 +02:00
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
category: "birthday",
|
|
|
|
picture: {
|
2020-11-26 11:41:13 +01:00
|
|
|
media: {
|
2019-05-22 14:12:11 +02:00
|
|
|
name: "picture for my event",
|
|
|
|
alt: "A very sunny landscape",
|
2019-05-31 17:58:03 +02:00
|
|
|
file: "event.jpg",
|
|
|
|
actor_id: #{actor.id}
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
picture {
|
|
|
|
name,
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
map = %{
|
|
|
|
"query" => mutation,
|
|
|
|
"event.jpg" => %Plug.Upload{
|
|
|
|
path: "test/fixtures/picture.png",
|
|
|
|
filename: "event.jpg"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post("/api", map)
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["picture"]["name"] ==
|
|
|
|
"picture for my event"
|
|
|
|
end
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
test "create_event/3 creates an event with an picture ID", %{
|
2019-05-22 14:12:11 +02:00
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
2020-11-26 11:41:13 +01:00
|
|
|
media = %{name: "my pic", alt: "represents something", file: "picture.png"}
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
mutation = """
|
2020-11-26 11:41:13 +01:00
|
|
|
mutation { uploadMedia (
|
|
|
|
name: "#{media.name}",
|
|
|
|
alt: "#{media.alt}",
|
|
|
|
file: "#{media.file}"
|
2019-05-22 14:12:11 +02:00
|
|
|
) {
|
|
|
|
id,
|
|
|
|
url,
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
map = %{
|
|
|
|
"query" => mutation,
|
2020-11-26 11:41:13 +01:00
|
|
|
media.file => %Plug.Upload{
|
2019-05-22 14:12:11 +02:00
|
|
|
path: "test/fixtures/picture.png",
|
2020-11-26 11:41:13 +01:00
|
|
|
filename: media.file
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post(
|
|
|
|
"/api",
|
|
|
|
map
|
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
assert json_response(res, 200)["data"]["uploadMedia"]["name"] == media.name
|
|
|
|
media_id = json_response(res, 200)["data"]["uploadMedia"]["id"]
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createEvent(
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
2021-06-07 16:39:44 +02:00
|
|
|
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
|
2019-05-22 14:12:11 +02:00
|
|
|
organizer_actor_id: "#{actor.id}",
|
|
|
|
category: "birthday",
|
|
|
|
picture: {
|
2020-11-26 11:41:13 +01:00
|
|
|
media_id: "#{media_id}"
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
picture {
|
|
|
|
name,
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event"
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["picture"]["name"] == media.name
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createEvent"]["picture"]["url"]
|
|
|
|
end
|
2021-08-19 20:43:35 +02:00
|
|
|
|
|
|
|
test "create_event/3 creates an event with detected language", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: %Actor{id: actor_id},
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "Come to my event",
|
|
|
|
description: "This should be long enough to get detected",
|
|
|
|
organizer_actor_id: actor_id,
|
|
|
|
begins_on: "2021-07-26T09:00:00Z"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["createEvent"]["language"] == "en"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_event/3 creates an event with manually set language", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: %Actor{id: actor_id},
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
title: "Come to my event",
|
|
|
|
description: "This should be long enough to get detected",
|
|
|
|
organizer_actor_id: actor_id,
|
|
|
|
begins_on: "2021-07-26T09:00:00Z",
|
|
|
|
language: "it"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["createEvent"]["language"] == "it"
|
|
|
|
end
|
2021-07-26 17:23:42 +02:00
|
|
|
end
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "create_event/3 on behalf of a group" do
|
|
|
|
@variables %{
|
|
|
|
title: "come to my event",
|
|
|
|
description: "it will be fine",
|
|
|
|
begins_on: "2021-07-26T09:00:00Z"
|
|
|
|
}
|
|
|
|
|
|
|
|
test "create_event/3 should check the member has permission to create a group event", %{
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
%User{} = user = insert(:user)
|
|
|
|
%Actor{id: group_id} = group = insert(:group)
|
|
|
|
|
|
|
|
%Actor{id: member_not_approved_actor_id} =
|
|
|
|
member_not_approved_actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: member_not_approved_actor)
|
|
|
|
%Actor{id: member_actor_id} = member_actor = insert(:actor, user: user)
|
|
|
|
insert(:member, parent: group, actor: member_actor, role: :member)
|
|
|
|
%Actor{id: moderator_actor_id} = moderator_actor = insert(:actor, user: user)
|
|
|
|
insert(:member, parent: group, actor: moderator_actor, role: :moderator)
|
|
|
|
%Actor{id: not_member_actor_id} = insert(:actor, user: user)
|
|
|
|
|
|
|
|
variables = Map.put(@variables, :attributed_to_id, "#{group_id}")
|
2019-09-02 17:23:00 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{member_not_approved_actor_id}")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["data"]["createEvent"] == nil
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"Organizer profile doesn't have permission to create an event on behalf of this group"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{not_member_actor_id}")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["data"]["createEvent"] == nil
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"Organizer profile doesn't have permission to create an event on behalf of this group"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{member_actor_id}")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["data"]["createEvent"] == nil
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"Organizer profile doesn't have permission to create an event on behalf of this group"
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @create_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{moderator_actor_id}")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["createEvent"] != nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@update_event_mutation """
|
|
|
|
mutation updateEvent(
|
|
|
|
$eventId: ID!
|
|
|
|
$title: String
|
|
|
|
$description: String
|
|
|
|
$beginsOn: DateTime
|
|
|
|
$endsOn: DateTime
|
|
|
|
$status: EventStatus
|
|
|
|
$visibility: EventVisibility
|
|
|
|
$joinOptions: EventJoinOptions
|
|
|
|
$draft: Boolean
|
|
|
|
$tags: [String]
|
|
|
|
$picture: MediaInput
|
|
|
|
$onlineAddress: String
|
|
|
|
$phoneAddress: String
|
|
|
|
$organizerActorId: ID
|
|
|
|
$attributedToId: ID
|
|
|
|
$category: String
|
|
|
|
$physicalAddress: AddressInput
|
|
|
|
$options: EventOptionsInput
|
|
|
|
$contacts: [Contact]
|
|
|
|
) {
|
|
|
|
updateEvent(
|
|
|
|
eventId: $eventId
|
|
|
|
title: $title
|
|
|
|
description: $description
|
|
|
|
beginsOn: $beginsOn
|
|
|
|
endsOn: $endsOn
|
|
|
|
status: $status
|
|
|
|
visibility: $visibility
|
|
|
|
joinOptions: $joinOptions
|
|
|
|
draft: $draft
|
|
|
|
tags: $tags
|
|
|
|
picture: $picture
|
|
|
|
onlineAddress: $onlineAddress
|
|
|
|
phoneAddress: $phoneAddress
|
|
|
|
organizerActorId: $organizerActorId
|
|
|
|
attributedToId: $attributedToId
|
|
|
|
category: $category
|
|
|
|
physicalAddress: $physicalAddress
|
|
|
|
options: $options
|
|
|
|
contacts: $contacts
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
uuid,
|
|
|
|
url,
|
|
|
|
title
|
|
|
|
draft
|
|
|
|
description
|
|
|
|
beginsOn
|
|
|
|
endsOn
|
|
|
|
status
|
|
|
|
tags {
|
|
|
|
title,
|
|
|
|
slug
|
|
|
|
},
|
|
|
|
online_address,
|
|
|
|
phone_address,
|
|
|
|
category,
|
|
|
|
options {
|
|
|
|
maximumAttendeeCapacity,
|
|
|
|
showRemainingAttendeeCapacity
|
|
|
|
},
|
|
|
|
physicalAddress {
|
|
|
|
url,
|
|
|
|
geom,
|
|
|
|
street
|
|
|
|
}
|
|
|
|
picture {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
describe "update_event/3" do
|
|
|
|
test "update_event/3 should check the event exists", %{conn: conn, actor: _actor, user: user} do
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{eventId: 45, title: "my event updated"}
|
|
|
|
)
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] == "Event not found"
|
2019-09-02 17:23:00 +02:00
|
|
|
end
|
|
|
|
|
2020-10-09 18:12:35 +02:00
|
|
|
test "update_event/3 should check the user can change the organizer", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
actor2 = insert(:actor)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{eventId: event.id, title: "my event updated", organizerActorId: actor2.id}
|
|
|
|
)
|
2020-10-09 18:12:35 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2020-10-09 19:29:12 +02:00
|
|
|
"You can't attribute this event to this profile."
|
2020-10-09 18:12:35 +02:00
|
|
|
end
|
|
|
|
|
2020-10-09 16:07:13 +02:00
|
|
|
test "update_event/3 should check the user is the organizer", %{
|
2019-09-02 17:23:00 +02:00
|
|
|
conn: conn,
|
2019-09-04 18:24:31 +02:00
|
|
|
actor: _actor,
|
2019-09-02 17:23:00 +02:00
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{eventId: event.id, title: "my event updated"}
|
|
|
|
)
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] == "You can't edit this event."
|
2020-10-09 18:12:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "update_event/3 should check the user is the organizer also when it's changed", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{eventId: event.id, title: "my event updated", organizerActorId: actor.id}
|
|
|
|
)
|
2020-10-09 18:12:35 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] == "You can't edit this event."
|
2019-09-02 17:23:00 +02:00
|
|
|
end
|
|
|
|
|
2019-11-18 18:40:03 +01:00
|
|
|
test "update_event/3 should check end time is after the beginning time", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
title: "my event updated",
|
|
|
|
endsOn: event.begins_on |> DateTime.add(3600 * -2) |> DateTime.to_iso8601()
|
|
|
|
}
|
|
|
|
)
|
2019-11-18 18:40:03 +01:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
2020-10-01 15:07:15 +02:00
|
|
|
["ends_on cannot be set before begins_on"]
|
2019-11-18 18:40:03 +01:00
|
|
|
end
|
|
|
|
|
2021-11-10 20:31:29 +01:00
|
|
|
test "updates an event", %{conn: conn, actor: actor, user: user} do
|
|
|
|
%Event{uuid: event_uuid, title: event_title} =
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
|
2021-10-13 12:55:49 +02:00
|
|
|
creator = insert(:participant, event: event, actor: actor, role: :creator)
|
2019-09-30 18:18:04 +02:00
|
|
|
participant_user = insert(:user)
|
|
|
|
participant_actor = insert(:actor, user: participant_user)
|
|
|
|
|
2021-10-13 12:55:49 +02:00
|
|
|
participant =
|
2019-09-30 18:18:04 +02:00
|
|
|
insert(:participant, event: event, actor: participant_actor, role: :participant)
|
|
|
|
|
2019-09-16 15:11:43 +02:00
|
|
|
address = insert(:address)
|
2019-09-02 17:23:00 +02:00
|
|
|
|
|
|
|
begins_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
2019-09-16 15:11:43 +02:00
|
|
|
ends_on = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
|
2019-09-02 17:23:00 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
title: "my event updated",
|
|
|
|
description: "description updated",
|
|
|
|
beginsOn: "#{begins_on}",
|
|
|
|
endsOn: "#{ends_on}",
|
|
|
|
status: "TENTATIVE",
|
|
|
|
tags: ["tag1_updated", "tag2_updated"],
|
|
|
|
onlineAddress: "toto@example.com",
|
|
|
|
phoneAddress: "0000000000",
|
|
|
|
category: "birthday",
|
|
|
|
options: %{
|
|
|
|
maximumAttendeeCapacity: 30,
|
|
|
|
showRemainingAttendeeCapacity: true
|
|
|
|
},
|
|
|
|
physicalAddress: %{
|
|
|
|
street: "#{address.street}",
|
|
|
|
locality: "#{address.locality}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["errors"] == nil
|
2019-09-02 17:23:00 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
event_res = res["data"]["updateEvent"]
|
2019-09-16 15:11:43 +02:00
|
|
|
|
|
|
|
assert event_res["title"] == "my event updated"
|
|
|
|
assert event_res["description"] == "description updated"
|
2021-07-26 17:23:42 +02:00
|
|
|
assert event_res["beginsOn"] == "#{begins_on}"
|
|
|
|
assert event_res["endsOn"] == "#{ends_on}"
|
2019-09-23 10:26:23 +02:00
|
|
|
assert event_res["status"] == "TENTATIVE"
|
|
|
|
assert event_res["online_address"] == "toto@example.com"
|
|
|
|
assert event_res["phone_address"] == "0000000000"
|
2019-09-16 15:11:43 +02:00
|
|
|
assert event_res["category"] == "birthday"
|
|
|
|
|
|
|
|
assert event_res["options"]["maximumAttendeeCapacity"] == 30
|
|
|
|
assert event_res["options"]["showRemainingAttendeeCapacity"] == true
|
|
|
|
|
|
|
|
assert event_res["uuid"] == event.uuid
|
|
|
|
assert event_res["url"] == event.url
|
|
|
|
|
|
|
|
assert event_res["physicalAddress"]["street"] == address.street
|
|
|
|
refute event_res["physicalAddress"]["url"] == address.url
|
|
|
|
|
|
|
|
assert event_res["tags"] == [
|
2019-09-04 18:24:31 +02:00
|
|
|
%{"slug" => "tag1-updated", "title" => "tag1_updated"},
|
|
|
|
%{"slug" => "tag2-updated", "title" => "tag2_updated"}
|
2019-09-02 17:23:00 +02:00
|
|
|
]
|
2019-09-30 18:18:04 +02:00
|
|
|
|
2019-11-04 15:10:58 +01:00
|
|
|
{event_id_int, ""} = Integer.parse(event_res["id"])
|
|
|
|
|
|
|
|
assert_enqueued(
|
2020-01-23 00:55:07 +01:00
|
|
|
worker: Workers.BuildSearch,
|
2019-11-04 15:10:58 +01:00
|
|
|
args: %{event_id: event_id_int, op: :update_search_event}
|
|
|
|
)
|
|
|
|
|
2021-11-10 20:31:29 +01:00
|
|
|
assert [
|
|
|
|
%{
|
|
|
|
args: %{
|
|
|
|
"event_uuid" => ^event_uuid,
|
|
|
|
"action" => "notify_of_event_update",
|
|
|
|
"old_event" => %{
|
|
|
|
"title" => ^event_title
|
|
|
|
},
|
|
|
|
"changes" => %{
|
|
|
|
"description" => "description updated",
|
|
|
|
"status" => "tentative",
|
|
|
|
"title" => "my event updated"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] = all_enqueued(worker: Workers.EventDelayedNotificationWorker)
|
|
|
|
|
|
|
|
Oban.drain_queue(queue: :default, with_scheduled: true)
|
|
|
|
|
2020-06-04 15:41:58 +02:00
|
|
|
{:ok, new_event} = Mobilizon.Events.get_event_with_preload(event.id)
|
2019-09-30 18:18:04 +02:00
|
|
|
|
|
|
|
assert_delivered_email(
|
|
|
|
Email.Event.event_updated(
|
2020-10-08 08:53:25 +02:00
|
|
|
user.email,
|
2021-10-18 11:09:27 +02:00
|
|
|
creator,
|
2019-09-30 18:18:04 +02:00
|
|
|
actor,
|
|
|
|
event,
|
|
|
|
new_event,
|
2021-11-10 20:31:29 +01:00
|
|
|
MapSet.new([:title, :begins_on, :ends_on, :status, :physical_address]),
|
|
|
|
"Etc/UTC",
|
|
|
|
"en"
|
2019-09-30 18:18:04 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_delivered_email(
|
|
|
|
Email.Event.event_updated(
|
2020-10-08 08:53:25 +02:00
|
|
|
participant_user.email,
|
2021-10-18 11:09:27 +02:00
|
|
|
participant,
|
2019-09-30 18:18:04 +02:00
|
|
|
participant_actor,
|
|
|
|
event,
|
|
|
|
new_event,
|
2021-11-10 20:31:29 +01:00
|
|
|
MapSet.new([:title, :begins_on, :ends_on, :status, :physical_address]),
|
|
|
|
"Etc/UTC",
|
|
|
|
"en"
|
2019-09-30 18:18:04 +02:00
|
|
|
)
|
|
|
|
)
|
2019-09-02 17:23:00 +02:00
|
|
|
end
|
|
|
|
|
2019-09-04 18:24:31 +02:00
|
|
|
test "update_event/3 updates an event with a new picture", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
begins_on =
|
|
|
|
event.begins_on
|
2021-07-26 17:23:42 +02:00
|
|
|
|> DateTime.add(3 * 3600)
|
2019-09-18 17:32:37 +02:00
|
|
|
|> DateTime.truncate(:second)
|
|
|
|
|> DateTime.to_iso8601()
|
2019-09-04 18:24:31 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
title: "my event updated",
|
|
|
|
description: "description updated",
|
|
|
|
beginsOn: "#{begins_on}",
|
|
|
|
category: "birthday",
|
|
|
|
picture: %{
|
|
|
|
media: %{
|
|
|
|
name: "picture for my event",
|
|
|
|
alt: "A very sunny landscape",
|
|
|
|
file: "event.jpg",
|
|
|
|
actorId: "#{actor.id}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
uploads: %{
|
|
|
|
"event.jpg" => %Plug.Upload{
|
|
|
|
path: "test/fixtures/picture.png",
|
|
|
|
filename: "event.jpg"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2019-09-04 18:24:31 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["updateEvent"]["title"] == "my event updated"
|
|
|
|
assert res["data"]["updateEvent"]["uuid"] == event.uuid
|
|
|
|
assert res["data"]["updateEvent"]["url"] == event.url
|
2019-09-04 18:24:31 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"]["beginsOn"] ==
|
|
|
|
event.begins_on |> DateTime.add(3 * 3600) |> DateTime.to_iso8601()
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"]["picture"]["name"] ==
|
2019-09-04 18:24:31 +02:00
|
|
|
"picture for my event"
|
|
|
|
end
|
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
@person_participations_query """
|
|
|
|
query EventPersonParticipation($actorId: ID!, $eventId: ID!) {
|
|
|
|
person(id: $actorId) {
|
|
|
|
id
|
|
|
|
participations(eventId: $eventId) {
|
|
|
|
total
|
|
|
|
elements {
|
|
|
|
role
|
|
|
|
actor {
|
|
|
|
id
|
2019-10-02 17:59:07 +02:00
|
|
|
}
|
2021-07-26 17:23:42 +02:00
|
|
|
event {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
test "respects the draft status", %{conn: conn, actor: actor, user: user} do
|
|
|
|
event = insert(:event, organizer_actor: actor, draft: true)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
title: "my event updated but still draft",
|
|
|
|
draft: true
|
|
|
|
}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"]["draft"] == true
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @find_event_query,
|
|
|
|
variables: %{
|
|
|
|
uuid: event.uuid
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert hd(res["errors"])["message"] =~ "not found"
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2021-07-26 17:23:42 +02:00
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @find_event_query,
|
|
|
|
variables: %{
|
|
|
|
uuid: event.uuid
|
|
|
|
}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["event"]["draft"] == true
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @person_participations_query,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
actorId: actor.id
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["person"]["participations"]["elements"] == []
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
title: "my event updated and no longer draft",
|
|
|
|
draft: false
|
|
|
|
}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"]["draft"] == false
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @find_event_query,
|
|
|
|
variables: %{
|
|
|
|
uuid: event.uuid
|
2019-10-02 17:59:07 +02:00
|
|
|
}
|
2021-07-26 17:23:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["event"]["draft"] == false
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @person_participations_query,
|
|
|
|
variables: %{
|
|
|
|
eventId: event.id,
|
|
|
|
actorId: actor.id
|
|
|
|
}
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["errors"] == nil
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["person"]["participations"]["elements"] == [
|
|
|
|
%{
|
|
|
|
"actor" => %{"id" => to_string(actor.id)},
|
|
|
|
"event" => %{"id" => to_string(event.id)},
|
|
|
|
"role" => "CREATOR"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "update_event/3 on behalf of a group" do
|
|
|
|
test "should check the member has permission to update a group event", %{
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
%User{} = user = insert(:user)
|
|
|
|
%Actor{id: group_id} = group = insert(:group)
|
|
|
|
|
|
|
|
%Actor{id: member_not_approved_actor_id} =
|
|
|
|
member_not_approved_actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
insert(:member, parent: group, actor: member_not_approved_actor)
|
|
|
|
%Actor{id: member_actor_id} = member_actor = insert(:actor, user: user)
|
|
|
|
insert(:member, parent: group, actor: member_actor, role: :member)
|
|
|
|
%Actor{id: moderator_actor_id} = moderator_actor = insert(:actor, user: user)
|
|
|
|
insert(:member, parent: group, actor: moderator_actor, role: :moderator)
|
|
|
|
|
|
|
|
%Actor{} = administrator_actor = insert(:actor, user: user)
|
|
|
|
insert(:member, parent: group, actor: administrator_actor, role: :administrator)
|
|
|
|
|
2021-09-10 11:35:32 +02:00
|
|
|
%Actor{id: not_member_actor_id} = not_member_actor = insert(:actor, user: user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|
|
|
|
%Event{} =
|
|
|
|
event = insert(:event, attributed_to: group, organizer_actor: administrator_actor)
|
|
|
|
|
|
|
|
variables =
|
|
|
|
@variables
|
|
|
|
|> Map.put(:attributed_to_id, "#{group_id}")
|
|
|
|
|> Map.put(:eventId, to_string(event.id))
|
|
|
|
|
2021-11-03 08:50:28 +01:00
|
|
|
Users.update_user_default_actor(user, member_not_approved_actor)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{member_not_approved_actor_id}")
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"] == nil
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"This profile doesn't have permission to update an event on behalf of this group"
|
|
|
|
|
2021-11-03 08:50:28 +01:00
|
|
|
Users.update_user_default_actor(user, not_member_actor)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2021-07-26 17:23:42 +02:00
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{not_member_actor_id}")
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"] == nil
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"This profile doesn't have permission to update an event on behalf of this group"
|
|
|
|
|
2021-11-03 08:50:28 +01:00
|
|
|
Users.update_user_default_actor(user, member_actor)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
2021-07-26 17:23:42 +02:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{member_actor_id}")
|
|
|
|
)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert res["data"]["updateEvent"] == nil
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
assert hd(res["errors"])["message"] ==
|
|
|
|
"This profile doesn't have permission to update an event on behalf of this group"
|
|
|
|
|
2021-11-03 08:50:28 +01:00
|
|
|
Users.update_user_default_actor(user, moderator_actor)
|
2021-07-26 17:23:42 +02:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @update_event_mutation,
|
|
|
|
variables: Map.put(variables, :organizer_actor_id, "#{moderator_actor_id}")
|
|
|
|
)
|
|
|
|
|
|
|
|
assert res["errors"] == nil
|
|
|
|
assert res["data"]["updateEvent"] != nil
|
2019-10-02 17:59:07 +02:00
|
|
|
end
|
2021-07-26 17:23:42 +02:00
|
|
|
end
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "list_events/3" do
|
2020-12-09 17:55:38 +01:00
|
|
|
@fetch_events_query """
|
|
|
|
query Events($page: Int, $limit: Int) {
|
|
|
|
events(page: $page, limit: $limit) {
|
|
|
|
total
|
|
|
|
elements {
|
|
|
|
uuid
|
2018-12-21 11:45:55 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-09 17:55:38 +01:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
test "list_events/3 returns events", %{conn: conn} do
|
|
|
|
event = insert(:event)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @fetch_events_query)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
assert res["data"]["events"]["elements"] |> Enum.map(& &1["uuid"]) == [
|
|
|
|
event.uuid
|
|
|
|
]
|
2018-12-21 11:45:55 +01:00
|
|
|
|
2020-12-18 16:32:54 +01:00
|
|
|
insert(:event)
|
|
|
|
insert(:event)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
2020-12-18 16:32:54 +01:00
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @fetch_events_query,
|
|
|
|
variables: %{page: 1, limit: 2}
|
|
|
|
)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
2020-12-18 16:32:54 +01:00
|
|
|
assert res["data"]["events"]["total"] == 3
|
|
|
|
assert res["data"]["events"]["elements"] |> length == 2
|
2018-12-21 11:45:55 +01:00
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @fetch_events_query,
|
2020-12-18 16:32:54 +01:00
|
|
|
variables: %{page: 2, limit: 2}
|
2020-12-09 17:55:38 +01:00
|
|
|
)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
2020-12-18 16:32:54 +01:00
|
|
|
assert res["data"]["events"]["total"] == 3
|
|
|
|
assert res["data"]["events"]["elements"] |> length == 1
|
2018-12-21 11:45:55 +01:00
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(
|
|
|
|
query: @fetch_events_query,
|
2020-12-18 16:32:54 +01:00
|
|
|
variables: %{page: 3, limit: 2}
|
2020-12-09 17:55:38 +01:00
|
|
|
)
|
2018-12-21 11:45:55 +01:00
|
|
|
|
2020-12-18 16:32:54 +01:00
|
|
|
assert res["data"]["events"]["total"] == 3
|
2020-12-09 17:55:38 +01:00
|
|
|
assert res["data"]["events"]["elements"] |> length == 0
|
2018-12-21 11:45:55 +01:00
|
|
|
end
|
2019-01-14 15:56:07 +01:00
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
test "list_events/3 doesn't list private events", %{conn: conn} do
|
2019-01-14 15:56:07 +01:00
|
|
|
insert(:event, visibility: :private)
|
|
|
|
insert(:event, visibility: :unlisted)
|
2019-02-01 12:33:15 +01:00
|
|
|
insert(:event, visibility: :restricted)
|
2019-01-14 15:56:07 +01:00
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @fetch_events_query)
|
2019-01-14 15:56:07 +01:00
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
assert res["data"]["events"]["total"] == 0
|
|
|
|
assert res["data"]["events"]["elements"] |> Enum.map(& &1["uuid"]) == []
|
2019-01-14 15:56:07 +01:00
|
|
|
end
|
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
test "list_events/3 doesn't list draft events", %{conn: conn} do
|
2019-10-02 17:59:07 +02:00
|
|
|
insert(:event, visibility: :public, draft: true)
|
|
|
|
|
|
|
|
res =
|
2020-12-09 17:55:38 +01:00
|
|
|
conn
|
|
|
|
|> AbsintheHelpers.graphql_query(query: @fetch_events_query)
|
2019-10-02 17:59:07 +02:00
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
assert res["data"]["events"]["total"] == 0
|
|
|
|
assert res["data"]["events"]["elements"] |> Enum.map(& &1["uuid"]) == []
|
2019-10-02 17:59:07 +02:00
|
|
|
end
|
|
|
|
|
2019-01-14 15:56:07 +01:00
|
|
|
test "find_event/3 returns an unlisted event", context do
|
|
|
|
event = insert(:event, visibility: :unlisted)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
|
|
|
uuid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
|
|
|
end
|
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
# test "find_event/3 doesn't return a private event", context do
|
|
|
|
# event = insert(:event, visibility: :private)
|
|
|
|
#
|
|
|
|
# query = """
|
|
|
|
# {
|
|
|
|
# event(uuid: "#{event.uuid}") {
|
|
|
|
# uuid,
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# """
|
|
|
|
#
|
|
|
|
# res =
|
|
|
|
# context.conn
|
|
|
|
# |> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
#
|
|
|
|
# assert json_response(res, 200)["errors"] |> hd |> Map.get("message") ==
|
|
|
|
# "Event with UUID #{event.uuid} not found"
|
|
|
|
# end
|
2021-07-26 17:23:42 +02:00
|
|
|
end
|
2019-01-25 17:06:57 +01:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "delete_event/3" do
|
2019-01-25 17:06:57 +01:00
|
|
|
test "delete_event/3 deletes an event", %{conn: conn, user: user, actor: actor} do
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
deleteEvent(
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> 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"]["deleteEvent"]["id"] == to_string(event.id)
|
2019-01-25 17:06:57 +01:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
|
|
|
end
|
2019-02-01 09:52:36 +01:00
|
|
|
|
|
|
|
test "delete_event/3 should check the user is authenticated", %{conn: conn, actor: actor} do
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
deleteEvent(
|
|
|
|
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 event can be deleted by the user", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user,
|
2020-11-26 11:41:13 +01:00
|
|
|
actor: _actor
|
2019-02-01 09:52:36 +01:00
|
|
|
} do
|
|
|
|
actor2 = insert(:actor)
|
|
|
|
event = insert(:event, organizer_actor: actor2)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
deleteEvent(
|
|
|
|
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
|
2019-04-11 18:25:32 +02:00
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
test "delete_event/3 allows a event being deleted by a moderator and creates a entry in actionLogs",
|
|
|
|
%{
|
|
|
|
conn: conn,
|
|
|
|
user: _user,
|
|
|
|
actor: _actor
|
|
|
|
} do
|
|
|
|
user_moderator = insert(:user, role: :moderator)
|
|
|
|
actor_moderator = insert(:actor, user: user_moderator)
|
|
|
|
|
|
|
|
actor2 = insert(:actor)
|
|
|
|
event = insert(:event, organizer_actor: actor2)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
deleteEvent(
|
|
|
|
event_id: #{event.id}
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_moderator)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["deleteEvent"]["id"] == to_string(event.id)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
actionLogs {
|
2021-04-27 17:53:11 +02:00
|
|
|
total
|
|
|
|
elements {
|
|
|
|
action,
|
|
|
|
actor {
|
|
|
|
preferredUsername
|
2019-09-09 09:31:08 +02:00
|
|
|
},
|
2021-04-27 17:53:11 +02:00
|
|
|
object {
|
|
|
|
... on Report {
|
|
|
|
id,
|
|
|
|
status
|
|
|
|
},
|
|
|
|
... on ReportNote {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
... on Event {
|
|
|
|
id,
|
|
|
|
title
|
|
|
|
}
|
2019-09-09 09:31:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> auth_conn(user_moderator)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "actionLogs"))
|
|
|
|
|
2021-04-27 17:53:11 +02:00
|
|
|
assert hd(json_response(res, 200)["data"]["actionLogs"]["elements"]) == %{
|
2019-09-09 09:31:08 +02:00
|
|
|
"action" => "EVENT_DELETION",
|
|
|
|
"actor" => %{"preferredUsername" => actor_moderator.preferred_username},
|
|
|
|
"object" => %{"title" => event.title, "id" => to_string(event.id)}
|
|
|
|
}
|
|
|
|
end
|
2021-07-26 17:23:42 +02:00
|
|
|
end
|
2019-09-09 09:31:08 +02:00
|
|
|
|
2021-07-26 17:23:42 +02:00
|
|
|
describe "list_related_events/3" do
|
2019-04-11 18:25:32 +02:00
|
|
|
test "list_related_events/3 should give related events", %{
|
|
|
|
conn: conn,
|
|
|
|
actor: actor
|
|
|
|
} do
|
|
|
|
tag1 = insert(:tag, title: "Elixir", slug: "elixir")
|
|
|
|
tag2 = insert(:tag, title: "PostgreSQL", slug: "postgresql")
|
|
|
|
|
|
|
|
event = insert(:event, title: "Initial event", organizer_actor: actor, tags: [tag1, tag2])
|
|
|
|
|
|
|
|
event2 =
|
|
|
|
insert(:event,
|
|
|
|
title: "Event from same actor",
|
|
|
|
organizer_actor: actor,
|
|
|
|
visibility: :public,
|
|
|
|
begins_on: Timex.shift(DateTime.utc_now(), days: 3)
|
|
|
|
)
|
|
|
|
|
|
|
|
event3 =
|
|
|
|
insert(:event,
|
|
|
|
title: "Event with same tags",
|
|
|
|
tags: [tag1, tag2],
|
|
|
|
visibility: :public,
|
|
|
|
begins_on: Timex.shift(DateTime.utc_now(), days: 3)
|
|
|
|
)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
event(uuid: "#{event.uuid}") {
|
|
|
|
uuid,
|
|
|
|
title,
|
|
|
|
tags {
|
|
|
|
id
|
|
|
|
},
|
|
|
|
related_events {
|
|
|
|
uuid,
|
|
|
|
title,
|
|
|
|
tags {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["data"]["event"]["related_events"])["uuid"] == event2.uuid
|
|
|
|
|
|
|
|
assert hd(tl(json_response(res, 200)["data"]["event"]["related_events"]))["uuid"] ==
|
|
|
|
event3.uuid
|
|
|
|
end
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|
|
|
|
end
|