Make tests great again !
(Also use only one field for public/private key pem) Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
defmodule EventosWeb.AccountControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Accounts
|
||||
|
||||
@create_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", private_key: "some private_key", public_key: "some public_key", suspended: true, uri: "some uri", url: "some url", username: "some username"}
|
||||
|
||||
def fixture(:account) do
|
||||
{:ok, account} = Accounts.create_account(@create_attrs)
|
||||
account
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all accounts", %{conn: conn, user: user} do
|
||||
conn = get conn, account_path(conn, :index)
|
||||
assert hd(json_response(conn, 200)["data"])["username"] == user.account.username
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete account" do
|
||||
setup [:create_account]
|
||||
|
||||
test "deletes own account", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, account_path(conn, :delete, user.account)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, account_path(conn, :show, user.account)
|
||||
end
|
||||
end
|
||||
|
||||
test "deletes other account", %{conn: conn, account: account, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, account_path(conn, :delete, account)
|
||||
assert response(conn, 401)
|
||||
conn = get conn, account_path(conn, :show, account)
|
||||
assert response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_account(_) do
|
||||
account = fixture(:account)
|
||||
{:ok, account: account}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
@@ -1,44 +1,42 @@
|
||||
defmodule EventosWeb.ActivityPubControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
import Eventos.Factory
|
||||
alias EventosWeb.ActivityPub.{AccountView, ObjectView}
|
||||
alias Eventos.{Repo, Accounts, Accounts.Account}
|
||||
alias EventosWeb.ActivityPub.{ActorView, ObjectView}
|
||||
alias Eventos.{Repo, Actors, Actors.Actor}
|
||||
alias Eventos.Activity
|
||||
import Logger
|
||||
|
||||
describe "/@:username" do
|
||||
test "it returns a json representation of the account", %{conn: conn} do
|
||||
account = insert(:account)
|
||||
test "it returns a json representation of the actor", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/@#{account.username}")
|
||||
|> get("/@#{actor.preferred_username}")
|
||||
|
||||
account = Accounts.get_account!(account.id)
|
||||
actor = Actors.get_actor!(actor.id)
|
||||
|
||||
assert json_response(conn, 200) == AccountView.render("account.json", %{account: account})
|
||||
Logger.error(inspect AccountView.render("account.json", %{account: account}))
|
||||
assert json_response(conn, 200) == ActorView.render("actor.json", %{actor: actor})
|
||||
Logger.error(inspect ActorView.render("actor.json", %{actor: actor}))
|
||||
end
|
||||
end
|
||||
|
||||
describe "/@username/slug" do
|
||||
describe "/events/uuid" do
|
||||
test "it returns a json representation of the object", %{conn: conn} do
|
||||
event = insert(:event)
|
||||
{slug, parts} = List.pop_at(String.split(event.url, "/"), -1)
|
||||
"@" <> username = List.last(parts)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/@#{username}/#{slug}")
|
||||
|> get("/events/#{event.uuid}")
|
||||
|
||||
assert json_response(conn, 200) == ObjectView.render("event.json", %{event: event})
|
||||
Logger.error(inspect ObjectView.render("event.json", %{event: event}))
|
||||
end
|
||||
end
|
||||
|
||||
# describe "/accounts/:username/inbox" do
|
||||
# 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!()
|
||||
#
|
||||
@@ -54,7 +52,7 @@ defmodule EventosWeb.ActivityPubControllerTest do
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "/accounts/:nickname/followers" do
|
||||
# describe "/actors/:nickname/followers" do
|
||||
# test "it returns the followers in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
|
||||
49
test/eventos_web/controllers/actor_controller_test.exs
Normal file
49
test/eventos_web/controllers/actor_controller_test.exs
Normal file
@@ -0,0 +1,49 @@
|
||||
defmodule EventosWeb.ActorControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Actors
|
||||
|
||||
setup %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all actors", %{conn: conn, user: user} do
|
||||
conn = get conn, actor_path(conn, :index)
|
||||
assert hd(json_response(conn, 200)["data"])["username"] == user.actor.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
|
||||
|
||||
defp create_actor(_) do
|
||||
actor = insert(:actor)
|
||||
{:ok, actor: actor}
|
||||
end
|
||||
end
|
||||
@@ -16,8 +16,8 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
@@ -101,11 +101,4 @@ defmodule EventosWeb.AddressControllerTest do
|
||||
defp create_address(_) do
|
||||
{:ok, address: insert(:address)}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
defmodule EventosWeb.BotControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Actors
|
||||
alias Eventos.Actors.Bot
|
||||
|
||||
@create_attrs %{source: "some source", type: "some type"}
|
||||
@update_attrs %{source: "some updated source", type: "some updated type"}
|
||||
@invalid_attrs %{source: nil, type: nil}
|
||||
|
||||
def fixture(:bot) do
|
||||
{:ok, bot} = Actors.create_bot(@create_attrs)
|
||||
bot
|
||||
end
|
||||
@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"}
|
||||
@invalid_attrs %{source: nil, type: nil, name: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json"), user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
@@ -25,7 +24,8 @@ defmodule EventosWeb.BotControllerTest do
|
||||
end
|
||||
|
||||
describe "create bot" do
|
||||
test "renders bot when data is valid", %{conn: conn} 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
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
@@ -36,7 +36,8 @@ defmodule EventosWeb.BotControllerTest do
|
||||
"type" => "some type"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
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
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
@@ -45,7 +46,8 @@ defmodule EventosWeb.BotControllerTest do
|
||||
describe "update bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "renders bot when data is valid", %{conn: conn, bot: %Bot{id: id} = bot} 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
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
@@ -56,7 +58,8 @@ defmodule EventosWeb.BotControllerTest do
|
||||
"type" => "some updated type"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, bot: bot} do
|
||||
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
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
@@ -65,7 +68,8 @@ defmodule EventosWeb.BotControllerTest do
|
||||
describe "delete bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "deletes chosen bot", %{conn: conn, bot: bot} 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)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
@@ -75,7 +79,7 @@ defmodule EventosWeb.BotControllerTest do
|
||||
end
|
||||
|
||||
defp create_bot(_) do
|
||||
bot = fixture(:bot)
|
||||
bot = insert(:bot)
|
||||
{:ok, bot: bot}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,8 +16,8 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
@@ -89,11 +89,4 @@ defmodule EventosWeb.CategoryControllerTest do
|
||||
category = fixture(:category)
|
||||
{:ok, category: category}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,39 +4,37 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
alias Eventos.Events
|
||||
alias Eventos.Events.Comment
|
||||
|
||||
@create_attrs %{text: "some text", url: "some url"}
|
||||
@update_attrs %{text: "some updated text", url: "some updated url"}
|
||||
import Eventos.Factory
|
||||
|
||||
@create_attrs %{text: "some text"}
|
||||
@update_attrs %{text: "some updated text"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
||||
def fixture(:comment) do
|
||||
{:ok, comment} = Events.create_comment(@create_attrs)
|
||||
comment
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all comments", %{conn: conn} do
|
||||
conn = get conn, comment_path(conn, :index)
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json"), user: user}
|
||||
end
|
||||
|
||||
describe "create comment" do
|
||||
test "renders comment when data is valid", %{conn: conn} do
|
||||
conn = post conn, comment_path(conn, :create), comment: @create_attrs
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
test "renders comment when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
actor = insert(:actor)
|
||||
attrs = Map.merge(@create_attrs, %{actor_id: actor.id})
|
||||
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, id)
|
||||
conn = get conn, comment_path(conn, :show, uuid)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some text",
|
||||
"url" => "some url"}
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
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
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
@@ -45,19 +43,25 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
describe "update comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "renders comment when data is valid", %{conn: conn, comment: %Comment{id: id} = comment} do
|
||||
conn = put conn, comment_path(conn, :update, comment), comment: @update_attrs
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
test "renders comment when data is valid", %{conn: conn, comment: %Comment{id: id, uuid: uuid} = comment, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
actor = insert(:actor)
|
||||
attrs = Map.merge(@update_attrs, %{actor_id: actor.id})
|
||||
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, id)
|
||||
conn = get conn, comment_path(conn, :show, uuid)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some updated text",
|
||||
"url" => "some updated url"}
|
||||
"uuid" => uuid,
|
||||
"url" => "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, comment: comment} do
|
||||
conn = put conn, comment_path(conn, :update, comment), comment: @invalid_attrs
|
||||
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
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -65,17 +69,18 @@ defmodule EventosWeb.CommentControllerTest do
|
||||
describe "delete comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "deletes chosen comment", %{conn: conn, comment: comment} do
|
||||
conn = delete conn, comment_path(conn, :delete, comment)
|
||||
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)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, comment_path(conn, :show, comment)
|
||||
get conn, comment_path(conn, :show, uuid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_comment(_) do
|
||||
comment = fixture(:comment)
|
||||
comment = insert(:comment)
|
||||
{:ok, comment: comment}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,8 +21,8 @@ defmodule EventosWeb.EventControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
@@ -35,30 +35,21 @@ defmodule EventosWeb.EventControllerTest do
|
||||
|
||||
describe "create event" do
|
||||
test "renders event when data is valid", %{conn: conn, user: user} do
|
||||
attrs = Map.put(@create_attrs, :organizer_account_id, user.account.id)
|
||||
attrs = Map.put(@create_attrs, :organizer_actor_id, user.actor.id)
|
||||
attrs = Map.put(attrs, :address, @create_address_attrs)
|
||||
|
||||
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
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
assert %{"uuid" => uuid} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, event_path(conn, :show, id)
|
||||
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",
|
||||
"group" => nil,
|
||||
"organizer" => %{
|
||||
"description" => nil,
|
||||
"display_name" => nil,
|
||||
"domain" => nil,
|
||||
"suspended" => false,
|
||||
"uri" => "https://",
|
||||
"url" => "https://",
|
||||
},
|
||||
"participants" => [],
|
||||
"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"]
|
||||
@@ -66,7 +57,7 @@ defmodule EventosWeb.EventControllerTest do
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_account_id, user.account.id)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, user.actor.id)
|
||||
attrs = Map.put(attrs, :address, @create_address_attrs)
|
||||
conn = post conn, event_path(conn, :create), event: attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
@@ -76,9 +67,9 @@ defmodule EventosWeb.EventControllerTest do
|
||||
describe "export event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders ics export of event", %{conn: conn, event: %Event{id: id} = 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, id)
|
||||
conn = get conn, event_path(conn, :export_to_ics, uuid)
|
||||
exported_event = ICalendar.export_event(event)
|
||||
assert exported_event == response(conn, 200)
|
||||
end
|
||||
@@ -87,38 +78,29 @@ defmodule EventosWeb.EventControllerTest do
|
||||
describe "update event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders event when data is valid", %{conn: conn, event: %Event{id: id} = event, user: user} do
|
||||
test "renders event when data is valid", %{conn: conn, event: %Event{uuid: uuid} = event, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
address = address_fixture()
|
||||
attrs = Map.put(@update_attrs, :organizer_account_id, user.account.id)
|
||||
attrs = Map.put(@update_attrs, :organizer_actor_id, user.actor.id)
|
||||
attrs = Map.put(attrs, :address_id, address.id)
|
||||
conn = put conn, event_path(conn, :update, event), event: attrs
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
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, id)
|
||||
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",
|
||||
"group" => nil,
|
||||
"organizer" => %{
|
||||
"description" => nil,
|
||||
"display_name" => nil,
|
||||
"domain" => nil,
|
||||
"suspended" => false,
|
||||
"uri" => "https://",
|
||||
"url" => "https://",
|
||||
},
|
||||
"participants" => [],
|
||||
"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, user: user} do
|
||||
test "renders errors when data is invalid", %{conn: conn, event: %Event{uuid: uuid} = event, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_account_id, user.account.id)
|
||||
conn = put conn, event_path(conn, :update, event), event: attrs
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, user.actor.id)
|
||||
conn = put conn, event_path(conn, :update, uuid), event: attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
@@ -126,26 +108,18 @@ defmodule EventosWeb.EventControllerTest do
|
||||
describe "delete event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "deletes chosen event", %{conn: conn, event: event, user: user} 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, event)
|
||||
conn = delete conn, event_path(conn, :delete, uuid)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, event_path(conn, :show, event)
|
||||
end
|
||||
conn = get conn, event_path(conn, :show, uuid)
|
||||
assert response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_event(_) do
|
||||
account = insert(:account)
|
||||
event = insert(:event, organizer_account: account)
|
||||
{:ok, event: event, account: account}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, event: event, actor: actor}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
defmodule EventosWeb.GroupControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Groups
|
||||
alias Eventos.Groups.Group
|
||||
|
||||
@create_attrs %{description: "some description", suspended: true, title: "some title", uri: "some uri", url: "some url"}
|
||||
@update_attrs %{description: "some updated description", suspended: false, title: "some updated title", uri: "some updated uri", url: "some updated url"}
|
||||
@invalid_attrs %{description: nil, suspended: nil, title: nil, uri: nil, url: nil}
|
||||
|
||||
def fixture(:group) do
|
||||
{:ok, group} = Groups.create_group(@create_attrs)
|
||||
group
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all groups", %{conn: conn} do
|
||||
conn = get conn, group_path(conn, :index)
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create group" do
|
||||
test "renders group when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, group_path(conn, :create), group: @create_attrs
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, group_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some description",
|
||||
"suspended" => true,
|
||||
"title" => "some title",
|
||||
"uri" => "h",
|
||||
"url" => "h",
|
||||
"events" => [],
|
||||
"members" => []
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post conn, group_path(conn, :create), group: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update group" do
|
||||
setup [:create_group]
|
||||
|
||||
test "renders group when data is valid", %{conn: conn, group: %Group{id: id} = group, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, group_path(conn, :update, group), group: @update_attrs
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, group_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some updated description",
|
||||
"suspended" => false,
|
||||
"title" => "some updated title",
|
||||
"uri" => "some updated uri",
|
||||
"url" => "some updated url",
|
||||
"events" => [],
|
||||
"members" => []
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, group: group, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put conn, group_path(conn, :update, group), group: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete group" do
|
||||
setup [:create_group]
|
||||
|
||||
test "deletes chosen group", %{conn: conn, group: group, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete conn, group_path(conn, :delete, group)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, group_path(conn, :show, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_group(_) do
|
||||
group = fixture(:group)
|
||||
{:ok, group: group}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
@@ -16,9 +16,9 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
event = insert(:event, organizer_account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, conn: conn, user: user, event: event}
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
conn = post conn, session_path(conn, :create), session: attrs
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, "/api/events/" <> Integer.to_string(event_id) <> "/sessions"
|
||||
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)
|
||||
@@ -107,11 +107,4 @@ defmodule EventosWeb.SessionControllerTest do
|
||||
session = insert(:session)
|
||||
{:ok, session: session}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,8 +16,8 @@ defmodule EventosWeb.TagControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
@@ -85,11 +85,4 @@ defmodule EventosWeb.TagControllerTest do
|
||||
tag = fixture(:tag)
|
||||
{:ok, tag: tag}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,9 +16,9 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
event = insert(:event, organizer_account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, conn: conn, user: user, event: event}
|
||||
end
|
||||
|
||||
@@ -94,11 +94,4 @@ defmodule EventosWeb.TrackControllerTest do
|
||||
track = insert(:track)
|
||||
{:ok, track: track}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %Eventos.Accounts.User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,21 +3,21 @@ defmodule EventosWeb.UserControllerTest do
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.User
|
||||
alias Eventos.Actors
|
||||
alias Eventos.Actors.User
|
||||
|
||||
@create_attrs %{email: "foo@bar.tld", password: "some password_hash", username: "some username"}
|
||||
# @update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"}
|
||||
@invalid_attrs %{email: "not an email", password: nil, username: nil}
|
||||
|
||||
def fixture(:user) do
|
||||
{:ok, user} = Accounts.create_user(@create_attrs)
|
||||
{:ok, user} = Actors.create_user(@create_attrs)
|
||||
user
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
account = insert(:account)
|
||||
user = insert(:user, account: account)
|
||||
actor = insert(:actor)
|
||||
user = insert(:user, actor: actor)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
@@ -32,20 +32,20 @@ defmodule EventosWeb.UserControllerTest do
|
||||
describe "create user" do
|
||||
test "renders user when data is valid", %{conn: conn} do
|
||||
conn = post conn, user_path(conn, :create), @create_attrs
|
||||
assert %{"user" => %{"id" => id, "account" => %{"avatar_url" => avatar_url}}} = json_response(conn, 201)
|
||||
assert %{"user" => %{"id" => id, "actor" => %{"avatar" => avatar_url}}} = json_response(conn, 201)
|
||||
assert id > 0
|
||||
assert avatar_url == nil
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post conn, user_path(conn, :create), @invalid_attrs
|
||||
assert json_response(conn, 400)["msg"] != %{}
|
||||
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
|
||||
assert %{"user" => %{"id" => id, "account" => %{"avatar_url" => avatar_url}}} = json_response(conn, 201)
|
||||
assert %{"user" => %{"id" => id, "actor" => %{"avatar" => avatar_url}}} = json_response(conn, 201)
|
||||
assert id > 0
|
||||
assert avatar_url == "https://secure.gravatar.com/avatar/68b2910a6bb84a482d920e1057533100?default=404"
|
||||
end
|
||||
@@ -88,11 +88,4 @@ defmodule EventosWeb.UserControllerTest do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
defp auth_conn(conn, %User{} = user) do
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{token}")
|
||||
|> put_req_header("accept", "application/json")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user