initial commit

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2017-12-08 09:58:14 +01:00
commit 90ceb4f6fe
181 changed files with 8219 additions and 0 deletions

View File

@@ -0,0 +1,335 @@
defmodule Eventos.AccountsTest do
use Eventos.DataCase
alias Eventos.Accounts
describe "users" do
alias Eventos.Accounts.User
@valid_attrs %{email: "some email", password_hash: "some password_hash", role: 42, username: "some username"}
@update_attrs %{email: "some updated email", password_hash: "some updated password_hash", role: 43, username: "some updated username"}
@invalid_attrs %{email: nil, password_hash: nil, role: nil, username: nil}
def user_fixture(attrs \\ %{}) do
{:ok, user} =
attrs
|> Enum.into(@valid_attrs)
|> Accounts.create_user()
user
end
test "list_users/0 returns all users" do
user = user_fixture()
assert Accounts.list_users() == [user]
end
test "get_user!/1 returns the user with given id" do
user = user_fixture()
assert Accounts.get_user!(user.id) == user
end
test "create_user/1 with valid data creates a user" do
assert {:ok, %User{} = user} = Accounts.create_user(@valid_attrs)
assert user.email == "some email"
assert user.password_hash == "some password_hash"
assert user.role == 42
assert user.username == "some username"
end
test "create_user/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_user(@invalid_attrs)
end
test "update_user/2 with valid data updates the user" do
user = user_fixture()
assert {:ok, user} = Accounts.update_user(user, @update_attrs)
assert %User{} = user
assert user.email == "some updated email"
assert user.password_hash == "some updated password_hash"
assert user.role == 43
assert user.username == "some updated username"
end
test "update_user/2 with invalid data returns error changeset" do
user = user_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_user(user, @invalid_attrs)
assert user == Accounts.get_user!(user.id)
end
test "delete_user/1 deletes the user" do
user = user_fixture()
assert {:ok, %User{}} = Accounts.delete_user(user)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_user!(user.id) end
end
test "change_user/1 returns a user changeset" do
user = user_fixture()
assert %Ecto.Changeset{} = Accounts.change_user(user)
end
end
describe "accounts" do
alias Eventos.Accounts.Account
@valid_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"}
@update_attrs %{description: "some updated description", display_name: "some updated display_name", domain: "some updated domain", private_key: "some updated private_key", public_key: "some updated public_key", suspended: false, uri: "some updated uri", url: "some updated url", username: "some updated username"}
@invalid_attrs %{description: nil, display_name: nil, domain: nil, private_key: nil, public_key: nil, suspended: nil, uri: nil, url: nil, username: nil}
def account_fixture(attrs \\ %{}) do
{:ok, account} =
attrs
|> Enum.into(@valid_attrs)
|> Accounts.create_account()
account
end
test "list_accounts/0 returns all accounts" do
account = account_fixture()
assert Accounts.list_accounts() == [account]
end
test "get_account!/1 returns the account with given id" do
account = account_fixture()
assert Accounts.get_account!(account.id) == account
end
test "create_account/1 with valid data creates a account" do
assert {:ok, %Account{} = account} = Accounts.create_account(@valid_attrs)
assert account.description == "some description"
assert account.display_name == "some display_name"
assert account.domain == "some domain"
assert account.private_key == "some private_key"
assert account.public_key == "some public_key"
assert account.suspended == true
assert account.uri == "some uri"
assert account.url == "some url"
assert account.username == "some username"
end
test "create_account/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_account(@invalid_attrs)
end
test "update_account/2 with valid data updates the account" do
account = account_fixture()
assert {:ok, account} = Accounts.update_account(account, @update_attrs)
assert %Account{} = account
assert account.description == "some updated description"
assert account.display_name == "some updated display_name"
assert account.domain == "some updated domain"
assert account.private_key == "some updated private_key"
assert account.public_key == "some updated public_key"
assert account.suspended == false
assert account.uri == "some updated uri"
assert account.url == "some updated url"
assert account.username == "some updated username"
end
test "update_account/2 with invalid data returns error changeset" do
account = account_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_account(account, @invalid_attrs)
assert account == Accounts.get_account!(account.id)
end
test "delete_account/1 deletes the account" do
account = account_fixture()
assert {:ok, %Account{}} = Accounts.delete_account(account)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_account!(account.id) end
end
test "change_account/1 returns a account changeset" do
account = account_fixture()
assert %Ecto.Changeset{} = Accounts.change_account(account)
end
end
describe "groups" do
alias Eventos.Accounts.Group
@valid_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 group_fixture(attrs \\ %{}) do
{:ok, group} =
attrs
|> Enum.into(@valid_attrs)
|> Accounts.create_group()
group
end
test "list_groups/0 returns all groups" do
group = group_fixture()
assert Accounts.list_groups() == [group]
end
test "get_group!/1 returns the group with given id" do
group = group_fixture()
assert Accounts.get_group!(group.id) == group
end
test "create_group/1 with valid data creates a group" do
assert {:ok, %Group{} = group} = Accounts.create_group(@valid_attrs)
assert group.description == "some description"
assert group.suspended == true
assert group.title == "some title"
assert group.uri == "some uri"
assert group.url == "some url"
end
test "create_group/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_group(@invalid_attrs)
end
test "update_group/2 with valid data updates the group" do
group = group_fixture()
assert {:ok, group} = Accounts.update_group(group, @update_attrs)
assert %Group{} = group
assert group.description == "some updated description"
assert group.suspended == false
assert group.title == "some updated title"
assert group.uri == "some updated uri"
assert group.url == "some updated url"
end
test "update_group/2 with invalid data returns error changeset" do
group = group_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_group(group, @invalid_attrs)
assert group == Accounts.get_group!(group.id)
end
test "delete_group/1 deletes the group" do
group = group_fixture()
assert {:ok, %Group{}} = Accounts.delete_group(group)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_group!(group.id) end
end
test "change_group/1 returns a group changeset" do
group = group_fixture()
assert %Ecto.Changeset{} = Accounts.change_group(group)
end
end
describe "group_accounts" do
alias Eventos.Accounts.GroupAccount
@valid_attrs %{role: 42}
@update_attrs %{role: 43}
@invalid_attrs %{role: nil}
def group_account_fixture(attrs \\ %{}) do
{:ok, group_account} =
attrs
|> Enum.into(@valid_attrs)
|> Accounts.create_group_account()
group_account
end
test "list_group_accounts/0 returns all group_accounts" do
group_account = group_account_fixture()
assert Accounts.list_group_accounts() == [group_account]
end
test "get_group_account!/1 returns the group_account with given id" do
group_account = group_account_fixture()
assert Accounts.get_group_account!(group_account.id) == group_account
end
test "create_group_account/1 with valid data creates a group_account" do
assert {:ok, %GroupAccount{} = group_account} = Accounts.create_group_account(@valid_attrs)
assert group_account.role == 42
end
test "create_group_account/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_group_account(@invalid_attrs)
end
test "update_group_account/2 with valid data updates the group_account" do
group_account = group_account_fixture()
assert {:ok, group_account} = Accounts.update_group_account(group_account, @update_attrs)
assert %GroupAccount{} = group_account
assert group_account.role == 43
end
test "update_group_account/2 with invalid data returns error changeset" do
group_account = group_account_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_group_account(group_account, @invalid_attrs)
assert group_account == Accounts.get_group_account!(group_account.id)
end
test "delete_group_account/1 deletes the group_account" do
group_account = group_account_fixture()
assert {:ok, %GroupAccount{}} = Accounts.delete_group_account(group_account)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_group_account!(group_account.id) end
end
test "change_group_account/1 returns a group_account changeset" do
group_account = group_account_fixture()
assert %Ecto.Changeset{} = Accounts.change_group_account(group_account)
end
end
describe "group_request" do
alias Eventos.Accounts.GroupRequest
@valid_attrs %{state: 42}
@update_attrs %{state: 43}
@invalid_attrs %{state: nil}
def group_request_fixture(attrs \\ %{}) do
{:ok, group_request} =
attrs
|> Enum.into(@valid_attrs)
|> Accounts.create_group_request()
group_request
end
test "list_group_requests/0 returns all group_request" do
group_request = group_request_fixture()
assert Accounts.list_group_requests() == [group_request]
end
test "get_group_request!/1 returns the group_request with given id" do
group_request = group_request_fixture()
assert Accounts.get_group_request!(group_request.id) == group_request
end
test "create_group_request/1 with valid data creates a group_request" do
assert {:ok, %GroupRequest{} = group_request} = Accounts.create_group_request(@valid_attrs)
assert group_request.state == 42
end
test "create_group_request/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_group_request(@invalid_attrs)
end
test "update_group_request/2 with valid data updates the group_request" do
group_request = group_request_fixture()
assert {:ok, group_request} = Accounts.update_group_request(group_request, @update_attrs)
assert %GroupRequest{} = group_request
assert group_request.state == 43
end
test "update_group_request/2 with invalid data returns error changeset" do
group_request = group_request_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_group_request(group_request, @invalid_attrs)
assert group_request == Accounts.get_group_request!(group_request.id)
end
test "delete_group_request/1 deletes the group_request" do
group_request = group_request_fixture()
assert {:ok, %GroupRequest{}} = Accounts.delete_group_request(group_request)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_group_request!(group_request.id) end
end
test "change_group_request/1 returns a group_request changeset" do
group_request = group_request_fixture()
assert %Ecto.Changeset{} = Accounts.change_group_request(group_request)
end
end
end

