forked from shibao/cannery
76 lines
2.2 KiB
Elixir
76 lines
2.2 KiB
Elixir
defmodule Cannery.InvitesTest do
|
|
use Cannery.DataCase
|
|
|
|
alias Cannery.{AccountsFixtures, Invites}
|
|
alias Ecto.Changeset
|
|
|
|
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} =
|
|
AccountsFixtures.user_fixture()
|
|
|> Invites.create_invite(attrs |> Enum.into(@valid_attrs))
|
|
|
|
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, %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, %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 %Changeset{} = Invites.change_invite(invite)
|
|
end
|
|
end
|
|
end
|