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:
Thomas Citharel
2018-06-14 17:25:55 +02:00
parent 32596c3624
commit ca36dd12e2
43 changed files with 498 additions and 656 deletions

View File

@@ -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