View File

@@ -0,0 +1,315 @@
defmodule Eventos.EventsTest do
use Eventos.DataCase
alias Eventos.Events
describe "events" do
alias Eventos.Events.Event
@valid_attrs %{begin_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 %{begin_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 %{begin_on: nil, description: nil, ends_on: nil, title: nil}
def event_fixture(attrs \\ %{}) do
{:ok, event} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_event()
event
end
test "list_events/0 returns all events" do
event = event_fixture()
assert Events.list_events() == [event]
end
test "get_event!/1 returns the event with given id" do
event = event_fixture()
assert Events.get_event!(event.id) == event
end
test "create_event/1 with valid data creates a event" do
assert {:ok, %Event{} = event} = Events.create_event(@valid_attrs)
assert event.begin_on == DateTime.from_naive!(~N[2010-04-17 14:00:00.000000Z], "Etc/UTC")
assert event.description == "some description"
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00.000000Z], "Etc/UTC")
assert event.title == "some title"
end
test "create_event/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_event(@invalid_attrs)
end
test "update_event/2 with valid data updates the event" do
event = event_fixture()
assert {:ok, event} = Events.update_event(event, @update_attrs)
assert %Event{} = event
assert event.begin_on == DateTime.from_naive!(~N[2011-05-18 15:01:01.000000Z], "Etc/UTC")
assert event.description == "some updated description"
assert event.ends_on == DateTime.from_naive!(~N[2011-05-18 15:01:01.000000Z], "Etc/UTC")
assert event.title == "some updated title"
end
test "update_event/2 with invalid data returns error changeset" do
event = event_fixture()
assert {:error, %Ecto.Changeset{}} = Events.update_event(event, @invalid_attrs)
assert event == Events.get_event!(event.id)
end
test "delete_event/1 deletes the event" do
event = event_fixture()
assert {:ok, %Event{}} = Events.delete_event(event)
assert_raise Ecto.NoResultsError, fn -> Events.get_event!(event.id) end
end
test "change_event/1 returns a event changeset" do
event = event_fixture()
assert %Ecto.Changeset{} = Events.change_event(event)
end
end
describe "categories" do
alias Eventos.Events.Category
@valid_attrs %{picture: "some picture", title: "some title"}
@update_attrs %{picture: "some updated picture", title: "some updated title"}
@invalid_attrs %{picture: nil, title: nil}
def category_fixture(attrs \\ %{}) do
{:ok, category} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_category()
category
end
test "list_categories/0 returns all categories" do
category = category_fixture()
assert Events.list_categories() == [category]
end
test "get_category!/1 returns the category with given id" do
category = category_fixture()
assert Events.get_category!(category.id) == category
end
test "create_category/1 with valid data creates a category" do
assert {:ok, %Category{} = category} = Events.create_category(@valid_attrs)
assert category.picture == "some picture"
assert category.title == "some title"
end
test "create_category/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_category(@invalid_attrs)
end
test "update_category/2 with valid data updates the category" do
category = category_fixture()
assert {:ok, category} = Events.update_category(category, @update_attrs)
assert %Category{} = category
assert category.picture == "some updated picture"
assert category.title == "some updated title"
end
test "update_category/2 with invalid data returns error changeset" do
category = category_fixture()
assert {:error, %Ecto.Changeset{}} = Events.update_category(category, @invalid_attrs)
assert category == Events.get_category!(category.id)
end
test "delete_category/1 deletes the category" do
category = category_fixture()
assert {:ok, %Category{}} = Events.delete_category(category)
assert_raise Ecto.NoResultsError, fn -> Events.get_category!(category.id) end
end
test "change_category/1 returns a category changeset" do
category = category_fixture()
assert %Ecto.Changeset{} = Events.change_category(category)
end
end
describe "tags" do
alias Eventos.Events.Tag
@valid_attrs %{slug: "some slug", title: "some title"}
@update_attrs %{slug: "some updated slug", title: "some updated title"}
@invalid_attrs %{slug: nil, title: nil}
def tag_fixture(attrs \\ %{}) do
{:ok, tag} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_tag()
tag
end
test "list_tags/0 returns all tags" do
tag = tag_fixture()
assert Events.list_tags() == [tag]
end
test "get_tag!/1 returns the tag with given id" do
tag = tag_fixture()
assert Events.get_tag!(tag.id) == tag
end
test "create_tag/1 with valid data creates a tag" do
assert {:ok, %Tag{} = tag} = Events.create_tag(@valid_attrs)
assert tag.slug == "some slug"
assert tag.title == "some title"
end
test "create_tag/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_tag(@invalid_attrs)
end
test "update_tag/2 with valid data updates the tag" do
tag = tag_fixture()
assert {:ok, tag} = Events.update_tag(tag, @update_attrs)
assert %Tag{} = tag
assert tag.slug == "some updated slug"
assert tag.title == "some updated title"
end
test "update_tag/2 with invalid data returns error changeset" do
tag = tag_fixture()
assert {:error, %Ecto.Changeset{}} = Events.update_tag(tag, @invalid_attrs)
assert tag == Events.get_tag!(tag.id)
end
test "delete_tag/1 deletes the tag" do
tag = tag_fixture()
assert {:ok, %Tag{}} = Events.delete_tag(tag)
assert_raise Ecto.NoResultsError, fn -> Events.get_tag!(tag.id) end
end
test "change_tag/1 returns a tag changeset" do
tag = tag_fixture()
assert %Ecto.Changeset{} = Events.change_tag(tag)
end
end
describe "event_accounts" do
alias Eventos.Events.EventAccounts
@valid_attrs %{roles: 42}
@update_attrs %{roles: 43}
@invalid_attrs %{roles: nil}
def event_accounts_fixture(attrs \\ %{}) do
{:ok, event_accounts} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_event_accounts()
event_accounts
end
test "list_event_accounts/0 returns all event_accounts" do
event_accounts = event_accounts_fixture()
assert Events.list_event_accounts() == [event_accounts]
end
test "get_event_accounts!/1 returns the event_accounts with given id" do
event_accounts = event_accounts_fixture()
assert Events.get_event_accounts!(event_accounts.id) == event_accounts
end
test "create_event_accounts/1 with valid data creates a event_accounts" do
assert {:ok, %EventAccounts{} = event_accounts} = Events.create_event_accounts(@valid_attrs)
assert event_accounts.roles == 42
end
test "create_event_accounts/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_event_accounts(@invalid_attrs)
end
test "update_event_accounts/2 with valid data updates the event_accounts" do
event_accounts = event_accounts_fixture()
assert {:ok, event_accounts} = Events.update_event_accounts(event_accounts, @update_attrs)
assert %EventAccounts{} = event_accounts
assert event_accounts.roles == 43
end
test "update_event_accounts/2 with invalid data returns error changeset" do
event_accounts = event_accounts_fixture()
assert {:error, %Ecto.Changeset{}} = Events.update_event_accounts(event_accounts, @invalid_attrs)
assert event_accounts == Events.get_event_accounts!(event_accounts.id)
end
test "delete_event_accounts/1 deletes the event_accounts" do
event_accounts = event_accounts_fixture()
assert {:ok, %EventAccounts{}} = Events.delete_event_accounts(event_accounts)
assert_raise Ecto.NoResultsError, fn -> Events.get_event_accounts!(event_accounts.id) end
end
test "change_event_accounts/1 returns a event_accounts changeset" do
event_accounts = event_accounts_fixture()
assert %Ecto.Changeset{} = Events.change_event_accounts(event_accounts)
end
end
describe "event_requests" do
alias Eventos.Events.EventRequest
@valid_attrs %{state: 42}
@update_attrs %{state: 43}
@invalid_attrs %{state: nil}
def event_request_fixture(attrs \\ %{}) do
{:ok, event_request} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_event_request()
event_request
end
test "list_event_requests/0 returns all event_requests" do
event_request = event_request_fixture()
assert Events.list_event_requests() == [event_request]
end
test "get_event_request!/1 returns the event_request with given id" do
event_request = event_request_fixture()
assert Events.get_event_request!(event_request.id) == event_request
end
test "create_event_request/1 with valid data creates a event_request" do
assert {:ok, %EventRequest{} = event_request} = Events.create_event_request(@valid_attrs)
assert event_request.state == 42
end
test "create_event_request/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_event_request(@invalid_attrs)
end
test "update_event_request/2 with valid data updates the event_request" do
event_request = event_request_fixture()
assert {:ok, event_request} = Events.update_event_request(event_request, @update_attrs)
assert %EventRequest{} = event_request
assert event_request.state == 43
end
test "update_event_request/2 with invalid data returns error changeset" do
event_request = event_request_fixture()
assert {:error, %Ecto.Changeset{}} = Events.update_event_request(event_request, @invalid_attrs)
assert event_request == Events.get_event_request!(event_request.id)
end
test "delete_event_request/1 deletes the event_request" do
event_request = event_request_fixture()
assert {:ok, %EventRequest{}} = Events.delete_event_request(event_request)
assert_raise Ecto.NoResultsError, fn -> Events.get_event_request!(event_request.id) end
end
test "change_event_request/1 returns a event_request changeset" do
event_request = event_request_fixture()
assert %Ecto.Changeset{} = Events.change_event_request(event_request)
end
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.AccountControllerTest do
use EventosWeb.ConnCase
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"}
@update_attrs %{description: "some updated description", display_name: "some updated display_name", domain: "some updated domain", private_key: "some updated private_key", public_key: "some updated public_key", suspended: false, uri: "some updated uri", url: "some updated url", username: "some updated username"}
@invalid_attrs %{description: nil, display_name: nil, domain: nil, private_key: nil, public_key: nil, suspended: nil, uri: nil, url: nil, username: nil}
def fixture(:account) do
{:ok, account} = Accounts.create_account(@create_attrs)
account
end
describe "index" do
test "lists all accounts", %{conn: conn} do
conn = get conn, account_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Accounts"
end
end
describe "new account" do
test "renders form", %{conn: conn} do
conn = get conn, account_path(conn, :new)
assert html_response(conn, 200) =~ "New Account"
end
end
describe "create account" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, account_path(conn, :create), account: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == account_path(conn, :show, id)
conn = get conn, account_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Account"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, account_path(conn, :create), account: @invalid_attrs
assert html_response(conn, 200) =~ "New Account"
end
end
describe "edit account" do
setup [:create_account]
test "renders form for editing chosen account", %{conn: conn, account: account} do
conn = get conn, account_path(conn, :edit, account)
assert html_response(conn, 200) =~ "Edit Account"
end
end
describe "update account" do
setup [:create_account]
test "redirects when data is valid", %{conn: conn, account: account} do
conn = put conn, account_path(conn, :update, account), account: @update_attrs
assert redirected_to(conn) == account_path(conn, :show, account)
conn = get conn, account_path(conn, :show, account)
assert html_response(conn, 200) =~ "some updated description"
end
test "renders errors when data is invalid", %{conn: conn, account: account} do
conn = put conn, account_path(conn, :update, account), account: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Account"
end
end
describe "delete account" do
setup [:create_account]
test "deletes chosen account", %{conn: conn, account: account} do
conn = delete conn, account_path(conn, :delete, account)
assert redirected_to(conn) == account_path(conn, :index)
assert_error_sent 404, fn ->
get conn, account_path(conn, :show, account)
end
end
end
defp create_account(_) do
account = fixture(:account)
{:ok, account: account}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.CategoryControllerTest do
use EventosWeb.ConnCase
alias Eventos.Events
@create_attrs %{picture: "some picture", title: "some title"}
@update_attrs %{picture: "some updated picture", title: "some updated title"}
@invalid_attrs %{picture: nil, title: nil}
def fixture(:category) do
{:ok, category} = Events.create_category(@create_attrs)
category
end
describe "index" do
test "lists all categories", %{conn: conn} do
conn = get conn, category_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Categories"
end
end
describe "new category" do
test "renders form", %{conn: conn} do
conn = get conn, category_path(conn, :new)
assert html_response(conn, 200) =~ "New Category"
end
end
describe "create category" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, category_path(conn, :create), category: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == category_path(conn, :show, id)
conn = get conn, category_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Category"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, category_path(conn, :create), category: @invalid_attrs
assert html_response(conn, 200) =~ "New Category"
end
end
describe "edit category" do
setup [:create_category]
test "renders form for editing chosen category", %{conn: conn, category: category} do
conn = get conn, category_path(conn, :edit, category)
assert html_response(conn, 200) =~ "Edit Category"
end
end
describe "update category" do
setup [:create_category]
test "redirects when data is valid", %{conn: conn, category: category} do
conn = put conn, category_path(conn, :update, category), category: @update_attrs
assert redirected_to(conn) == category_path(conn, :show, category)
conn = get conn, category_path(conn, :show, category)
assert html_response(conn, 200) =~ "some updated picture"
end
test "renders errors when data is invalid", %{conn: conn, category: category} do
conn = put conn, category_path(conn, :update, category), category: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Category"
end
end
describe "delete category" do
setup [:create_category]
test "deletes chosen category", %{conn: conn, category: category} do
conn = delete conn, category_path(conn, :delete, category)
assert redirected_to(conn) == category_path(conn, :index)
assert_error_sent 404, fn ->
get conn, category_path(conn, :show, category)
end
end
end
defp create_category(_) do
category = fixture(:category)
{:ok, category: category}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.EventAccountsControllerTest do
use EventosWeb.ConnCase
alias Eventos.Events
@create_attrs %{roles: 42}
@update_attrs %{roles: 43}
@invalid_attrs %{roles: nil}
def fixture(:event_accounts) do
{:ok, event_accounts} = Events.create_event_accounts(@create_attrs)
event_accounts
end
describe "index" do
test "lists all event_accounts", %{conn: conn} do
conn = get conn, event_accounts_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Event accounts"
end
end
describe "new event_accounts" do
test "renders form", %{conn: conn} do
conn = get conn, event_accounts_path(conn, :new)
assert html_response(conn, 200) =~ "New Event accounts"
end
end
describe "create event_accounts" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, event_accounts_path(conn, :create), event_accounts: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == event_accounts_path(conn, :show, id)
conn = get conn, event_accounts_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Event accounts"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, event_accounts_path(conn, :create), event_accounts: @invalid_attrs
assert html_response(conn, 200) =~ "New Event accounts"
end
end
describe "edit event_accounts" do
setup [:create_event_accounts]
test "renders form for editing chosen event_accounts", %{conn: conn, event_accounts: event_accounts} do
conn = get conn, event_accounts_path(conn, :edit, event_accounts)
assert html_response(conn, 200) =~ "Edit Event accounts"
end
end
describe "update event_accounts" do
setup [:create_event_accounts]
test "redirects when data is valid", %{conn: conn, event_accounts: event_accounts} do
conn = put conn, event_accounts_path(conn, :update, event_accounts), event_accounts: @update_attrs
assert redirected_to(conn) == event_accounts_path(conn, :show, event_accounts)
conn = get conn, event_accounts_path(conn, :show, event_accounts)
assert html_response(conn, 200)
end
test "renders errors when data is invalid", %{conn: conn, event_accounts: event_accounts} do
conn = put conn, event_accounts_path(conn, :update, event_accounts), event_accounts: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Event accounts"
end
end
describe "delete event_accounts" do
setup [:create_event_accounts]
test "deletes chosen event_accounts", %{conn: conn, event_accounts: event_accounts} do
conn = delete conn, event_accounts_path(conn, :delete, event_accounts)
assert redirected_to(conn) == event_accounts_path(conn, :index)
assert_error_sent 404, fn ->
get conn, event_accounts_path(conn, :show, event_accounts)
end
end
end
defp create_event_accounts(_) do
event_accounts = fixture(:event_accounts)
{:ok, event_accounts: event_accounts}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.EventControllerTest do
use EventosWeb.ConnCase
alias Eventos.Events
@create_attrs %{begin_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 %{begin_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 %{begin_on: nil, description: nil, ends_on: nil, title: nil}
def fixture(:event) do
{:ok, event} = Events.create_event(@create_attrs)
event
end
describe "index" do
test "lists all events", %{conn: conn} do
conn = get conn, event_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Events"
end
end
describe "new event" do
test "renders form", %{conn: conn} do
conn = get conn, event_path(conn, :new)
assert html_response(conn, 200) =~ "New Event"
end
end
describe "create event" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, event_path(conn, :create), event: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == event_path(conn, :show, id)
conn = get conn, event_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Event"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, event_path(conn, :create), event: @invalid_attrs
assert html_response(conn, 200) =~ "New Event"
end
end
describe "edit event" do
setup [:create_event]
test "renders form for editing chosen event", %{conn: conn, event: event} do
conn = get conn, event_path(conn, :edit, event)
assert html_response(conn, 200) =~ "Edit Event"
end
end
describe "update event" do
setup [:create_event]
test "redirects when data is valid", %{conn: conn, event: event} do
conn = put conn, event_path(conn, :update, event), event: @update_attrs
assert redirected_to(conn) == event_path(conn, :show, event)
conn = get conn, event_path(conn, :show, event)
assert html_response(conn, 200) =~ "some updated description"
end
test "renders errors when data is invalid", %{conn: conn, event: event} do
conn = put conn, event_path(conn, :update, event), event: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Event"
end
end
describe "delete event" do
setup [:create_event]
test "deletes chosen event", %{conn: conn, event: event} do
conn = delete conn, event_path(conn, :delete, event)
assert redirected_to(conn) == event_path(conn, :index)
assert_error_sent 404, fn ->
get conn, event_path(conn, :show, event)
end
end
end
defp create_event(_) do
event = fixture(:event)
{:ok, event: event}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.EventRequestControllerTest do
use EventosWeb.ConnCase
alias Eventos.Events
@create_attrs %{state: 42}
@update_attrs %{state: 43}
@invalid_attrs %{state: nil}
def fixture(:event_request) do
{:ok, event_request} = Events.create_event_request(@create_attrs)
event_request
end
describe "index" do
test "lists all event_requests", %{conn: conn} do
conn = get conn, event_request_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Event requests"
end
end
describe "new event_request" do
test "renders form", %{conn: conn} do
conn = get conn, event_request_path(conn, :new)
assert html_response(conn, 200) =~ "New Event request"
end
end
describe "create event_request" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, event_request_path(conn, :create), event_request: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == event_request_path(conn, :show, id)
conn = get conn, event_request_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Event request"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, event_request_path(conn, :create), event_request: @invalid_attrs
assert html_response(conn, 200) =~ "New Event request"
end
end
describe "edit event_request" do
setup [:create_event_request]
test "renders form for editing chosen event_request", %{conn: conn, event_request: event_request} do
conn = get conn, event_request_path(conn, :edit, event_request)
assert html_response(conn, 200) =~ "Edit Event request"
end
end
describe "update event_request" do
setup [:create_event_request]
test "redirects when data is valid", %{conn: conn, event_request: event_request} do
conn = put conn, event_request_path(conn, :update, event_request), event_request: @update_attrs
assert redirected_to(conn) == event_request_path(conn, :show, event_request)
conn = get conn, event_request_path(conn, :show, event_request)
assert html_response(conn, 200)
end
test "renders errors when data is invalid", %{conn: conn, event_request: event_request} do
conn = put conn, event_request_path(conn, :update, event_request), event_request: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Event request"
end
end
describe "delete event_request" do
setup [:create_event_request]
test "deletes chosen event_request", %{conn: conn, event_request: event_request} do
conn = delete conn, event_request_path(conn, :delete, event_request)
assert redirected_to(conn) == event_request_path(conn, :index)
assert_error_sent 404, fn ->
get conn, event_request_path(conn, :show, event_request)
end
end
end
defp create_event_request(_) do
event_request = fixture(:event_request)
{:ok, event_request: event_request}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.GroupAccountControllerTest do
use EventosWeb.ConnCase
alias Eventos.Accounts
@create_attrs %{role: 42}
@update_attrs %{role: 43}
@invalid_attrs %{role: nil}
def fixture(:group_account) do
{:ok, group_account} = Accounts.create_group_account(@create_attrs)
group_account
end
describe "index" do
test "lists all group_accounts", %{conn: conn} do
conn = get conn, group_account_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Group accounts"
end
end
describe "new group_account" do
test "renders form", %{conn: conn} do
conn = get conn, group_account_path(conn, :new)
assert html_response(conn, 200) =~ "New Group account"
end
end
describe "create group_account" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, group_account_path(conn, :create), group_account: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == group_account_path(conn, :show, id)
conn = get conn, group_account_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Group account"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, group_account_path(conn, :create), group_account: @invalid_attrs
assert html_response(conn, 200) =~ "New Group account"
end
end
describe "edit group_account" do
setup [:create_group_account]
test "renders form for editing chosen group_account", %{conn: conn, group_account: group_account} do
conn = get conn, group_account_path(conn, :edit, group_account)
assert html_response(conn, 200) =~ "Edit Group account"
end
end
describe "update group_account" do
setup [:create_group_account]
test "redirects when data is valid", %{conn: conn, group_account: group_account} do
conn = put conn, group_account_path(conn, :update, group_account), group_account: @update_attrs
assert redirected_to(conn) == group_account_path(conn, :show, group_account)
conn = get conn, group_account_path(conn, :show, group_account)
assert html_response(conn, 200)
end
test "renders errors when data is invalid", %{conn: conn, group_account: group_account} do
conn = put conn, group_account_path(conn, :update, group_account), group_account: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Group account"
end
end
describe "delete group_account" do
setup [:create_group_account]
test "deletes chosen group_account", %{conn: conn, group_account: group_account} do
conn = delete conn, group_account_path(conn, :delete, group_account)
assert redirected_to(conn) == group_account_path(conn, :index)
assert_error_sent 404, fn ->
get conn, group_account_path(conn, :show, group_account)
end
end
end
defp create_group_account(_) do
group_account = fixture(:group_account)
{:ok, group_account: group_account}
end
end

View File

@@ -0,0 +1,88 @@
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

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.GroupRequestControllerTest do
use EventosWeb.ConnCase
alias Eventos.Accounts
@create_attrs %{state: 42}
@update_attrs %{state: 43}
@invalid_attrs %{state: nil}
def fixture(:group_request) do
{:ok, group_request} = Accounts.create_group_request(@create_attrs)
group_request
end
describe "index" do
test "lists all group_request", %{conn: conn} do
conn = get conn, group_request_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Group requests"
end
end
describe "new group_request" do
test "renders form", %{conn: conn} do
conn = get conn, group_request_path(conn, :new)
assert html_response(conn, 200) =~ "New Group request"
end
end
describe "create group_request" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, group_request_path(conn, :create), group_request: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == group_request_path(conn, :show, id)
conn = get conn, group_request_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Group request"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, group_request_path(conn, :create), group_request: @invalid_attrs
assert html_response(conn, 200) =~ "New Group request"
end
end
describe "edit group_request" do
setup [:create_group_request]
test "renders form for editing chosen group_request", %{conn: conn, group_request: group_request} do
conn = get conn, group_request_path(conn, :edit, group_request)
assert html_response(conn, 200) =~ "Edit Group request"
end
end
describe "update group_request" do
setup [:create_group_request]
test "redirects when data is valid", %{conn: conn, group_request: group_request} do
conn = put conn, group_request_path(conn, :update, group_request), group_request: @update_attrs
assert redirected_to(conn) == group_request_path(conn, :show, group_request)
conn = get conn, group_request_path(conn, :show, group_request)
assert html_response(conn, 200)
end
test "renders errors when data is invalid", %{conn: conn, group_request: group_request} do
conn = put conn, group_request_path(conn, :update, group_request), group_request: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Group request"
end
end
describe "delete group_request" do
setup [:create_group_request]
test "deletes chosen group_request", %{conn: conn, group_request: group_request} do
conn = delete conn, group_request_path(conn, :delete, group_request)
assert redirected_to(conn) == group_request_path(conn, :index)
assert_error_sent 404, fn ->
get conn, group_request_path(conn, :show, group_request)
end
end
end
defp create_group_request(_) do
group_request = fixture(:group_request)
{:ok, group_request: group_request}
end
end

View File

@@ -0,0 +1,8 @@
defmodule EventosWeb.PageControllerTest do
use EventosWeb.ConnCase
test "GET /", %{conn: conn} do
conn = get conn, "/"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.TagControllerTest do
use EventosWeb.ConnCase
alias Eventos.Events
@create_attrs %{slug: "some slug", title: "some title"}
@update_attrs %{slug: "some updated slug", title: "some updated title"}
@invalid_attrs %{slug: nil, title: nil}
def fixture(:tag) do
{:ok, tag} = Events.create_tag(@create_attrs)
tag
end
describe "index" do
test "lists all tags", %{conn: conn} do
conn = get conn, tag_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Tags"
end
end
describe "new tag" do
test "renders form", %{conn: conn} do
conn = get conn, tag_path(conn, :new)
assert html_response(conn, 200) =~ "New Tag"
end
end
describe "create tag" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, tag_path(conn, :create), tag: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == tag_path(conn, :show, id)
conn = get conn, tag_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show Tag"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, tag_path(conn, :create), tag: @invalid_attrs
assert html_response(conn, 200) =~ "New Tag"
end
end
describe "edit tag" do
setup [:create_tag]
test "renders form for editing chosen tag", %{conn: conn, tag: tag} do
conn = get conn, tag_path(conn, :edit, tag)
assert html_response(conn, 200) =~ "Edit Tag"
end
end
describe "update tag" do
setup [:create_tag]
test "redirects when data is valid", %{conn: conn, tag: tag} do
conn = put conn, tag_path(conn, :update, tag), tag: @update_attrs
assert redirected_to(conn) == tag_path(conn, :show, tag)
conn = get conn, tag_path(conn, :show, tag)
assert html_response(conn, 200) =~ "some updated slug"
end
test "renders errors when data is invalid", %{conn: conn, tag: tag} do
conn = put conn, tag_path(conn, :update, tag), tag: @invalid_attrs
assert html_response(conn, 200) =~ "Edit Tag"
end
end
describe "delete tag" do
setup [:create_tag]
test "deletes chosen tag", %{conn: conn, tag: tag} do
conn = delete conn, tag_path(conn, :delete, tag)
assert redirected_to(conn) == tag_path(conn, :index)
assert_error_sent 404, fn ->
get conn, tag_path(conn, :show, tag)
end
end
end
defp create_tag(_) do
tag = fixture(:tag)
{:ok, tag: tag}
end
end

View File

@@ -0,0 +1,88 @@
defmodule EventosWeb.UserControllerTest do
use EventosWeb.ConnCase
alias Eventos.Accounts
@create_attrs %{email: "some email", password_hash: "some password_hash", role: 42, username: "some username"}
@update_attrs %{email: "some updated email", password_hash: "some updated password_hash", role: 43, username: "some updated username"}
@invalid_attrs %{email: nil, password_hash: nil, role: nil, username: nil}
def fixture(:user) do
{:ok, user} = Accounts.create_user(@create_attrs)
user
end
describe "index" do
test "lists all users", %{conn: conn} do
conn = get conn, user_path(conn, :index)
assert html_response(conn, 200) =~ "Listing Users"
end
end
describe "new user" do
test "renders form", %{conn: conn} do
conn = get conn, user_path(conn, :new)
assert html_response(conn, 200) =~ "New User"
end
end
describe "create user" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post conn, user_path(conn, :create), user: @create_attrs
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == user_path(conn, :show, id)
conn = get conn, user_path(conn, :show, id)
assert html_response(conn, 200) =~ "Show User"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post conn, user_path(conn, :create), user: @invalid_attrs
assert html_response(conn, 200) =~ "New User"
end
end
describe "edit user" do
setup [:create_user]
test "renders form for editing chosen user", %{conn: conn, user: user} do
conn = get conn, user_path(conn, :edit, user)
assert html_response(conn, 200) =~ "Edit User"
end
end
describe "update user" do
setup [:create_user]
test "redirects when data is valid", %{conn: conn, user: user} do
conn = put conn, user_path(conn, :update, user), user: @update_attrs
assert redirected_to(conn) == user_path(conn, :show, user)
conn = get conn, user_path(conn, :show, user)
assert html_response(conn, 200) =~ "some updated email"
end
test "renders errors when data is invalid", %{conn: conn, user: user} do
conn = put conn, user_path(conn, :update, user), user: @invalid_attrs
assert html_response(conn, 200) =~ "Edit User"
end
end
describe "delete user" do
setup [:create_user]
test "deletes chosen user", %{conn: conn, user: user} do
conn = delete conn, user_path(conn, :delete, user)
assert redirected_to(conn) == user_path(conn, :index)
assert_error_sent 404, fn ->
get conn, user_path(conn, :show, user)
end
end
end
defp create_user(_) do
user = fixture(:user)
{:ok, user: user}
end
end

View File

@@ -0,0 +1,21 @@
defmodule EventosWeb.ErrorViewTest do
use EventosWeb.ConnCase, async: true
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
test "renders 404.html" do
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"
end
test "render any other" do
assert render_to_string(EventosWeb.ErrorView, "505.html", []) ==
"Internal server error"
end
end

View File

@@ -0,0 +1,3 @@
defmodule EventosWeb.LayoutViewTest do
use EventosWeb.ConnCase, async: true
end

View File

@@ -0,0 +1,3 @@
defmodule EventosWeb.PageViewTest do
use EventosWeb.ConnCase, async: true
end

View File

@@ -0,0 +1,37 @@
defmodule EventosWeb.ChannelCase do
@moduledoc """
This module defines the test case to be used by
channel tests.
Such tests rely on `Phoenix.ChannelTest` and also
import other functionality to make it easier
to build common datastructures and query the data layer.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""
use ExUnit.CaseTemplate
using do
quote do
# Import conveniences for testing with channels
use Phoenix.ChannelTest
# The default endpoint for testing
@endpoint EventosWeb.Endpoint
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

38
test/support/conn_case.ex Normal file
View File

@@ -0,0 +1,38 @@
defmodule EventosWeb.ConnCase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a connection.
Such tests rely on `Phoenix.ConnTest` and also
import other functionality to make it easier
to build common datastructures and query the data layer.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""
use ExUnit.CaseTemplate
using do
quote do
# Import conveniences for testing with connections
use Phoenix.ConnTest
import EventosWeb.Router.Helpers
# The default endpoint for testing
@endpoint EventosWeb.Endpoint
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

53
test/support/data_case.ex Normal file
View File

@@ -0,0 +1,53 @@
defmodule Eventos.DataCase do
@moduledoc """
This module defines the setup for tests requiring
access to the application's data layer.
You may define functions here to be used as helpers in
your tests.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""
use ExUnit.CaseTemplate
using do
quote do
alias Eventos.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query
import Eventos.DataCase
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
@doc """
A helper that transform changeset errors to a map of messages.
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
assert %{password: ["password is too short"]} = errors_on(changeset)
"""
def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Enum.reduce(opts, message, fn {key, value}, acc ->
String.replace(acc, "%{#{key}}", to_string(value))
end)
end)
end
end

4
test/test_helper.exs Normal file
View File

@@ -0,0 +1,4 @@
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, :manual)