Remove credo and use mix format, and lint everything
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -7,9 +7,36 @@ defmodule Eventos.ActorsTest do
|
||||
describe "actors" do
|
||||
alias Eventos.Actors.Actor
|
||||
|
||||
@valid_attrs %{summary: "some description", name: "some name", domain: "some domain", keys: "some keypair", suspended: true, uri: "some uri", url: "some url", preferred_username: "some username"}
|
||||
@update_attrs %{summary: "some updated description", name: "some updated name", domain: "some updated domain", keys: "some updated keys", suspended: false, uri: "some updated uri", url: "some updated url", preferred_username: "some updated username"}
|
||||
@invalid_attrs %{summary: nil, name: nil, domain: nil, keys: nil, suspended: nil, uri: nil, url: nil, preferred_username: nil}
|
||||
@valid_attrs %{
|
||||
summary: "some description",
|
||||
name: "some name",
|
||||
domain: "some domain",
|
||||
keys: "some keypair",
|
||||
suspended: true,
|
||||
uri: "some uri",
|
||||
url: "some url",
|
||||
preferred_username: "some username"
|
||||
}
|
||||
@update_attrs %{
|
||||
summary: "some updated description",
|
||||
name: "some updated name",
|
||||
domain: "some updated domain",
|
||||
keys: "some updated keys",
|
||||
suspended: false,
|
||||
uri: "some updated uri",
|
||||
url: "some updated url",
|
||||
preferred_username: "some updated username"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
summary: nil,
|
||||
name: nil,
|
||||
domain: nil,
|
||||
keys: nil,
|
||||
suspended: nil,
|
||||
uri: nil,
|
||||
url: nil,
|
||||
preferred_username: nil
|
||||
}
|
||||
|
||||
def actor_fixture(attrs \\ %{}) do
|
||||
{:ok, actor} =
|
||||
@@ -77,7 +104,16 @@ defmodule Eventos.ActorsTest do
|
||||
describe "users" do
|
||||
alias Eventos.Actors.{User, Actor}
|
||||
|
||||
@actor_valid_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", keys: "some keys", suspended: true, uri: "some uri", url: "some url", preferred_username: "some username"}
|
||||
@actor_valid_attrs %{
|
||||
description: "some description",
|
||||
display_name: "some display_name",
|
||||
domain: "some domain",
|
||||
keys: "some keys",
|
||||
suspended: true,
|
||||
uri: "some uri",
|
||||
url: "some url",
|
||||
preferred_username: "some username"
|
||||
}
|
||||
@valid_attrs %{email: "foo@bar.tld", password: "some password", role: 42}
|
||||
@update_attrs %{email: "foo@fighters.tld", password: "some updated password", role: 43}
|
||||
@invalid_attrs %{email: nil, password_hash: nil, role: nil}
|
||||
@@ -138,12 +174,21 @@ defmodule Eventos.ActorsTest do
|
||||
end
|
||||
|
||||
describe "groups" do
|
||||
|
||||
alias Eventos.Actors
|
||||
alias Eventos.Actors.Actor
|
||||
|
||||
@valid_attrs %{summary: "some description", suspended: true, preferred_username: "some-title", name: "Some Title"}
|
||||
@update_attrs %{summary: "some updated description", suspended: false, preferred_username: "some-updated-title", name: "Some Updated Title"}
|
||||
@valid_attrs %{
|
||||
summary: "some description",
|
||||
suspended: true,
|
||||
preferred_username: "some-title",
|
||||
name: "Some Title"
|
||||
}
|
||||
@update_attrs %{
|
||||
summary: "some updated description",
|
||||
suspended: false,
|
||||
preferred_username: "some-updated-title",
|
||||
name: "Some Updated Title"
|
||||
}
|
||||
@invalid_attrs %{summary: nil, suspended: nil, preferred_username: nil, name: nil}
|
||||
|
||||
test "create_group/1 with valid data creates a group" do
|
||||
@@ -184,9 +229,11 @@ defmodule Eventos.ActorsTest do
|
||||
end
|
||||
|
||||
test "create_bot/1 with valid data creates a bot" do
|
||||
attrs = @valid_attrs
|
||||
|> Map.merge(%{actor_id: insert(:actor).id})
|
||||
|> Map.merge(%{user_id: insert(:user).id})
|
||||
attrs =
|
||||
@valid_attrs
|
||||
|> Map.merge(%{actor_id: insert(:actor).id})
|
||||
|> Map.merge(%{user_id: insert(:user).id})
|
||||
|
||||
assert {:ok, %Bot{} = bot} = Actors.create_bot(attrs)
|
||||
assert bot.source == "some source"
|
||||
assert bot.type == "some type"
|
||||
|
||||
@@ -6,9 +6,36 @@ defmodule Eventos.AddressesTest do
|
||||
describe "addresses" do
|
||||
alias Eventos.Addresses.Address
|
||||
|
||||
@valid_attrs %{addressCountry: "some addressCountry", addressLocality: "some addressLocality", addressRegion: "some addressRegion", description: "some description", floor: "some floor", postalCode: "some postalCode", streetAddress: "some streetAddress", geom: %Geo.Point{coordinates: {10, -10}, srid: 4326}}
|
||||
@update_attrs %{addressCountry: "some updated addressCountry", addressLocality: "some updated addressLocality", addressRegion: "some updated addressRegion", description: "some updated description", floor: "some updated floor", postalCode: "some updated postalCode", streetAddress: "some updated streetAddress", geom: %Geo.Point{coordinates: {20, -20}, srid: 4326}}
|
||||
@invalid_attrs %{addressCountry: nil, addressLocality: nil, addressRegion: nil, description: nil, floor: nil, postalCode: nil, streetAddress: nil, geom: nil}
|
||||
@valid_attrs %{
|
||||
addressCountry: "some addressCountry",
|
||||
addressLocality: "some addressLocality",
|
||||
addressRegion: "some addressRegion",
|
||||
description: "some description",
|
||||
floor: "some floor",
|
||||
postalCode: "some postalCode",
|
||||
streetAddress: "some streetAddress",
|
||||
geom: %Geo.Point{coordinates: {10, -10}, srid: 4326}
|
||||
}
|
||||
@update_attrs %{
|
||||
addressCountry: "some updated addressCountry",
|
||||
addressLocality: "some updated addressLocality",
|
||||
addressRegion: "some updated addressRegion",
|
||||
description: "some updated description",
|
||||
floor: "some updated floor",
|
||||
postalCode: "some updated postalCode",
|
||||
streetAddress: "some updated streetAddress",
|
||||
geom: %Geo.Point{coordinates: {20, -20}, srid: 4326}
|
||||
}
|
||||
@invalid_attrs %{
|
||||
addressCountry: nil,
|
||||
addressLocality: nil,
|
||||
addressRegion: nil,
|
||||
description: nil,
|
||||
floor: nil,
|
||||
postalCode: nil,
|
||||
streetAddress: nil,
|
||||
geom: nil
|
||||
}
|
||||
|
||||
def address_fixture(attrs \\ %{}) do
|
||||
{:ok, address} =
|
||||
|
||||
@@ -6,7 +6,12 @@ defmodule Eventos.EventsTest do
|
||||
alias Eventos.Events
|
||||
alias Eventos.Actors
|
||||
|
||||
@event_valid_attrs %{begins_on: "2010-04-17 14:00:00.000000Z", description: "some description", ends_on: "2010-04-17 14:00:00.000000Z", title: "some title"}
|
||||
@event_valid_attrs %{
|
||||
begins_on: "2010-04-17 14:00:00.000000Z",
|
||||
description: "some description",
|
||||
ends_on: "2010-04-17 14:00:00.000000Z",
|
||||
title: "some title"
|
||||
}
|
||||
|
||||
def actor_fixture do
|
||||
insert(:actor)
|
||||
@@ -27,8 +32,18 @@ defmodule Eventos.EventsTest do
|
||||
describe "events" do
|
||||
alias Eventos.Events.Event
|
||||
|
||||
@valid_attrs %{begins_on: "2010-04-17 14:00:00.000000Z", description: "some description", ends_on: "2010-04-17 14:00:00.000000Z", title: "some title"}
|
||||
@update_attrs %{begins_on: "2011-05-18 15:01:01.000000Z", description: "some updated description", ends_on: "2011-05-18 15:01:01.000000Z", title: "some updated title"}
|
||||
@valid_attrs %{
|
||||
begins_on: "2010-04-17 14:00:00.000000Z",
|
||||
description: "some description",
|
||||
ends_on: "2010-04-17 14:00:00.000000Z",
|
||||
title: "some title"
|
||||
}
|
||||
@update_attrs %{
|
||||
begins_on: "2011-05-18 15:01:01.000000Z",
|
||||
description: "some updated description",
|
||||
ends_on: "2011-05-18 15:01:01.000000Z",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{begins_on: nil, description: nil, ends_on: nil, title: nil}
|
||||
|
||||
test "list_events/0 returns all events" do
|
||||
@@ -45,11 +60,14 @@ defmodule Eventos.EventsTest do
|
||||
actor = actor_fixture()
|
||||
category = category_fixture()
|
||||
address = address_fixture()
|
||||
valid_attrs = @event_valid_attrs
|
||||
|
||||
valid_attrs =
|
||||
@event_valid_attrs
|
||||
|> Map.put(:organizer_actor, actor)
|
||||
|> Map.put(:organizer_actor_id, actor.id)
|
||||
|> Map.put(:category_id, category.id)
|
||||
|> Map.put(:address_id, address.id)
|
||||
|
||||
assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
|
||||
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00.000000Z], "Etc/UTC")
|
||||
assert event.description == "some description"
|
||||
@@ -93,7 +111,11 @@ defmodule Eventos.EventsTest do
|
||||
alias Eventos.Events.Category
|
||||
|
||||
@valid_attrs %{description: "some description", picture: "some picture", title: "some title"}
|
||||
@update_attrs %{description: "some updated description", picture: "some updated picture", title: "some updated title"}
|
||||
@update_attrs %{
|
||||
description: "some updated description",
|
||||
picture: "some updated picture",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{description: nil, picture: nil, title: nil}
|
||||
|
||||
test "list_categories/0 returns all categories" do
|
||||
@@ -216,6 +238,7 @@ defmodule Eventos.EventsTest do
|
||||
actor = actor_fixture()
|
||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
||||
valid_attrs = Map.put(valid_attrs, :actor_id, actor.id)
|
||||
|
||||
{:ok, participant} =
|
||||
attrs
|
||||
|> Enum.into(valid_attrs)
|
||||
@@ -229,10 +252,10 @@ defmodule Eventos.EventsTest do
|
||||
assert Events.list_participants() == [participant]
|
||||
end
|
||||
|
||||
# test "get_participant!/1 returns the participant with given id" do
|
||||
# participant = participant_fixture()
|
||||
# assert Events.get_participant!(participant.id) == participant
|
||||
# end
|
||||
# test "get_participant!/1 returns the participant with given id" do
|
||||
# participant = participant_fixture()
|
||||
# assert Events.get_participant!(participant.id) == participant
|
||||
# end
|
||||
|
||||
test "create_participant/1 with valid data creates a participant" do
|
||||
actor = actor_fixture()
|
||||
@@ -273,13 +296,41 @@ defmodule Eventos.EventsTest do
|
||||
describe "sessions" do
|
||||
alias Eventos.Events.Session
|
||||
|
||||
@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}
|
||||
@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
|
||||
}
|
||||
|
||||
def session_fixture(attrs \\ %{}) do
|
||||
event = event_fixture()
|
||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
||||
|
||||
{:ok, session} =
|
||||
attrs
|
||||
|> Enum.into(valid_attrs)
|
||||
@@ -352,12 +403,17 @@ defmodule Eventos.EventsTest do
|
||||
alias Eventos.Events.Track
|
||||
|
||||
@valid_attrs %{color: "some color", description: "some description", name: "some name"}
|
||||
@update_attrs %{color: "some updated color", description: "some updated description", name: "some updated name"}
|
||||
@update_attrs %{
|
||||
color: "some updated color",
|
||||
description: "some updated description",
|
||||
name: "some updated name"
|
||||
}
|
||||
@invalid_attrs %{color: nil, description: nil, name: nil}
|
||||
|
||||
def track_fixture(attrs \\ %{}) do
|
||||
event = event_fixture()
|
||||
valid_attrs = Map.put(@valid_attrs, :event_id, event.id)
|
||||
|
||||
{:ok, track} =
|
||||
attrs
|
||||
|> Enum.into(valid_attrs)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
defmodule Eventos.Service.Activitypub.ActivitypubTest do
|
||||
|
||||
use Eventos.DataCase
|
||||
|
||||
import Eventos.Factory
|
||||
@@ -11,7 +10,8 @@ defmodule Eventos.Service.Activitypub.ActivitypubTest do
|
||||
|
||||
describe "fetching actor from it's url" do
|
||||
test "returns an actor" do
|
||||
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"} = actor} = ActivityPub.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"} = actor} =
|
||||
ActivityPub.make_actor_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ defmodule Eventos.Service.WebFingerTest do
|
||||
|
||||
{:ok, result} =
|
||||
WebFinger.webfinger("#{actor.preferred_username}@#{EventosWeb.Endpoint.host()}", "JSON")
|
||||
|
||||
assert is_map(result)
|
||||
end
|
||||
|
||||
@@ -29,23 +30,29 @@ defmodule Eventos.Service.WebFingerTest do
|
||||
end
|
||||
|
||||
describe "fingering" do
|
||||
|
||||
test "a mastodon actor" do
|
||||
actor = "tcit@social.tcit.fr"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> actor, "url" => "https://social.tcit.fr/users/tcit"}} = WebFinger.finger(actor)
|
||||
assert {:ok, %{"subject" => "acct:" <> actor, "url" => "https://social.tcit.fr/users/tcit"}} =
|
||||
WebFinger.finger(actor)
|
||||
end
|
||||
|
||||
test "a pleroma actor" do
|
||||
actor = "@lain@pleroma.soykaf.com"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> actor, "url" => "https://pleroma.soykaf.com/users/lain"}} = WebFinger.finger(actor)
|
||||
assert {:ok,
|
||||
%{"subject" => "acct:" <> actor, "url" => "https://pleroma.soykaf.com/users/lain"}} =
|
||||
WebFinger.finger(actor)
|
||||
end
|
||||
|
||||
test "a peertube actor" do
|
||||
actor = "framasoft@framatube.org"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> actor, "url" => "https://framatube.org/accounts/framasoft"}} = WebFinger.finger(actor)
|
||||
assert {:ok,
|
||||
%{
|
||||
"subject" => "acct:" <> actor,
|
||||
"url" => "https://framatube.org/accounts/framasoft"
|
||||
}} = WebFinger.finger(actor)
|
||||
end
|
||||
|
||||
test "a friendica actor" do
|
||||
|
||||
@@ -18,7 +18,7 @@ defmodule EventosWeb.ActivityPubControllerTest do
|
||||
actor = Actors.get_actor!(actor.id)
|
||||
|
||||
assert json_response(conn, 200) == ActorView.render("actor.json", %{actor: actor})
|
||||
Logger.error(inspect ActorView.render("actor.json", %{actor: actor}))
|
||||
Logger.error(inspect(ActorView.render("actor.json", %{actor: actor})))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,106 +32,106 @@ defmodule EventosWeb.ActivityPubControllerTest do
|
||||
|> get("/events/#{event.uuid}")
|
||||
|
||||
assert json_response(conn, 200) == ObjectView.render("event.json", %{event: event})
|
||||
Logger.error(inspect ObjectView.render("event.json", %{event: event}))
|
||||
Logger.error(inspect(ObjectView.render("event.json", %{event: event})))
|
||||
end
|
||||
end
|
||||
|
||||
# describe "/actors/:username/inbox" do
|
||||
# test "it inserts an incoming activity into the database", %{conn: conn} do
|
||||
# data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
#
|
||||
# conn =
|
||||
# conn
|
||||
# |> assign(:valid_signature, true)
|
||||
# |> put_req_header("content-type", "application/activity+json")
|
||||
# |> post("/inbox", data)
|
||||
#
|
||||
# assert "ok" == json_response(conn, 200)
|
||||
# :timer.sleep(500)
|
||||
# assert Activity.get_by_ap_id(data["id"])
|
||||
# end
|
||||
# end
|
||||
# describe "/actors/:username/inbox" do
|
||||
# test "it inserts an incoming activity into the database", %{conn: conn} do
|
||||
# data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
#
|
||||
# conn =
|
||||
# conn
|
||||
# |> assign(:valid_signature, true)
|
||||
# |> put_req_header("content-type", "application/activity+json")
|
||||
# |> post("/inbox", data)
|
||||
#
|
||||
# assert "ok" == json_response(conn, 200)
|
||||
# :timer.sleep(500)
|
||||
# assert Activity.get_by_ap_id(data["id"])
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "/actors/:nickname/followers" do
|
||||
# test "it returns the followers in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user_two.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# other_user = insert(:user)
|
||||
# User.follow(other_user, user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# describe "/users/:nickname/following" do
|
||||
# test "it returns the following in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user_two.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# user = Repo.get(User, user.id)
|
||||
# other_user = insert(:user)
|
||||
# User.follow(user, other_user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
# describe "/actors/:nickname/followers" do
|
||||
# test "it returns the followers in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user_two.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# other_user = insert(:user)
|
||||
# User.follow(other_user, user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# describe "/users/:nickname/following" do
|
||||
# test "it returns the following in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user_two.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# user = Repo.get(User, user.id)
|
||||
# other_user = insert(:user)
|
||||
# User.follow(user, other_user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -15,11 +15,17 @@ defmodule EventosWeb.ActorControllerTest do
|
||||
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
||||
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
||||
|
||||
@create_attrs %{preferred_username: "otheridentity", summary: "This is my other identity", domain: nil, keys: pem, user: nil}
|
||||
@create_attrs %{
|
||||
preferred_username: "otheridentity",
|
||||
summary: "This is my other identity",
|
||||
domain: nil,
|
||||
keys: pem,
|
||||
user: nil
|
||||
}
|
||||
|
||||
describe "index" do
|
||||
test "lists all actors", %{conn: conn, user: user, actor: actor} do
|
||||
conn = get conn, actor_path(conn, :index)
|
||||
conn = get(conn, actor_path(conn, :index))
|
||||
assert hd(json_response(conn, 200)["data"])["username"] == actor.preferred_username
|
||||
end
|
||||
end
|
||||
@@ -27,32 +33,32 @@ defmodule EventosWeb.ActorControllerTest do
|
||||
describe "create actor" do
|
||||
test "from an existing user", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, actor_path(conn, :create), actor: @create_attrs
|
||||
conn = post(conn, actor_path(conn, :create), actor: @create_attrs)
|
||||
assert json_response(conn, 201)["data"]["username"] == @create_attrs.preferred_username
|
||||
end
|
||||
end
|
||||
|
||||
###
|
||||
# Not possible atm
|
||||
###
|
||||
# describe "delete actor" do
|
||||
# setup [:create_actor]
|
||||
#
|
||||
# test "deletes own actor", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, user.actor)
|
||||
# assert response(conn, 204)
|
||||
# assert_error_sent 404, fn ->
|
||||
# get conn, actor_path(conn, :show, user.actor)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# test "deletes other actor", %{conn: conn, actor: actor, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, actor)
|
||||
# assert response(conn, 401)
|
||||
# conn = get conn, actor_path(conn, :show, actor)
|
||||
# assert response(conn, 200)
|
||||
# end
|
||||
# end
|
||||
###
|
||||
# Not possible atm
|
||||
###
|
||||
# describe "delete actor" do
|
||||
# setup [:create_actor]
|
||||
#
|
||||
# test "deletes own actor", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, user.actor)
|
||||
# assert response(conn, 204)
|
||||
# assert_error_sent 404, fn ->
|
||||
# get conn, actor_path(conn, :show, user.actor)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# test "deletes other actor", %{conn: conn, actor: actor, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, actor)
|
||||
# assert response(conn, 401)
|
||||
# conn = get conn, actor_path(conn, :show, actor)
|
||||
# assert response(conn, 200)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -6,9 +6,36 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
alias Eventos.Addresses
|
||||
alias Eventos.Addresses.Address
|
||||
|
||||
@create_attrs %{addressCountry: "some addressCountry", addressLocality: "some addressLocality", addressRegion: "some addressRegion", description: "some description", floor: "some floor", postalCode: "some postalCode", streetAddress: "some streetAddress", geom: %{type: :point, data: %{latitude: -20, longitude: 30}}}
|
||||
@update_attrs %{addressCountry: "some updated addressCountry", addressLocality: "some updated addressLocality", addressRegion: "some updated addressRegion", description: "some updated description", floor: "some updated floor", postalCode: "some updated postalCode", streetAddress: "some updated streetAddress", geom: %{type: :point, data: %{latitude: -40, longitude: 40}}}
|
||||
@invalid_attrs %{addressCountry: nil, addressLocality: nil, addressRegion: nil, description: nil, floor: nil, postalCode: nil, streetAddress: nil, geom: %{type: nil, data: %{latitude: nil, longitude: nil}}}
|
||||
@create_attrs %{
|
||||
addressCountry: "some addressCountry",
|
||||
addressLocality: "some addressLocality",
|
||||
addressRegion: "some addressRegion",
|
||||
description: "some description",
|
||||
floor: "some floor",
|
||||
postalCode: "some postalCode",
|
||||
streetAddress: "some streetAddress",
|
||||
geom: %{type: :point, data: %{latitude: -20, longitude: 30}}
|
||||
}
|
||||
@update_attrs %{
|
||||
addressCountry: "some updated addressCountry",
|
||||
addressLocality: "some updated addressLocality",
|
||||
addressRegion: "some updated addressRegion",
|
||||
description: "some updated description",
|
||||
floor: "some updated floor",
|
||||
postalCode: "some updated postalCode",
|
||||
streetAddress: "some updated streetAddress",
|
||||
geom: %{type: :point, data: %{latitude: -40, longitude: 40}}
|
||||
}
|
||||
@invalid_attrs %{
|
||||
addressCountry: nil,
|
||||
addressLocality: nil,
|
||||
addressRegion: nil,
|
||||
description: nil,
|
||||
floor: nil,
|
||||
postalCode: nil,
|
||||
streetAddress: nil,
|
||||
geom: %{type: nil, data: %{latitude: nil, longitude: nil}}
|
||||
}
|
||||
|
||||
def fixture(:address) do
|
||||
{:ok, address} = Addresses.create_address(@create_attrs)
|
||||
@@ -24,7 +51,7 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
describe "index" do
|
||||
test "lists all addresses", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get conn, address_path(conn, :index)
|
||||
conn = get(conn, address_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -32,26 +59,30 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
describe "create address" do
|
||||
test "renders address when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, address_path(conn, :create), address: @create_attrs
|
||||
conn = post(conn, address_path(conn, :create), address: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, address_path(conn, :show, id)
|
||||
conn = get(conn, address_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"description" => "some description",
|
||||
"floor" => "some floor",
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress",
|
||||
"geom" => %{"data" => %{"latitude" => -20.0, "longitude" => 30.0}, "type" => "point"}
|
||||
}
|
||||
"id" => id,
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"description" => "some description",
|
||||
"floor" => "some floor",
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -20.0, "longitude" => 30.0},
|
||||
"type" => "point"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, address_path(conn, :create), address: @invalid_attrs
|
||||
conn = post(conn, address_path(conn, :create), address: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -59,28 +90,36 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
describe "update address" do
|
||||
setup [:create_address]
|
||||
|
||||
test "renders address when data is valid", %{conn: conn, address: %Address{id: id} = address, user: user} do
|
||||
test "renders address when data is valid", %{
|
||||
conn: conn,
|
||||
address: %Address{id: id} = address,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, address_path(conn, :update, address), address: @update_attrs
|
||||
conn = put(conn, address_path(conn, :update, address), address: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, address_path(conn, :show, id)
|
||||
conn = get(conn, address_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"addressCountry" => "some updated addressCountry",
|
||||
"addressLocality" => "some updated addressLocality",
|
||||
"addressRegion" => "some updated addressRegion",
|
||||
"description" => "some updated description",
|
||||
"floor" => "some updated floor",
|
||||
"postalCode" => "some updated postalCode",
|
||||
"streetAddress" => "some updated streetAddress",
|
||||
"geom" => %{"data" => %{"latitude" => -40.0, "longitude" => 40.0}, "type" => "point"}
|
||||
}
|
||||
"id" => id,
|
||||
"addressCountry" => "some updated addressCountry",
|
||||
"addressLocality" => "some updated addressLocality",
|
||||
"addressRegion" => "some updated addressRegion",
|
||||
"description" => "some updated description",
|
||||
"floor" => "some updated floor",
|
||||
"postalCode" => "some updated postalCode",
|
||||
"streetAddress" => "some updated streetAddress",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -40.0, "longitude" => 40.0},
|
||||
"type" => "point"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, address: address, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, address_path(conn, :update, address), address: @invalid_attrs
|
||||
conn = put(conn, address_path(conn, :update, address), address: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -90,11 +129,12 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
|
||||
test "deletes chosen address", %{conn: conn, address: address, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, address_path(conn, :delete, address)
|
||||
conn = delete(conn, address_path(conn, :delete, address))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, address_path(conn, :show, address)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, address_path(conn, :show, address))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ defmodule EventosWeb.BotControllerTest do
|
||||
alias Eventos.Actors.Bot
|
||||
|
||||
@create_attrs %{source: "some source", type: "some type", name: "some name"}
|
||||
@update_attrs %{source: "some updated source", type: "some updated type", name: "some updated name"}
|
||||
@update_attrs %{
|
||||
source: "some updated source",
|
||||
type: "some updated type",
|
||||
name: "some updated name"
|
||||
}
|
||||
@invalid_attrs %{source: nil, type: nil, name: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
@@ -18,7 +22,7 @@ defmodule EventosWeb.BotControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all bots", %{conn: conn} do
|
||||
conn = get conn, bot_path(conn, :index)
|
||||
conn = get(conn, bot_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -26,19 +30,21 @@ defmodule EventosWeb.BotControllerTest do
|
||||
describe "create bot" do
|
||||
test "renders bot when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, bot_path(conn, :create), bot: @create_attrs
|
||||
conn = post(conn, bot_path(conn, :create), bot: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, bot_path(conn, :show, id)
|
||||
conn = get(conn, bot_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some source",
|
||||
"type" => "some type"}
|
||||
"id" => id,
|
||||
"source" => "some source",
|
||||
"type" => "some type"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, bot_path(conn, :create), bot: @invalid_attrs
|
||||
conn = post(conn, bot_path(conn, :create), bot: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -48,19 +54,21 @@ defmodule EventosWeb.BotControllerTest do
|
||||
|
||||
test "renders bot when data is valid", %{conn: conn, bot: %Bot{id: id} = bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, bot_path(conn, :update, bot), bot: @update_attrs
|
||||
conn = put(conn, bot_path(conn, :update, bot), bot: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, bot_path(conn, :show, id)
|
||||
conn = get(conn, bot_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some updated source",
|
||||
"type" => "some updated type"}
|
||||
"id" => id,
|
||||
"source" => "some updated source",
|
||||
"type" => "some updated type"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, bot: bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, bot_path(conn, :update, bot), bot: @invalid_attrs
|
||||
conn = put(conn, bot_path(conn, :update, bot), bot: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -70,11 +78,12 @@ defmodule EventosWeb.BotControllerTest do
|
||||
|
||||
test "deletes chosen bot", %{conn: conn, bot: bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, bot_path(conn, :delete, bot)
|
||||
conn = delete(conn, bot_path(conn, :delete, bot))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, bot_path(conn, :show, bot)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, bot_path(conn, :show, bot))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
alias Eventos.Events.Category
|
||||
|
||||
@create_attrs %{description: "some description", picture: "some picture", title: "some title"}
|
||||
@update_attrs %{description: "some updated description", picture: "some updated picture", title: "some updated title"}
|
||||
@update_attrs %{
|
||||
description: "some updated description",
|
||||
picture: "some updated picture",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{description: nil, picture: nil, title: nil}
|
||||
|
||||
def fixture(:category) do
|
||||
@@ -23,7 +27,7 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all categories", %{conn: conn} do
|
||||
conn = get conn, category_path(conn, :index)
|
||||
conn = get(conn, category_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -31,20 +35,22 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
describe "create category" do
|
||||
test "renders category when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, category_path(conn, :create), category: @create_attrs
|
||||
conn = post(conn, category_path(conn, :create), category: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, category_path(conn, :show, id)
|
||||
conn = get(conn, category_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some description",
|
||||
"picture" => "some picture",
|
||||
"title" => "some title"}
|
||||
"id" => id,
|
||||
"description" => "some description",
|
||||
"picture" => "some picture",
|
||||
"title" => "some title"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, category_path(conn, :create), category: @invalid_attrs
|
||||
conn = post(conn, category_path(conn, :create), category: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -52,22 +58,28 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
describe "update category" do
|
||||
setup [:create_category]
|
||||
|
||||
test "renders category when data is valid", %{conn: conn, category: %Category{id: id} = category, user: user} do
|
||||
test "renders category when data is valid", %{
|
||||
conn: conn,
|
||||
category: %Category{id: id} = category,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, category_path(conn, :update, category), category: @update_attrs
|
||||
conn = put(conn, category_path(conn, :update, category), category: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, category_path(conn, :show, id)
|
||||
conn = get(conn, category_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some updated description",
|
||||
"picture" => "some updated picture",
|
||||
"title" => "some updated title"}
|
||||
"id" => id,
|
||||
"description" => "some updated description",
|
||||
"picture" => "some updated picture",
|
||||
"title" => "some updated title"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, category: category, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, category_path(conn, :update, category), category: @invalid_attrs
|
||||
conn = put(conn, category_path(conn, :update, category), category: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -77,11 +89,12 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
|
||||
test "deletes chosen category", %{conn: conn, category: category, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, category_path(conn, :delete, category)
|
||||
conn = delete(conn, category_path(conn, :delete, category))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, category_path(conn, :show, category)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, category_path(conn, :show, category))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -20,21 +20,22 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
test "renders comment when data is valid", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.merge(@create_attrs, %{actor_id: actor.id})
|
||||
conn = post conn, comment_path(conn, :create), comment: attrs
|
||||
conn = post(conn, comment_path(conn, :create), comment: attrs)
|
||||
assert %{"uuid" => uuid, "id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, comment_path(conn, :show, uuid)
|
||||
conn = get(conn, comment_path(conn, :show, uuid))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
"id" => id,
|
||||
"text" => "some text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, comment_path(conn, :create), comment: @invalid_attrs
|
||||
conn = post(conn, comment_path(conn, :create), comment: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -42,24 +43,30 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
describe "update comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "renders comment when data is valid", %{conn: conn, comment: %Comment{id: id, uuid: uuid} = comment, user: user, actor: actor} do
|
||||
test "renders comment when data is valid", %{
|
||||
conn: conn,
|
||||
comment: %Comment{id: id, uuid: uuid} = comment,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.merge(@update_attrs, %{actor_id: actor.id})
|
||||
conn = put conn, comment_path(conn, :update, uuid), comment: attrs
|
||||
conn = put(conn, comment_path(conn, :update, uuid), comment: attrs)
|
||||
assert %{"uuid" => uuid, "id" => id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, comment_path(conn, :show, uuid)
|
||||
conn = get(conn, comment_path(conn, :show, uuid))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some updated text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
"id" => id,
|
||||
"text" => "some updated text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, comment: comment, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, comment_path(conn, :update, comment.uuid), comment: @invalid_attrs
|
||||
conn = put(conn, comment_path(conn, :update, comment.uuid), comment: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -67,13 +74,18 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
describe "delete comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "deletes chosen comment", %{conn: conn, comment: %Comment{uuid: uuid} = comment, user: user} do
|
||||
test "deletes chosen comment", %{
|
||||
conn: conn,
|
||||
comment: %Comment{uuid: uuid} = comment,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, comment_path(conn, :delete, uuid)
|
||||
conn = delete(conn, comment_path(conn, :delete, uuid))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, comment_path(conn, :show, uuid)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, comment_path(conn, :show, uuid))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,10 +6,29 @@ defmodule EventosWeb.EventControllerTest do
|
||||
alias Eventos.Events.Event
|
||||
alias Eventos.Export.ICalendar
|
||||
|
||||
@create_attrs %{begins_on: "2010-04-17 14:00:00.000000Z", description: "some description", ends_on: "2010-04-17 14:00:00.000000Z", title: "some title"}
|
||||
@update_attrs %{begins_on: "2011-05-18 15:01:01.000000Z", description: "some updated description", ends_on: "2011-05-18 15:01:01.000000Z", title: "some updated title"}
|
||||
@create_attrs %{
|
||||
begins_on: "2010-04-17 14:00:00.000000Z",
|
||||
description: "some description",
|
||||
ends_on: "2010-04-17 14:00:00.000000Z",
|
||||
title: "some title"
|
||||
}
|
||||
@update_attrs %{
|
||||
begins_on: "2011-05-18 15:01:01.000000Z",
|
||||
description: "some updated description",
|
||||
ends_on: "2011-05-18 15:01:01.000000Z",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{begins_on: nil, description: nil, ends_on: nil, title: nil, address_id: nil}
|
||||
@create_address_attrs %{"addressCountry" => "some addressCountry", "addressLocality" => "some addressLocality", "addressRegion" => "some addressRegion", "description" => "some description", "floor" => "some floor", "postalCode" => "some postalCode", "streetAddress" => "some streetAddress", "geom" => %{"type" => :point, "data" => %{"latitude" => -20, "longitude" => 30}}}
|
||||
@create_address_attrs %{
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"description" => "some description",
|
||||
"floor" => "some floor",
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress",
|
||||
"geom" => %{"type" => :point, "data" => %{"latitude" => -20, "longitude" => 30}}
|
||||
}
|
||||
|
||||
def fixture(:event) do
|
||||
{:ok, event} = Events.create_event(@create_attrs)
|
||||
@@ -28,7 +47,7 @@ defmodule EventosWeb.EventControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all events", %{conn: conn} do
|
||||
conn = get conn, event_path(conn, :index)
|
||||
conn = get(conn, event_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -41,25 +60,37 @@ defmodule EventosWeb.EventControllerTest do
|
||||
category = insert(:category)
|
||||
attrs = Map.put(attrs, :category_id, category.id)
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, event_path(conn, :create), event: attrs
|
||||
conn = post(conn, event_path(conn, :create), event: attrs)
|
||||
assert %{"uuid" => uuid} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, event_path(conn, :show, uuid)
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
|
||||
assert %{
|
||||
"begins_on" => "2010-04-17T14:00:00Z",
|
||||
"description" => "some description",
|
||||
"ends_on" => "2010-04-17T14:00:00Z",
|
||||
"title" => "some title",
|
||||
"participants" => [],
|
||||
"physical_address" => %{"addressCountry" => "some addressCountry", "addressLocality" => "some addressLocality", "addressRegion" => "some addressRegion", "floor" => "some floor", "geom" => %{"data" => %{"latitude" => -20.0, "longitude" => 30.0}, "type" => "point"}, "postalCode" => "some postalCode", "streetAddress" => "some streetAddress"}
|
||||
} = json_response(conn, 200)["data"]
|
||||
"begins_on" => "2010-04-17T14:00:00Z",
|
||||
"description" => "some description",
|
||||
"ends_on" => "2010-04-17T14:00:00Z",
|
||||
"title" => "some title",
|
||||
"participants" => [],
|
||||
"physical_address" => %{
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"floor" => "some floor",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -20.0, "longitude" => 30.0},
|
||||
"type" => "point"
|
||||
},
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress"
|
||||
}
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, actor.id)
|
||||
attrs = Map.put(attrs, :address, @create_address_attrs)
|
||||
conn = post conn, event_path(conn, :create), event: attrs
|
||||
conn = post(conn, event_path(conn, :create), event: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -67,9 +98,13 @@ defmodule EventosWeb.EventControllerTest do
|
||||
describe "export event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders ics export of event", %{conn: conn, event: %Event{uuid: uuid} = event, user: user} do
|
||||
test "renders ics export of event", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get conn, event_path(conn, :export_to_ics, uuid)
|
||||
conn = get(conn, event_path(conn, :export_to_ics, uuid))
|
||||
exported_event = ICalendar.export_event(event)
|
||||
assert exported_event == response(conn, 200)
|
||||
end
|
||||
@@ -78,29 +113,51 @@ defmodule EventosWeb.EventControllerTest do
|
||||
describe "update event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders event when data is valid", %{conn: conn, event: %Event{uuid: uuid} = event, user: user, actor: actor} do
|
||||
test "renders event when data is valid", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
address = address_fixture()
|
||||
attrs = Map.put(@update_attrs, :organizer_actor_id, actor.id)
|
||||
attrs = Map.put(attrs, :address_id, address.id)
|
||||
conn = put conn, event_path(conn, :update, uuid), event: attrs
|
||||
conn = put(conn, event_path(conn, :update, uuid), event: attrs)
|
||||
assert %{"uuid" => uuid} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, event_path(conn, :show, uuid)
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
|
||||
assert %{
|
||||
"begins_on" => "2011-05-18T15:01:01Z",
|
||||
"description" => "some updated description",
|
||||
"ends_on" => "2011-05-18T15:01:01Z",
|
||||
"title" => "some updated title",
|
||||
"participants" => [],
|
||||
"physical_address" => %{"addressCountry" => "My Country", "addressLocality" => "My Locality", "addressRegion" => "My Region", "floor" => "Myfloor", "geom" => %{"data" => %{"latitude" => 30.0, "longitude" => -90.0}, "type" => "point"}, "postalCode" => "My Postal Code", "streetAddress" => "My Street Address"}
|
||||
"physical_address" => %{
|
||||
"addressCountry" => "My Country",
|
||||
"addressLocality" => "My Locality",
|
||||
"addressRegion" => "My Region",
|
||||
"floor" => "Myfloor",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => 30.0, "longitude" => -90.0},
|
||||
"type" => "point"
|
||||
},
|
||||
"postalCode" => "My Postal Code",
|
||||
"streetAddress" => "My Street Address"
|
||||
}
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, event: %Event{uuid: uuid} = event, user: user, actor: actor} do
|
||||
test "renders errors when data is invalid", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, actor.id)
|
||||
conn = put conn, event_path(conn, :update, uuid), event: attrs
|
||||
conn = put(conn, event_path(conn, :update, uuid), event: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -110,9 +167,9 @@ defmodule EventosWeb.EventControllerTest do
|
||||
|
||||
test "deletes chosen event", %{conn: conn, event: %Event{uuid: uuid} = event, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, event_path(conn, :delete, uuid)
|
||||
conn = delete(conn, event_path(conn, :delete, uuid))
|
||||
assert response(conn, 204)
|
||||
conn = get conn, event_path(conn, :show, uuid)
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
assert response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ defmodule EventosWeb.PageControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get conn, "/"
|
||||
conn = get(conn, "/")
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,9 +6,36 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
alias Eventos.Events
|
||||
alias Eventos.Events.Session
|
||||
|
||||
@create_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}
|
||||
@create_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
|
||||
}
|
||||
|
||||
def fixture(:session) do
|
||||
{:ok, session} = Events.create_session(@create_attrs)
|
||||
@@ -24,7 +51,7 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all sessions", %{conn: conn} do
|
||||
conn = get conn, session_path(conn, :index)
|
||||
conn = get(conn, session_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -34,29 +61,31 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
conn = auth_conn(conn, user)
|
||||
event_id = event.id
|
||||
attrs = Map.put(@create_attrs, :event_id, event_id)
|
||||
conn = post conn, session_path(conn, :create), session: attrs
|
||||
conn = post(conn, session_path(conn, :create), session: attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, session_path(conn, :show_sessions_for_event, event.uuid)
|
||||
conn = get(conn, session_path(conn, :show_sessions_for_event, event.uuid))
|
||||
assert hd(json_response(conn, 200)["data"])["id"] == id
|
||||
|
||||
conn = get conn, session_path(conn, :show, id)
|
||||
conn = get(conn, session_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"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"}
|
||||
"id" => id,
|
||||
"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"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = post conn, session_path(conn, :create), session: attrs
|
||||
conn = post(conn, session_path(conn, :create), session: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -64,28 +93,35 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
describe "update session" do
|
||||
setup [:create_session]
|
||||
|
||||
test "renders session when data is valid", %{conn: conn, session: %Session{id: id} = session, user: user, event: event} do
|
||||
test "renders session when data is valid", %{
|
||||
conn: conn,
|
||||
session: %Session{id: id} = session,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@update_attrs, :event_id, event.id)
|
||||
conn = patch conn, session_path(conn, :update, session), session: attrs
|
||||
conn = patch(conn, session_path(conn, :update, session), session: attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, session_path(conn, :show, id)
|
||||
conn = get(conn, session_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"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"}
|
||||
"id" => id,
|
||||
"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"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, session: session, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = patch conn, session_path(conn, :update, session), session: @invalid_attrs
|
||||
conn = patch(conn, session_path(conn, :update, session), session: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -95,11 +131,12 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
|
||||
test "deletes chosen session", %{conn: conn, session: session, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, session_path(conn, :delete, session)
|
||||
conn = delete(conn, session_path(conn, :delete, session))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, session_path(conn, :show, session)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, session_path(conn, :show, session))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ defmodule EventosWeb.TagControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all tags", %{conn: conn} do
|
||||
conn = get conn, tag_path(conn, :index)
|
||||
conn = get(conn, tag_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -31,18 +31,16 @@ defmodule EventosWeb.TagControllerTest do
|
||||
describe "create tag" do
|
||||
test "renders tag when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, tag_path(conn, :create), tag: @create_attrs
|
||||
conn = post(conn, tag_path(conn, :create), tag: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, tag_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"title" => "some title"}
|
||||
conn = get(conn, tag_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "title" => "some title"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, tag_path(conn, :create), tag: @invalid_attrs
|
||||
conn = post(conn, tag_path(conn, :create), tag: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -52,18 +50,16 @@ defmodule EventosWeb.TagControllerTest do
|
||||
|
||||
test "renders tag when data is valid", %{conn: conn, tag: %Tag{id: id} = tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, tag_path(conn, :update, tag), tag: @update_attrs
|
||||
conn = put(conn, tag_path(conn, :update, tag), tag: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, tag_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"title" => "some updated title"}
|
||||
conn = get(conn, tag_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "title" => "some updated title"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, tag: tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, tag_path(conn, :update, tag), tag: @invalid_attrs
|
||||
conn = put(conn, tag_path(conn, :update, tag), tag: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -73,11 +69,12 @@ defmodule EventosWeb.TagControllerTest do
|
||||
|
||||
test "deletes chosen tag", %{conn: conn, tag: tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, tag_path(conn, :delete, tag)
|
||||
conn = delete(conn, tag_path(conn, :delete, tag))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, tag_path(conn, :show, tag)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, tag_path(conn, :show, tag))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
alias Eventos.Events.Track
|
||||
|
||||
@create_attrs %{color: "some color", description: "some description", name: "some name"}
|
||||
@update_attrs %{color: "some updated color", description: "some updated description", name: "some updated name"}
|
||||
@update_attrs %{
|
||||
color: "some updated color",
|
||||
description: "some updated description",
|
||||
name: "some updated name"
|
||||
}
|
||||
@invalid_attrs %{color: nil, description: nil, name: nil}
|
||||
|
||||
def fixture(:track) do
|
||||
@@ -24,7 +28,7 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
|
||||
describe "index" do
|
||||
test "lists all tracks", %{conn: conn} do
|
||||
conn = get conn, track_path(conn, :index)
|
||||
conn = get(conn, track_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
@@ -33,21 +37,23 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
test "renders track when data is valid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@create_attrs, :event_id, event.id)
|
||||
conn = post conn, track_path(conn, :create), track: attrs
|
||||
conn = post(conn, track_path(conn, :create), track: attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, track_path(conn, :show, id)
|
||||
conn = get(conn, track_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"color" => "some color",
|
||||
"description" => "some description",
|
||||
"name" => "some name"}
|
||||
"id" => id,
|
||||
"color" => "some color",
|
||||
"description" => "some description",
|
||||
"name" => "some name"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = post conn, track_path(conn, :create), track: attrs
|
||||
conn = post(conn, track_path(conn, :create), track: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -55,24 +61,36 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
describe "update track" do
|
||||
setup [:create_track]
|
||||
|
||||
test "renders track when data is valid", %{conn: conn, track: %Track{id: id} = track, user: user, event: event} do
|
||||
test "renders track when data is valid", %{
|
||||
conn: conn,
|
||||
track: %Track{id: id} = track,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@update_attrs, :event_id, event.id)
|
||||
conn = put conn, track_path(conn, :update, track), track: attrs
|
||||
conn = put(conn, track_path(conn, :update, track), track: attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, track_path(conn, :show, id)
|
||||
conn = get(conn, track_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"color" => "some updated color",
|
||||
"description" => "some updated description",
|
||||
"name" => "some updated name"}
|
||||
"id" => id,
|
||||
"color" => "some updated color",
|
||||
"description" => "some updated description",
|
||||
"name" => "some updated name"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, track: track, user: user, event: event} do
|
||||
test "renders errors when data is invalid", %{
|
||||
conn: conn,
|
||||
track: track,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = put conn, track_path(conn, :update, track), track: attrs
|
||||
conn = put(conn, track_path(conn, :update, track), track: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -82,11 +100,12 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
|
||||
test "deletes chosen track", %{conn: conn, track: track, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, track_path(conn, :delete, track)
|
||||
conn = delete(conn, track_path(conn, :delete, track))
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, track_path(conn, :show, track)
|
||||
end
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, track_path(conn, :show, track))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -24,58 +24,63 @@ defmodule EventosWeb.UserControllerTest do
|
||||
describe "index" do
|
||||
test "lists all users", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get conn, user_path(conn, :index)
|
||||
conn = get(conn, user_path(conn, :index))
|
||||
assert hd(json_response(conn, 200)["data"])["id"] == user.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "create user" do
|
||||
test "renders user when data is valid", %{conn: conn} do
|
||||
conn = post conn, user_path(conn, :create), @create_attrs
|
||||
conn = post(conn, user_path(conn, :create), @create_attrs)
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post conn, user_path(conn, :create), @invalid_attrs
|
||||
conn = post(conn, user_path(conn, :create), @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
|
||||
test "renders user with avatar when email is valid", %{conn: conn} do
|
||||
attrs = %{email: "contact@framasoft.org", password: "some password_hash", username: "framasoft"}
|
||||
conn = post conn, user_path(conn, :create), attrs
|
||||
attrs = %{
|
||||
email: "contact@framasoft.org",
|
||||
password: "some password_hash",
|
||||
username: "framasoft"
|
||||
}
|
||||
|
||||
conn = post(conn, user_path(conn, :create), attrs)
|
||||
assert %{"email" => "contact@framasoft.org"} = json_response(conn, 201)
|
||||
end
|
||||
end
|
||||
|
||||
# describe "update user" do
|
||||
# setup [:create_user]
|
||||
#
|
||||
# test "renders user when data is valid", %{conn: conn, user: %User{id: id} = user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @update_attrs
|
||||
# assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
#
|
||||
# conn = get conn, user_path(conn, :show, id)
|
||||
# assert json_response(conn, 200)["data"] == %{
|
||||
# "id" => id,
|
||||
# "email" => "some updated email",
|
||||
# "password_hash" => "some updated password_hash",
|
||||
# "role" => 43}
|
||||
# end
|
||||
#
|
||||
# test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @invalid_attrs
|
||||
# assert json_response(conn, 422)["errors"] != %{}
|
||||
# end
|
||||
# end
|
||||
# describe "update user" do
|
||||
# setup [:create_user]
|
||||
#
|
||||
# test "renders user when data is valid", %{conn: conn, user: %User{id: id} = user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @update_attrs
|
||||
# assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
#
|
||||
# conn = get conn, user_path(conn, :show, id)
|
||||
# assert json_response(conn, 200)["data"] == %{
|
||||
# "id" => id,
|
||||
# "email" => "some updated email",
|
||||
# "password_hash" => "some updated password_hash",
|
||||
# "role" => 43}
|
||||
# end
|
||||
#
|
||||
# test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @invalid_attrs
|
||||
# assert json_response(conn, 422)["errors"] != %{}
|
||||
# end
|
||||
# end
|
||||
|
||||
describe "delete user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "deletes chosen user", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, user_path(conn, :delete, user)
|
||||
conn = delete(conn, user_path(conn, :delete, user))
|
||||
assert response(conn, 204)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,17 +5,14 @@ defmodule EventosWeb.ErrorViewTest do
|
||||
import Phoenix.View
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(EventosWeb.ErrorView, "404.html", []) ==
|
||||
"Page not found"
|
||||
assert render_to_string(EventosWeb.ErrorView, "404.html", []) == "Page not found"
|
||||
end
|
||||
|
||||
test "render 500.html" do
|
||||
assert render_to_string(EventosWeb.ErrorView, "500.html", []) ==
|
||||
"Internal server error"
|
||||
assert render_to_string(EventosWeb.ErrorView, "500.html", []) == "Internal server error"
|
||||
end
|
||||
|
||||
test "render any other" do
|
||||
assert render_to_string(EventosWeb.ErrorView, "505.html", []) ==
|
||||
"Internal server error"
|
||||
assert render_to_string(EventosWeb.ErrorView, "505.html", []) == "Internal server error"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,13 +25,13 @@ defmodule EventosWeb.ChannelCase do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Eventos.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -26,6 +26,7 @@ defmodule EventosWeb.ConnCase do
|
||||
|
||||
def auth_conn(%Plug.Conn{} = conn, %Eventos.Actors.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
|
||||
conn
|
||||
|> Plug.Conn.put_req_header("authorization", "Bearer #{token}")
|
||||
|> Plug.Conn.put_req_header("accept", "application/json")
|
||||
@@ -33,13 +34,13 @@ defmodule EventosWeb.ConnCase do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Eventos.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ defmodule Eventos.Factory do
|
||||
%Eventos.Actors.User{
|
||||
password_hash: "Jane Smith",
|
||||
email: sequence(:email, &"email-#{&1}@example.com"),
|
||||
role: 0,
|
||||
role: 0
|
||||
}
|
||||
end
|
||||
|
||||
@@ -18,14 +18,14 @@ defmodule Eventos.Factory do
|
||||
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
||||
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
||||
|
||||
|
||||
preferred_username = sequence("thomas")
|
||||
|
||||
%Eventos.Actors.Actor{
|
||||
preferred_username: preferred_username,
|
||||
domain: nil,
|
||||
keys: pem,
|
||||
url: EventosWeb.Endpoint.url() <> "/@#{preferred_username}",
|
||||
user: nil,
|
||||
user: nil
|
||||
}
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ defmodule Eventos.Factory do
|
||||
text: "My Comment",
|
||||
actor: build(:actor),
|
||||
event: build(:event),
|
||||
uuid: Ecto.UUID.generate(),
|
||||
uuid: Ecto.UUID.generate()
|
||||
}
|
||||
end
|
||||
|
||||
@@ -75,9 +75,9 @@ defmodule Eventos.Factory do
|
||||
|
||||
def session_factory do
|
||||
%Eventos.Events.Session{
|
||||
title: sequence("MySession"),
|
||||
event: build(:event),
|
||||
track: build(:track)
|
||||
title: sequence("MySession"),
|
||||
event: build(:event),
|
||||
track: build(:track)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -93,7 +93,14 @@ defmodule Eventos.Factory do
|
||||
source: "https://mysource.tld/feed.ics",
|
||||
type: "ics",
|
||||
user: build(:user),
|
||||
actor: build(:actor),
|
||||
actor: build(:actor)
|
||||
}
|
||||
end
|
||||
|
||||
def member_factory do
|
||||
%Eventos.Actors.Member{
|
||||
parent: build(:actor),
|
||||
actor: build(:actor)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{:ok, _} = Application.ensure_all_started(:ex_machina)
|
||||
ExUnit.configure formatters: [ExUnit.CLIFormatter, ExUnitNotifier]
|
||||
ExUnit.configure(formatters: [ExUnit.CLIFormatter, ExUnitNotifier])
|
||||
|
||||
ExUnit.start()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user