debianize-mobilizon/test/eventos_web/controllers/group_controller_test.exs

89 lines
2.8 KiB
Elixir
Raw Normal View History

defmodule EventosWeb.GroupControllerTest do
use EventosWeb.ConnCase
alias Eventos.Accounts
@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} = Accounts.create_group(@create_attrs)
group
end
describe "index" do
test "lists all groups", %{conn: conn} do
conn = get conn, group_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Groups"
end
end
describe "new group" do
test "renders form", %{conn: conn} do
conn = get conn, group_path(conn, :new)
assert html_response(conn, 200) =~ "New Group"
end
end
describe "create group" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, group_path(conn, :create), group: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == group_path(conn, :show, id)
conn = get conn, group_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Group"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, group_path(conn, :create), group: @invalid_attrs
assert html_response(conn, 200) =~ "New Group"
end
end
describe "edit group" do
setup [:create_group]
test "renders form for editing chosen group", %{conn: conn, group: group} do
conn = get conn, group_path(conn, :edit, group)
assert html_response(conn, 200) =~ "Edit Group"
end
end
describe "update group" do
setup [:create_group]
test "redirects when data is valid", %{conn: conn, group: group} do
conn = put conn, group_path(conn, :update, group), group: @update_attrs
assert redirected_to(conn) == group_path(conn, :show, group)
conn = get conn, group_path(conn, :show, group)
assert html_response(conn, 200) =~ "some updated description"
end
test "renders errors when data is invalid", %{conn: conn, group: group} do
conn = put conn, group_path(conn, :update, group), group: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Group"
end
end
describe "delete group" do
setup [:create_group]
test "deletes chosen group", %{conn: conn, group: group} do
conn = delete conn, group_path(conn, :delete, group)
assert redirected_to(conn) == group_path(conn, :index)
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
end