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
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events
|
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
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "events" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Event
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
setup do
|
|
|
|
actor = insert(:actor)
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
{: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 "list_events/0 returns all events", %{event: event} do
|
|
|
|
assert event.title == hd(Events.list_events()).title
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
test "get_event_full!/1 returns the event with given id", %{event: event} do
|
|
|
|
assert Events.get_event_full!(event.id).organizer_actor.preferred_username ==
|
|
|
|
event.organizer_actor.preferred_username
|
|
|
|
|
|
|
|
assert Events.get_event_full!(event.id).participants == []
|
|
|
|
end
|
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
test "find_events_by_name/1 returns events for a given name", %{
|
|
|
|
event: %Event{title: title} = event
|
|
|
|
} do
|
|
|
|
assert title == hd(Events.find_events_by_name(event.title)).title
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2018-11-06 10:30:27 +01:00
|
|
|
%Event{title: title2} = event2 = insert(:event, title: "Special event")
|
2019-02-21 18:11:49 +01:00
|
|
|
assert event2.title == Events.find_events_by_name("Special") |> hd() |> Map.get(:title)
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-02-21 18:11:49 +01:00
|
|
|
assert event2.title == Events.find_events_by_name(" Special ") |> hd() |> Map.get(:title)
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-02-21 18:11:49 +01:00
|
|
|
assert title == Events.find_events_by_name("") |> hd() |> Map.get(:title)
|
|
|
|
assert title2 == Events.find_events_by_name("") |> tl |> hd() |> Map.get(:title)
|
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
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
with {:ok, %Event{} = event} <- Events.create_event(valid_attrs) do
|
2019-02-14 14:19:55 +01:00
|
|
|
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
|
2018-11-12 18:17:53 +01:00
|
|
|
assert event.description == "some description"
|
2019-02-14 14:19:55 +01:00
|
|
|
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
|
2018-11-12 18:17:53 +01:00
|
|
|
assert event.title == "some title"
|
|
|
|
else
|
|
|
|
err ->
|
|
|
|
flunk("Failed to create an event #{inspect(err)}")
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_event/1 with invalid data returns error changeset" do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.create_event(@invalid_attrs)
|
|
|
|
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
|
2017-12-08 09:58:14 +01:00
|
|
|
assert {:error, %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
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "change_event/1 returns a event changeset", %{event: event} do
|
2017-12-08 09:58:14 +01:00
|
|
|
assert %Ecto.Changeset{} = Events.change_event(event)
|
|
|
|
end
|
2018-08-24 11:34:00 +02:00
|
|
|
|
2019-01-14 16:21:13 +01:00
|
|
|
test "get_public_events_for_actor/1", %{actor: actor, event: event} do
|
|
|
|
assert {:ok, [event_found], 1} = Events.get_public_events_for_actor(actor)
|
2018-08-24 11:34:00 +02:00
|
|
|
assert event_found.title == event.title
|
|
|
|
end
|
|
|
|
|
2019-01-14 16:21:13 +01:00
|
|
|
test "get_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-01-14 16:21:13 +01:00
|
|
|
with {:ok, events_found, 2} <- Events.get_public_events_for_actor(actor, 1, 10) do
|
2018-11-12 18:17:53 +01:00
|
|
|
event_ids = MapSet.new(events_found |> Enum.map(& &1.id))
|
|
|
|
assert event_ids == MapSet.new([event.id, event1.id])
|
|
|
|
else
|
|
|
|
err ->
|
|
|
|
flunk("Failed to get events for an actor #{inspect(err)}")
|
|
|
|
end
|
2018-08-24 11:34:00 +02:00
|
|
|
end
|
|
|
|
|
2019-01-14 16:21:13 +01:00
|
|
|
test "get_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-01-14 16:21:13 +01:00
|
|
|
with {:ok, [%Event{id: event_found_id}], 2} <-
|
|
|
|
Events.get_public_events_for_actor(actor, 1, 1) do
|
2018-11-12 18:17:53 +01:00
|
|
|
assert event_found_id in [event.id, event1.id]
|
|
|
|
else
|
|
|
|
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-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Tag
|
2017-12-08 09:58:14 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
test "change_tag/1 returns a tag changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
tag = insert(:tag)
|
2017-12-08 09:58:14 +01:00
|
|
|
assert %Ecto.Changeset{} = Events.change_tag(tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-14 14:19:55 +01:00
|
|
|
describe "tags_relations" do
|
|
|
|
alias Mobilizon.Events.TagRelation
|
|
|
|
alias Mobilizon.Events.Tag
|
|
|
|
|
|
|
|
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
|
|
|
|
assert {:ok, %TagRelation{} = tag_relation} =
|
|
|
|
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
|
|
|
|
|
|
|
|
test "tag_neighbors/2 return the connected tags for a given tag", %{
|
|
|
|
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
|
|
|
|
assert [tag4, tag2] == Events.tag_neighbors(tag1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "participants" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.{Participant, Event}
|
|
|
|
alias Mobilizon.Actors.Actor
|
2017-12-08 09:58:14 +01:00
|
|
|
|
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)
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
participant = insert(:participant, actor: actor, event: event)
|
|
|
|
{:ok, participant: participant, event: event, actor: actor}
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-11-12 18:17:53 +01:00
|
|
|
test "list_participants/0 returns all participants", %{
|
|
|
|
participant: %Participant{event_id: participant_event_id, actor_id: participant_actor_id}
|
|
|
|
} do
|
|
|
|
assert [participant_event_id] == Events.list_participants() |> Enum.map(& &1.event_id)
|
|
|
|
assert [participant_actor_id] == Events.list_participants() |> Enum.map(& &1.actor_id)
|
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
|
|
|
|
|
|
|
with {:ok, %Participant{} = participant} <- Events.create_participant(valid_attrs) do
|
|
|
|
assert participant.event_id == event.id
|
|
|
|
assert participant.actor_id == actor.id
|
2019-02-07 16:37:40 +01:00
|
|
|
assert participant.role == :creator
|
2018-11-12 18:17:53 +01:00
|
|
|
else
|
|
|
|
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
|
|
|
|
assert {:error, %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
|
2018-11-12 18:17:53 +01:00
|
|
|
with {:ok, %Participant{} = participant} <-
|
|
|
|
Events.update_participant(participant, @update_attrs) do
|
2019-02-07 16:37:40 +01:00
|
|
|
assert participant.role == :moderator
|
2018-11-12 18:17:53 +01:00
|
|
|
else
|
|
|
|
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
|
2018-01-13 23:33:03 +01:00
|
|
|
assert {:error, %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
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
test "change_participant/1 returns a participant changeset", %{participant: participant} do
|
2018-01-13 23:33:03 +01:00
|
|
|
assert %Ecto.Changeset{} = Events.change_participant(participant)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
describe "sessions" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Session
|
2018-01-13 23:33:03 +01:00
|
|
|
|
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)
|
|
|
|
assert Events.list_sessions_for_event(event) |> Enum.map(& &1.id) == [session.id]
|
|
|
|
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
|
|
|
|
|
|
|
|
test "change_session/1 returns a session changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
session = insert(:session)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert %Ecto.Changeset{} = Events.change_session(session)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "tracks" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Track
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
@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)
|
|
|
|
assert Events.list_sessions_for_track(track) |> Enum.map(& &1.id) == [session.id]
|
|
|
|
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
|
|
|
|
|
|
|
|
test "change_track/1 returns a track changeset" do
|
2018-11-23 15:03:53 +01:00
|
|
|
track = insert(:track)
|
2018-01-13 23:33:03 +01:00
|
|
|
assert %Ecto.Changeset{} = Events.change_track(track)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
describe "comments" do
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events.Comment
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
@valid_attrs %{text: "some text"}
|
|
|
|
@update_attrs %{text: "some updated text"}
|
2018-05-17 11:32:23 +02:00
|
|
|
@invalid_attrs %{text: nil, url: nil}
|
|
|
|
|
|
|
|
test "list_comments/0 returns all comments" do
|
2018-11-12 18:17:53 +01:00
|
|
|
%Comment{id: comment_id} = insert(:comment)
|
|
|
|
comment_ids = Events.list_comments() |> Enum.map(& &1.id)
|
|
|
|
assert comment_ids == [comment_id]
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "get_comment!/1 returns the comment with given id" do
|
2018-11-12 18:17:53 +01:00
|
|
|
%Comment{id: comment_id} = insert(:comment)
|
|
|
|
comment_fetched = Events.get_comment!(comment_id)
|
|
|
|
assert comment_fetched.id == comment_id
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_comment/1 with valid data creates a comment" do
|
2018-11-12 18:17:53 +01:00
|
|
|
actor = insert(:actor)
|
2018-06-14 17:25:55 +02:00
|
|
|
comment_data = Map.merge(@valid_attrs, %{actor_id: actor.id})
|
2018-11-12 18:17:53 +01:00
|
|
|
|
|
|
|
with {:ok, %Comment{} = comment} <- Events.create_comment(comment_data) do
|
|
|
|
assert comment.text == "some text"
|
|
|
|
assert comment.actor_id == actor.id
|
|
|
|
else
|
|
|
|
err ->
|
|
|
|
flunk("Failed to create a comment #{inspect(err)}")
|
|
|
|
end
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "create_comment/1 with invalid data returns error changeset" do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.create_comment(@invalid_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_comment/2 with valid data updates the comment" do
|
2018-11-12 18:17:53 +01:00
|
|
|
comment = insert(:comment)
|
|
|
|
|
|
|
|
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, @update_attrs) do
|
|
|
|
assert comment.text == "some updated text"
|
|
|
|
else
|
|
|
|
err ->
|
|
|
|
flunk("Failed to update a comment #{inspect(err)}")
|
|
|
|
end
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "update_comment/2 with invalid data returns error changeset" do
|
2018-11-12 18:17:53 +01:00
|
|
|
comment = insert(:comment)
|
2018-05-17 11:32:23 +02:00
|
|
|
assert {:error, %Ecto.Changeset{}} = Events.update_comment(comment, @invalid_attrs)
|
2018-06-14 17:25:55 +02:00
|
|
|
comment_fetched = Events.get_comment!(comment.id)
|
|
|
|
assert comment = comment_fetched
|
2018-05-17 11:32:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_comment/1 deletes the comment" do
|
2018-11-12 18:17:53 +01:00
|
|
|
comment = insert(:comment)
|
2018-05-17 11:32:23 +02:00
|
|
|
assert {:ok, %Comment{}} = Events.delete_comment(comment)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Events.get_comment!(comment.id) end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "change_comment/1 returns a comment changeset" do
|
2018-11-12 18:17:53 +01:00
|
|
|
comment = insert(:comment)
|
2018-05-17 11:32:23 +02:00
|
|
|
assert %Ecto.Changeset{} = Events.change_comment(comment)
|
|
|
|
end
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|