forked from shibao/cannery
add invite model
This commit is contained in:
66
test/cannery/invites_test.exs
Normal file
66
test/cannery/invites_test.exs
Normal file
@ -0,0 +1,66 @@
|
||||
defmodule Cannery.InvitesTest do
|
||||
use Cannery.DataCase
|
||||
|
||||
alias Cannery.Invites
|
||||
|
||||
describe "invites" do
|
||||
alias Cannery.Invites.Invite
|
||||
|
||||
@valid_attrs %{name: "some name", token: "some token"}
|
||||
@update_attrs %{name: "some updated name", token: "some updated token"}
|
||||
@invalid_attrs %{name: nil, token: nil}
|
||||
|
||||
def invite_fixture(attrs \\ %{}) do
|
||||
{:ok, invite} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Invites.create_invite()
|
||||
|
||||
invite
|
||||
end
|
||||
|
||||
test "list_invites/0 returns all invites" do
|
||||
invite = invite_fixture()
|
||||
assert Invites.list_invites() == [invite]
|
||||
end
|
||||
|
||||
test "get_invite!/1 returns the invite with given id" do
|
||||
invite = invite_fixture()
|
||||
assert Invites.get_invite!(invite.id) == invite
|
||||
end
|
||||
|
||||
test "create_invite/1 with valid data creates a invite" do
|
||||
assert {:ok, %Invite{} = invite} = Invites.create_invite(@valid_attrs)
|
||||
assert invite.name == "some name"
|
||||
assert invite.token == "some token"
|
||||
end
|
||||
|
||||
test "create_invite/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Invites.create_invite(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_invite/2 with valid data updates the invite" do
|
||||
invite = invite_fixture()
|
||||
assert {:ok, %Invite{} = invite} = Invites.update_invite(invite, @update_attrs)
|
||||
assert invite.name == "some updated name"
|
||||
assert invite.token == "some updated token"
|
||||
end
|
||||
|
||||
test "update_invite/2 with invalid data returns error changeset" do
|
||||
invite = invite_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Invites.update_invite(invite, @invalid_attrs)
|
||||
assert invite == Invites.get_invite!(invite.id)
|
||||
end
|
||||
|
||||
test "delete_invite/1 deletes the invite" do
|
||||
invite = invite_fixture()
|
||||
assert {:ok, %Invite{}} = Invites.delete_invite(invite)
|
||||
assert_raise Ecto.NoResultsError, fn -> Invites.get_invite!(invite.id) end
|
||||
end
|
||||
|
||||
test "change_invite/1 returns a invite changeset" do
|
||||
invite = invite_fixture()
|
||||
assert %Ecto.Changeset{} = Invites.change_invite(invite)
|
||||
end
|
||||
end
|
||||
end
|
116
test/cannery_web/live/invite_live_test.exs
Normal file
116
test/cannery_web/live/invite_live_test.exs
Normal file
@ -0,0 +1,116 @@
|
||||
defmodule CanneryWeb.InviteLiveTest do
|
||||
use CanneryWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
alias Cannery.Invites
|
||||
|
||||
@create_attrs %{name: "some name", token: "some token"}
|
||||
@update_attrs %{name: "some updated name", token: "some updated token"}
|
||||
@invalid_attrs %{name: nil, token: nil}
|
||||
|
||||
defp fixture(:invite) do
|
||||
{:ok, invite} = Invites.create_invite(@create_attrs)
|
||||
invite
|
||||
end
|
||||
|
||||
defp create_invite(_) do
|
||||
invite = fixture(:invite)
|
||||
%{invite: invite}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_invite]
|
||||
|
||||
test "lists all invites", %{conn: conn, invite: invite} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Invites"
|
||||
assert html =~ invite.name
|
||||
end
|
||||
|
||||
test "saves new invite", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New Invite") |> render_click() =~
|
||||
"New Invite"
|
||||
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#invite-form", invite: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Invite created successfully"
|
||||
assert html =~ "some name"
|
||||
end
|
||||
|
||||
test "updates invite in listing", %{conn: conn, invite: invite} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#invite-#{invite.id} a", "Edit") |> render_click() =~
|
||||
"Edit Invite"
|
||||
|
||||
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
|
||||
|
||||
assert index_live
|
||||
|> form("#invite-form", invite: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#invite-form", invite: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Invite updated successfully"
|
||||
assert html =~ "some updated name"
|
||||
end
|
||||
|
||||
test "deletes invite in listing", %{conn: conn, invite: invite} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#invite-#{invite.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#invite-#{invite.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_invite]
|
||||
|
||||
test "displays invite", %{conn: conn, invite: invite} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.invite_show_path(conn, :show, invite))
|
||||
|
||||
assert html =~ "Show Invite"
|
||||
assert html =~ invite.name
|
||||
end
|
||||
|
||||
test "updates invite within modal", %{conn: conn, invite: invite} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.invite_show_path(conn, :show, invite))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Invite"
|
||||
|
||||
assert_patch(show_live, Routes.invite_show_path(conn, :edit, invite))
|
||||
|
||||
assert show_live
|
||||
|> form("#invite-form", invite: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#invite-form", invite: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.invite_show_path(conn, :show, invite))
|
||||
|
||||
assert html =~ "Invite updated successfully"
|
||||
assert html =~ "some updated name"
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user