67
test/eventos/actors/actors_test.exs
Normal file
67
test/eventos/actors/actors_test.exs
Normal file
@@ -0,0 +1,67 @@
|
||||
defmodule Eventos.ActorsTest do
|
||||
use Eventos.DataCase
|
||||
|
||||
alias Eventos.Actors
|
||||
|
||||
describe "bots" do
|
||||
alias Eventos.Actors.Bot
|
||||
|
||||
@valid_attrs %{source: "some source", type: "some type"}
|
||||
@update_attrs %{source: "some updated source", type: "some updated type"}
|
||||
@invalid_attrs %{source: nil, type: nil}
|
||||
|
||||
def bot_fixture(attrs \\ %{}) do
|
||||
{:ok, bot} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Actors.create_bot()
|
||||
|
||||
bot
|
||||
end
|
||||
|
||||
test "list_bots/0 returns all bots" do
|
||||
bot = bot_fixture()
|
||||
assert Actors.list_bots() == [bot]
|
||||
end
|
||||
|
||||
test "get_bot!/1 returns the bot with given id" do
|
||||
bot = bot_fixture()
|
||||
assert Actors.get_bot!(bot.id) == bot
|
||||
end
|
||||
|
||||
test "create_bot/1 with valid data creates a bot" do
|
||||
assert {:ok, %Bot{} = bot} = Actors.create_bot(@valid_attrs)
|
||||
assert bot.source == "some source"
|
||||
assert bot.type == "some type"
|
||||
end
|
||||
|
||||
test "create_bot/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Actors.create_bot(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_bot/2 with valid data updates the bot" do
|
||||
bot = bot_fixture()
|
||||
assert {:ok, bot} = Actors.update_bot(bot, @update_attrs)
|
||||
assert %Bot{} = bot
|
||||
assert bot.source == "some updated source"
|
||||
assert bot.type == "some updated type"
|
||||
end
|
||||
|
||||
test "update_bot/2 with invalid data returns error changeset" do
|
||||
bot = bot_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Actors.update_bot(bot, @invalid_attrs)
|
||||
assert bot == Actors.get_bot!(bot.id)
|
||||
end
|
||||
|
||||
test "delete_bot/1 deletes the bot" do
|
||||
bot = bot_fixture()
|
||||
assert {:ok, %Bot{}} = Actors.delete_bot(bot)
|
||||
assert_raise Ecto.NoResultsError, fn -> Actors.get_bot!(bot.id) end
|
||||
end
|
||||
|
||||
test "change_bot/1 returns a bot changeset" do
|
||||
bot = bot_fixture()
|
||||
assert %Ecto.Changeset{} = Actors.change_bot(bot)
|
||||
end
|
||||
end
|
||||
end
|
||||
81
test/eventos_web/controllers/bot_controller_test.exs
Normal file
81
test/eventos_web/controllers/bot_controller_test.exs
Normal file
@@ -0,0 +1,81 @@
|
||||
defmodule EventosWeb.BotControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
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
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all bots", %{conn: conn} do
|
||||
conn = get conn, bot_path(conn, :index)
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create bot" do
|
||||
test "renders bot when data is valid", %{conn: conn} do
|
||||
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)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some source",
|
||||
"type" => "some type"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post conn, bot_path(conn, :create), bot: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "renders bot when data is valid", %{conn: conn, bot: %Bot{id: id} = bot} do
|
||||
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)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some updated source",
|
||||
"type" => "some updated type"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, bot: bot} do
|
||||
conn = put conn, bot_path(conn, :update, bot), bot: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "deletes chosen bot", %{conn: conn, bot: bot} do
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
defp create_bot(_) do
|
||||
bot = fixture(:bot)
|
||||
{:ok, bot: bot}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user