2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.EventsTest do
|
|
|
|
use Mobilizon.DataCase
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
import Mobilizon.Factory
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2019-09-22 16:26:23 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
2020-06-11 19:13:21 +02:00
|
|
|
alias Mobilizon.Events
|
2020-02-18 08:57:00 +01:00
|
|
|
alias Mobilizon.Events.{Event, Participant, Session, Tag, TagRelation, Track}
|
2020-10-14 09:45:58 +02:00
|
|
|
alias Mobilizon.Federation.ActivityPub.Relay
|
2020-01-23 00:55:07 +01:00
|
|
|
alias Mobilizon.Service.Workers
|
2019-09-16 02:07:44 +02:00
|
|
|
alias Mobilizon.Storage.Page
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
@event_valid_attrs %{
|
2019-02-14 14:19:55 +01:00
|
|
|
begins_on: "2010-04-17 14:00:00Z",
|
2018-07-27 10:45:35 +02:00
|
|
|
description: "some description",
|
2019-02-14 14:19:55 +01:00
|
|
|
ends_on: "2010-04-17 14:00:00Z",
|
2019-01-24 15:23:27 +01:00
|
|
|
title: "some title",
|
|
|
|
url: "some url",
|
2019-02-22 16:54:01 +01:00
|
|
|
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
|
|
|
|
category: "meeting"
|
2018-07-27 10:45:35 +02:00
|
|
|
}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2020-10-14 09:45:58 +02:00
|
|
|
describe "list_events/5" do
|
|
|
|
setup do
|
|
|
|
actor = insert(:actor)
|
|
|
|
event = insert(:event, organizer_actor: actor, visibility: :public, local: true)
|
|
|
|
Mobilizon.Config.clear_config_cache()
|
|
|
|
{:ok, actor: actor, event: event}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "list_events/0 returns all events", %{event: event} do
|
2020-12-09 17:55:38 +01:00
|
|
|
assert event.title == hd(Events.list_events().elements).title
|
2020-10-14 09:45:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "list_events/5 returns events from other instances if we follow them",
|
|
|
|
%{event: _event} do
|
2020-12-09 17:55:38 +01:00
|
|
|
events = Events.list_events().elements
|
2020-10-14 09:45:58 +02:00
|
|
|
assert length(events) == 1
|
|
|
|
|
|
|
|
%Actor{id: remote_instance_actor_id} = remote_instance_actor = insert(:instance_actor)
|
|
|
|
%Actor{id: remote_actor_id} = insert(:actor, domain: "somedomain.tld", user: nil)
|
|
|
|
%Event{url: remote_event_url} = insert(:event, local: false, title: "My Remote event")
|
|
|
|
Mobilizon.Share.create(remote_event_url, remote_instance_actor_id, remote_actor_id)
|
|
|
|
|
|
|
|
%Actor{} = own_instance_actor = Relay.get_actor()
|
|
|
|
|
|
|
|
insert(:follower, target_actor: remote_instance_actor, actor: own_instance_actor)
|
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
events = Events.list_events().elements
|
2020-10-14 09:45:58 +02:00
|
|
|
assert length(events) == 2
|
|
|
|
assert events |> Enum.any?(fn event -> event.title == "My Remote event" end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "list_events/5 doesn't return events from other instances if we don't follow them anymore",
|
|
|
|
%{event: _event} do
|
|
|
|
%Actor{id: remote_instance_actor_id} = insert(:instance_actor)
|
|
|
|
%Actor{id: remote_actor_id} = insert(:actor, domain: "somedomain.tld", user: nil)
|
|
|
|
%Event{url: remote_event_url} = insert(:event, local: false, title: "My Remote event")
|
|
|
|
Mobilizon.Share.create(remote_event_url, remote_instance_actor_id, remote_actor_id)
|
|
|
|
|
2020-12-09 17:55:38 +01:00
|
|
|
events = Events.list_events().elements
|
2020-10-14 09:45:58 +02:00
|
|
|
assert length(events) == 1
|
|
|
|
assert events |> Enum.all?(fn event -> event.title != "My Remote event" end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "events" do
|
2018-08-24 11:34:00 +02:00
|
|
|
setup do
|
|
|
|
actor = insert(:actor)
|
2020-10-14 09:45:58 +02:00
|
|
|
event = insert(:event, organizer_actor: actor, visibility: :public, local: true)
|
2020-01-23 00:55:07 +01:00
|
|
|
Workers.BuildSearch.insert_search_event(event)
|
2018-08-24 11:34:00 +02:00
|
|
|
{:ok, actor: actor, event: event}
|
|
|
|
end
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
@valid_attrs %{
|
2019-02-14 14:19:55 +01:00
|
|
|
begins_on: "2010-04-17 14:00:00Z",
|
2018-07-27 10:45:35 +02:00
|
|
|
description: "some description",
|
2019-02-14 14:19:55 +01:00
|
|
|
ends_on: "2010-04-17 14:00:00Z",
|
2018-07-27 10:45:35 +02:00
|
|
|
title: "some title"
|
|
|
|
}
|
|
|
|
@update_attrs %{
|
2019-02-14 14:19:55 +01:00
|
|
|
begins_on: "2011-05-18 15:01:01Z",
|
2018-07-27 10:45:35 +02:00
|
|
|
description: "some updated description",
|
2019-02-14 14:19:55 +01:00
|
|
|
ends_on: "2011-05-18 15:01:01Z",
|
2018-07-27 10:45:35 +02:00
|
|
|
title: "some updated title"
|
|
|
|
}
|
2018-01-13 23:33:03 +01:00
|
|
|
@invalid_attrs %{begins_on: nil, description: nil, ends_on: nil, title: nil}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "get_event!/1 returns the event with given id", %{event: event} do
|
2018-01-13 23:33:03 +01:00
|
|
|
assert Events.get_event!(event.id).title == event.title
|
2018-08-24 11:34:00 +02:00
|
|
|
refute Ecto.assoc_loaded?(Events.get_event!(event.id).organizer_actor)
|
|
|
|
end
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
test "get_event_with_preload!/1 returns the event with given id", %{event: event} do
|
|
|
|
assert Events.get_event_with_preload!(event.id).organizer_actor.preferred_username ==
|
2018-08-24 11:34:00 +02:00
|
|
|
event.organizer_actor.preferred_username
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
assert Events.get_event_with_preload!(event.id).participants == []
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
|
|
|
|
2019-10-22 10:25:28 +02:00
|
|
|
test "build_events_for_search/1 returns events for a given name", %{
|
2018-11-06 10:30:27 +01:00
|
|
|
event: %Event{title: title} = event
|
|
|
|
} do
|
2020-08-04 09:24:09 +02:00
|
|
|
assert title == hd(Events.build_events_for_search(%{term: event.title}).elements).title
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
%Event{} = event2 = insert(:event, title: "Special event")
|
2020-01-23 00:55:07 +01:00
|
|
|
Workers.BuildSearch.insert_search_event(event2)
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert event2.title ==
|
2020-08-04 09:24:09 +02:00
|
|
|
Events.build_events_for_search(%{term: "Special"}).elements
|
|
|
|
|> hd()
|
|
|
|
|> Map.get(:title)
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert event2.title ==
|
2020-08-04 09:24:09 +02:00
|
|
|
Events.build_events_for_search(%{term: " Spécïal "}).elements
|
2019-04-12 15:04:32 +02:00
|
|
|
|> hd()
|
|
|
|
|> Map.get(:title)
|
|
|
|
|
2019-10-22 10:25:28 +02:00
|
|
|
tag1 = insert(:tag, title: "coucou")
|
|
|
|
tag2 = insert(:tag, title: "hola")
|
|
|
|
%Event{} = event3 = insert(:event, title: "Nothing like it", tags: [tag1, tag2])
|
2020-01-23 00:55:07 +01:00
|
|
|
Workers.BuildSearch.insert_search_event(event3)
|
2019-10-22 10:25:28 +02:00
|
|
|
|
|
|
|
assert event3.title ==
|
2020-08-04 09:24:09 +02:00
|
|
|
Events.build_events_for_search(%{term: "hola"}).elements |> hd() |> Map.get(:title)
|
2019-10-22 10:25:28 +02:00
|
|
|
|
2020-08-04 09:24:09 +02:00
|
|
|
assert %Page{elements: _elements, total: 3} = Events.build_events_for_search(%{term: ""})
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-12-04 12:06:34 +01:00
|
|
|
test "find_close_events/3 returns events in the area" do
|
|
|
|
assert [] == Events.find_close_events(0, 0)
|
|
|
|
|
|
|
|
geom = %Geo.Point{coordinates: {47.2330724, -1.55068}, srid: 4326}
|
|
|
|
address = insert(:address, geom: geom)
|
|
|
|
event = insert(:event, physical_address: address)
|
|
|
|
|
|
|
|
assert [event.id] == Events.find_close_events(47.2330724, -1.55068) |> Enum.map(& &1.id)
|
|
|
|
end
|
|
|
|
|
2017-12-08 09:58:14 +01:00
|
|
|
test "create_event/1 with valid data creates a event" do
|
2018-11-12 18:17:53 +01:00
|
|
|
actor = insert(:actor)
|
|
|
|
address = insert(:address)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
|
|
|
valid_attrs =
|
|
|
|
@event_valid_attrs
|
2018-06-14 17:25:55 +02:00
|
|
|
|> Map.put(:organizer_actor, actor)
|
|
|
|
|> Map.put(:organizer_actor_id, actor.id)
|
2018-01-17 11:39:01 +01:00
|
|
|
|> Map.put(:address_id, address.id)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
{:ok, %Event{} = event} = Events.create_event(valid_attrs)
|
|
|
|
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
|
|
|
|
assert event.description == "some description"
|
|
|
|
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
|
|
|
|
assert event.title == "some title"
|
|
|
|
|
2020-03-05 19:32:34 +01:00
|
|
|
assert %Participant{} =
|
|
|
|
participant = hd(Events.list_participants_for_event(event.id).elements)
|
|
|
|
|
|
|
|
assert participant.actor.id == actor.id
|
|
|
|
assert participant.role == :creator
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_event/1 with invalid data returns error changeset" do
|
2019-10-25 17:43:37 +02:00
|
|
|
assert {:error, :insert, %Ecto.Changeset{}, _} = Events.create_event(@invalid_attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "update_event/2 with valid data updates the event", %{event: event} do
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:ok, event} = Events.update_event(event, @update_attrs)
|
|
|
|
assert %Event{} = event
|
2019-02-14 14:19:55 +01:00
|
|
|
assert event.begins_on == DateTime.from_naive!(~N[2011-05-18 15:01:01Z], "Etc/UTC")
|
2017-12-08 09:58:14 +01:00
|
|
|
assert event.description == "some updated description"
|
2019-02-14 14:19:55 +01:00
|
|
|
assert event.ends_on == DateTime.from_naive!(~N[2011-05-18 15:01:01Z], "Etc/UTC")
|
2017-12-08 09:58:14 +01:00
|
|
|
assert event.title == "some updated title"
|
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "update_event/2 with invalid data returns error changeset", %{event: event} do
|
2019-10-25 17:43:37 +02:00
|
|
|
assert {:error, :update, %Ecto.Changeset{}, _} = Events.update_event(event, @invalid_attrs)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert event.title == Events.get_event!(event.id).title
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "delete_event/1 deletes the event", %{event: event} do
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:ok, %Event{}} = Events.delete_event(event)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Events.get_event!(event.id) end
|
|
|
|
end
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
test "list_public_events_for_actor/1", %{actor: actor, event: event} do
|
2020-07-09 17:24:28 +02:00
|
|
|
assert %Page{elements: [event_found], total: 1} = Events.list_public_events_for_actor(actor)
|
2018-08-24 11:34:00 +02:00
|
|
|
assert event_found.title == event.title
|
|
|
|
end
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
test "list_public_events_for_actor/3", %{actor: actor, event: event} do
|
2018-08-24 11:34:00 +02:00
|
|
|
event1 = insert(:event, organizer_actor: actor)
|
2018-11-12 18:17:53 +01:00
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
case Events.list_public_events_for_actor(actor, 1, 10) do
|
2020-07-09 17:24:28 +02:00
|
|
|
%Page{elements: events_found, total: 2} ->
|
2019-07-23 18:06:22 +02:00
|
|
|
event_ids = MapSet.new(events_found |> Enum.map(& &1.id))
|
|
|
|
assert event_ids == MapSet.new([event.id, event1.id])
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
err ->
|
|
|
|
flunk("Failed to get events for an actor #{inspect(err)}")
|
|
|
|
end
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
test "list_public_events_for_actor/3 with limited results", %{actor: actor, event: event} do
|
2018-08-24 11:34:00 +02:00
|
|
|
event1 = insert(:event, organizer_actor: actor)
|
2018-11-12 18:17:53 +01:00
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
case Events.list_public_events_for_actor(actor, 1, 1) do
|
2020-07-09 17:24:28 +02:00
|
|
|
%Page{elements: [%Event{id: event_found_id}], total: 2} ->
|
2019-07-23 18:06:22 +02:00
|
|
|
assert event_found_id in [event.id, event1.id]
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
err ->
|
|
|
|
flunk("Failed to get limited events for an actor #{inspect(err)}")
|
|
|
|
end
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
2018-10-09 17:01:45 +02:00
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
test "get_event_by_url/1 with valid url", %{event: %Event{id: event_id, url: event_url}} do
|
|
|
|
assert event_id == Events.get_event_by_url(event_url).id
|
2018-10-09 17:01:45 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
test "get_event_by_url/1 with bad url" do
|
|
|
|
assert is_nil(Events.get_event_by_url("not valid"))
|
2018-10-09 17:01:45 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
test "get_event_by_url!/1 with valid url", %{event: %Event{id: event_id, url: event_url}} do
|
|
|
|
assert event_id == Events.get_event_by_url!(event_url).id
|
2018-10-09 17:01:45 +02:00
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
test "get_event_by_url!/1 with bad url" do
|
2018-10-09 17:01:45 +02:00
|
|
|
assert_raise Ecto.NoResultsError, fn ->
|
|
|
|
Events.get_event_by_url!("not valid")
|
|
|
|
end
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "tags" do
|
2018-01-13 23:33:03 +01:00
|
|
|
@valid_attrs %{title: "some title"}
|
|
|
|
@update_attrs %{title: "some updated title"}
|
|
|
|
@invalid_attrs %{title: nil}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
test "list_tags/0 returns all tags" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
|
|
|
assert [tag.id] == Events.list_tags() |> Enum.map(& &1.id)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2021-09-10 11:29:28 +02:00
|
|
|
test "list_tags/1 filters tags by title or slug" do
|
|
|
|
tag1 = insert(:tag, title: "PineApple", slug: "pineapple")
|
|
|
|
tag2 = insert(:tag, title: "sexy pineapple", slug: "sexy-pineapple")
|
|
|
|
assert [tag1.id, tag2.id] == Events.list_tags("apple") |> Enum.map(& &1.id)
|
|
|
|
end
|
|
|
|
|
2017-12-08 09:58:14 +01:00
|
|
|
test "get_tag!/1 returns the tag with given id" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
|
|
|
assert Events.get_tag!(tag.id).id == tag.id
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_tag/1 with valid data creates a tag" do
|
|
|
|
assert {:ok, %Tag{} = tag} = Events.create_tag(@valid_attrs)
|
|
|
|
assert tag.title == "some title"
|
2018-11-23 15:03:53 +01:00
|
|
|
assert tag.slug == "some-title"
|
|
|
|
|
|
|
|
assert {:ok, %Tag{} = tag2} = Events.create_tag(@valid_attrs)
|
|
|
|
assert tag2.title == "some title"
|
|
|
|
assert tag2.slug == "some-title-1"
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_tag/1 with invalid data returns error changeset" do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.create_tag(@invalid_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_tag/2 with valid data updates the tag" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:ok, tag} = Events.update_tag(tag, @update_attrs)
|
|
|
|
assert %Tag{} = tag
|
|
|
|
assert tag.title == "some updated title"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_tag/2 with invalid data returns error changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.update_tag(tag, @invalid_attrs)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert tag.id == Events.get_tag!(tag.id).id
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_tag/1 deletes the tag" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:ok, %Tag{}} = Events.delete_tag(tag)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Events.get_tag!(tag.id) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-14 14:19:55 +01:00
|
|
|
describe "tags_relations" do
|
|
|
|
setup do
|
|
|
|
tag1 = insert(:tag)
|
|
|
|
tag2 = insert(:tag)
|
|
|
|
{:ok, tag1: tag1, tag2: tag2}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_tag_relation/1 with valid data creates a tag relation", %{
|
|
|
|
tag1: %Tag{id: tag1_id} = tag1,
|
|
|
|
tag2: %Tag{id: tag2_id} = tag2
|
|
|
|
} do
|
2020-11-26 11:41:13 +01:00
|
|
|
assert {:ok, %TagRelation{}} =
|
2019-02-14 14:19:55 +01:00
|
|
|
Events.create_tag_relation(%{tag_id: tag1_id, link_id: tag2_id})
|
|
|
|
|
|
|
|
assert Events.are_tags_linked(tag1, tag2)
|
|
|
|
assert Events.are_tags_linked(tag2, tag1)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_tag_relation/1 with invalid data returns error changeset", %{
|
|
|
|
tag1: %Tag{} = tag1,
|
|
|
|
tag2: %Tag{} = tag2
|
|
|
|
} do
|
|
|
|
assert {:error, %Ecto.Changeset{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: nil, link_id: nil})
|
|
|
|
|
|
|
|
refute Events.are_tags_linked(tag1, tag2)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_tag_relation/1 deletes the tag relation" do
|
|
|
|
tag_relation = insert(:tag_relation)
|
|
|
|
assert {:ok, %TagRelation{}} = Events.delete_tag_relation(tag_relation)
|
|
|
|
end
|
|
|
|
|
2019-09-16 02:07:44 +02:00
|
|
|
test "list_tag_neighbors/2 return the connected tags for a given tag", %{
|
2019-02-14 14:19:55 +01:00
|
|
|
tag1: %Tag{} = tag1,
|
|
|
|
tag2: %Tag{} = tag2
|
|
|
|
} do
|
|
|
|
tag3 = insert(:tag)
|
|
|
|
tag4 = insert(:tag)
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag1.id, link_id: tag2.id})
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag2.id, link_id: tag1.id})
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag3.id, link_id: tag2.id})
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag4.id, link_id: tag1.id})
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag4.id, link_id: tag1.id})
|
|
|
|
|
|
|
|
assert {:ok, %TagRelation{}} =
|
|
|
|
Events.create_tag_relation(%{tag_id: tag4.id, link_id: tag1.id})
|
|
|
|
|
|
|
|
assert {:error,
|
|
|
|
%Ecto.Changeset{
|
|
|
|
errors: [
|
|
|
|
tag_id:
|
|
|
|
{"Can't add a relation on self",
|
|
|
|
[constraint: :check, constraint_name: "no_self_loops_check"]}
|
|
|
|
]
|
|
|
|
}} = Events.create_tag_relation(%{tag_id: tag1.id, link_id: tag1.id})
|
|
|
|
|
|
|
|
# The order is preserved, since tag4 has one more relation than tag2
|
2019-09-16 02:07:44 +02:00
|
|
|
assert [tag4, tag2] == Events.list_tag_neighbors(tag1)
|
2019-02-14 14:19:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "participants" do
|
2019-02-07 16:37:40 +01:00
|
|
|
@valid_attrs %{role: :creator}
|
|
|
|
@update_attrs %{role: :moderator}
|
|
|
|
@invalid_attrs %{role: :no_such_role}
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
setup do
|
|
|
|
actor = insert(:actor)
|
2019-12-03 11:29:51 +01:00
|
|
|
|
|
|
|
event =
|
|
|
|
insert(:event, organizer_actor: actor, participant_stats: %{creator: 1, participant: 1})
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
participant = insert(:participant, actor: actor, event: event)
|
|
|
|
{:ok, participant: participant, event: event, actor: actor}
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "get_participant!/1 returns the participant for a given event and given actor", %{
|
2018-11-12 18:17:53 +01:00
|
|
|
event: %Event{id: event_id},
|
|
|
|
actor: %Actor{id: actor_id}
|
2018-08-24 11:34:00 +02:00
|
|
|
} do
|
2018-11-12 18:17:53 +01:00
|
|
|
assert event_id == Events.get_participant!(event_id, actor_id).event_id
|
|
|
|
assert actor_id == Events.get_participant!(event_id, actor_id).actor_id
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
test "create_participant/1 with valid data creates a participant" do
|
2018-11-12 18:17:53 +01:00
|
|
|
actor = insert(:actor)
|
|
|
|
event = insert(:event)
|
2018-01-13 23:33:03 +01:00
|
|
|
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
2018-06-14 17:25:55 +02:00
|
|
|
valid_attrs = Map.put(valid_attrs, :actor_id, actor.id)
|
2018-11-12 18:17:53 +01:00
|
|
|
|
2019-07-23 18:06:22 +02:00
|
|
|
case Events.create_participant(valid_attrs) do
|
|
|
|
{:ok, %Participant{} = participant} ->
|
|
|
|
assert participant.event_id == event.id
|
|
|
|
assert participant.actor_id == actor.id
|
|
|
|
assert participant.role == :creator
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
err ->
|
|
|
|
flunk("Failed to create a participant #{inspect(err)}")
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
test "create_participant/1 with invalid data returns error changeset" do
|
2019-10-25 17:43:37 +02:00
|
|
|
assert {:error, :participant, %Ecto.Changeset{}, _} =
|
|
|
|
Events.create_participant(@invalid_attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "update_participant/2 with valid data updates the participant", %{
|
|
|
|
participant: participant
|
|
|
|
} do
|
2019-07-23 18:06:22 +02:00
|
|
|
case Events.update_participant(participant, @update_attrs) do
|
|
|
|
{:ok, %Participant{} = participant} ->
|
|
|
|
assert participant.role == :moderator
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
err ->
|
|
|
|
flunk("Failed to update a participant #{inspect(err)}")
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "update_participant/2 with invalid data returns error changeset", %{
|
|
|
|
participant: participant
|
|
|
|
} do
|
2019-12-03 11:29:51 +01:00
|
|
|
assert {:error, :participant, %Ecto.Changeset{}, %{}} =
|
|
|
|
Events.update_participant(participant, @invalid_attrs)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "delete_participant/1 deletes the participant", %{participant: participant} do
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:ok, %Participant{}} = Events.delete_participant(participant)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "sessions" do
|
2018-07-27 10:45:35 +02:00
|
|
|
@valid_attrs %{
|
|
|
|
audios_urls: "some audios_urls",
|
|
|
|
language: "some language",
|
|
|
|
long_abstract: "some long_abstract",
|
|
|
|
short_abstract: "some short_abstract",
|
|
|
|
slides_url: "some slides_url",
|
|
|
|
subtitle: "some subtitle",
|
|
|
|
title: "some title",
|
|
|
|
videos_urls: "some videos_urls"
|
|
|
|
}
|
|
|
|
@update_attrs %{
|
|
|
|
audios_urls: "some updated audios_urls",
|
|
|
|
language: "some updated language",
|
|
|
|
long_abstract: "some updated long_abstract",
|
|
|
|
short_abstract: "some updated short_abstract",
|
|
|
|
slides_url: "some updated slides_url",
|
|
|
|
subtitle: "some updated subtitle",
|
|
|
|
title: "some updated title",
|
|
|
|
videos_urls: "some updated videos_urls"
|
|
|
|
}
|
|
|
|
@invalid_attrs %{
|
|
|
|
audios_urls: nil,
|
|
|
|
language: nil,
|
|
|
|
long_abstract: nil,
|
|
|
|
short_abstract: nil,
|
|
|
|
slides_url: nil,
|
|
|
|
subtitle: nil,
|
|
|
|
title: nil,
|
|
|
|
videos_urls: nil
|
|
|
|
}
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
test "list_sessions/0 returns all sessions" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
|
|
|
assert [session.id] == Events.list_sessions() |> Enum.map(& &1.id)
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
2018-12-14 17:41:55 +01:00
|
|
|
test "list_sessions_for_event/1 returns sessions for an event" do
|
|
|
|
event = insert(:event)
|
|
|
|
session = insert(:session, event: event)
|
2019-09-18 00:37:31 +02:00
|
|
|
assert event |> Events.list_sessions_for_event() |> Enum.map(& &1.id) == [session.id]
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
test "get_session!/1 returns the session with given id" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
|
|
|
assert Events.get_session!(session.id).id == session.id
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_session/1 with valid data creates a session" do
|
2018-11-12 18:17:53 +01:00
|
|
|
event = insert(:event)
|
2018-01-13 23:33:03 +01:00
|
|
|
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
|
|
|
assert {:ok, %Session{} = session} = Events.create_session(valid_attrs)
|
|
|
|
assert session.audios_urls == "some audios_urls"
|
|
|
|
assert session.language == "some language"
|
|
|
|
assert session.long_abstract == "some long_abstract"
|
|
|
|
assert session.short_abstract == "some short_abstract"
|
|
|
|
assert session.slides_url == "some slides_url"
|
|
|
|
assert session.subtitle == "some subtitle"
|
|
|
|
assert session.title == "some title"
|
|
|
|
assert session.videos_urls == "some videos_urls"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_session/1 with invalid data returns error changeset" do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.create_session(@invalid_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_session/2 with valid data updates the session" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
|
|
|
assert {:ok, %Session{} = session} = Events.update_session(session, @update_attrs)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert session.audios_urls == "some updated audios_urls"
|
|
|
|
assert session.language == "some updated language"
|
|
|
|
assert session.long_abstract == "some updated long_abstract"
|
|
|
|
assert session.short_abstract == "some updated short_abstract"
|
|
|
|
assert session.slides_url == "some updated slides_url"
|
|
|
|
assert session.subtitle == "some updated subtitle"
|
|
|
|
assert session.title == "some updated title"
|
|
|
|
assert session.videos_urls == "some updated videos_urls"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_session/2 with invalid data returns error changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.update_session(session, @invalid_attrs)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert session.title == Events.get_session!(session.id).title
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_session/1 deletes the session" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:ok, %Session{}} = Events.delete_session(session)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Events.get_session!(session.id) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "tracks" do
|
|
|
|
@valid_attrs %{color: "some color", description: "some description", name: "some name"}
|
2018-07-27 10:45:35 +02:00
|
|
|
@update_attrs %{
|
|
|
|
color: "some updated color",
|
|
|
|
description: "some updated description",
|
|
|
|
name: "some updated name"
|
|
|
|
}
|
2018-01-13 23:33:03 +01:00
|
|
|
@invalid_attrs %{color: nil, description: nil, name: nil}
|
|
|
|
|
|
|
|
test "list_tracks/0 returns all tracks" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
|
|
|
assert [track.id] == Events.list_tracks() |> Enum.map(& &1.id)
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
2018-12-14 17:41:55 +01:00
|
|
|
test "list_sessions_for_track/1 returns sessions for an event" do
|
|
|
|
event = insert(:event)
|
|
|
|
track = insert(:track, event: event)
|
|
|
|
session = insert(:session, track: track, event: event)
|
2019-09-18 00:37:31 +02:00
|
|
|
assert track |> Events.list_sessions_for_track() |> Enum.map(& &1.id) == [session.id]
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
test "get_track!/1 returns the track with given id" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
|
|
|
assert Events.get_track!(track.id).id == track.id
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_track/1 with valid data creates a track" do
|
2018-11-12 18:17:53 +01:00
|
|
|
event = insert(:event)
|
2018-01-13 23:33:03 +01:00
|
|
|
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
|
|
|
assert {:ok, %Track{} = track} = Events.create_track(valid_attrs)
|
|
|
|
assert track.color == "some color"
|
|
|
|
assert track.description == "some description"
|
|
|
|
assert track.name == "some name"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create_track/1 with invalid data returns error changeset" do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.create_track(@invalid_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_track/2 with valid data updates the track" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
|
|
|
{:ok, %Track{} = track} = Events.update_track(track, @update_attrs)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert track.color == "some updated color"
|
|
|
|
assert track.description == "some updated description"
|
|
|
|
assert track.name == "some updated name"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_track/2 with invalid data returns error changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.update_track(track, @invalid_attrs)
|
2018-11-23 15:03:53 +01:00
|
|
|
assert track.color == Events.get_track!(track.id).color
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_track/1 deletes the track" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:ok, %Track{}} = Events.delete_track(track)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Events.get_track!(track.id) end
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|