forked from shibao/cannery
pass invites test
This commit is contained in:
parent
bd964105b4
commit
6f02310880
@ -1,74 +1,76 @@
|
|||||||
defmodule Cannery.InvitesTest do
|
defmodule Cannery.InvitesTest do
|
||||||
|
@moduledoc """
|
||||||
|
This module tests the Invites context
|
||||||
|
"""
|
||||||
|
|
||||||
use Cannery.DataCase
|
use Cannery.DataCase
|
||||||
|
|
||||||
alias Cannery.{AccountsFixtures, Invites}
|
alias Cannery.{Invites, Invites.Invite}
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
|
|
||||||
|
@moduletag :invites_test
|
||||||
|
|
||||||
|
@valid_attrs %{
|
||||||
|
"name" => "some name",
|
||||||
|
"token" => "some token"
|
||||||
|
}
|
||||||
|
@update_attrs %{
|
||||||
|
"name" => "some updated name",
|
||||||
|
"token" => "some updated token"
|
||||||
|
}
|
||||||
|
@invalid_attrs %{
|
||||||
|
"name" => nil,
|
||||||
|
"token" => nil
|
||||||
|
}
|
||||||
|
|
||||||
describe "invites" do
|
describe "invites" do
|
||||||
alias Cannery.Invites.Invite
|
setup do
|
||||||
|
current_user = admin_fixture()
|
||||||
@valid_attrs %{
|
{:ok, invite} = Invites.create_invite(current_user, @valid_attrs)
|
||||||
"name" => "some name",
|
[invite: invite, current_user: current_user]
|
||||||
"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
|
end
|
||||||
|
|
||||||
test "list_invites/0 returns all invites" do
|
test "list_invites/0 returns all invites", %{invite: invite, current_user: current_user} do
|
||||||
invite = invite_fixture()
|
assert Invites.list_invites(current_user) == [invite]
|
||||||
assert Invites.list_invites() == [invite]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get_invite!/1 returns the invite with given id" do
|
test "get_invite!/1 returns the invite with given id",
|
||||||
invite = invite_fixture()
|
%{invite: invite, current_user: current_user} do
|
||||||
assert Invites.get_invite!(invite.id) == invite
|
assert Invites.get_invite!(invite.id, current_user) == invite
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_invite/1 with valid data creates a invite" do
|
test "create_invite/1 with valid data creates a invite",
|
||||||
assert {:ok, %Invite{} = invite} = Invites.create_invite(@valid_attrs)
|
%{current_user: current_user} do
|
||||||
|
assert {:ok, %Invite{} = invite} = Invites.create_invite(current_user, @valid_attrs)
|
||||||
assert invite.name == "some name"
|
assert invite.name == "some name"
|
||||||
assert invite.token == "some token"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_invite/1 with invalid data returns error changeset" do
|
test "create_invite/1 with invalid data returns error changeset",
|
||||||
assert {:error, %Changeset{}} = Invites.create_invite(@invalid_attrs)
|
%{current_user: current_user} do
|
||||||
|
assert {:error, %Changeset{}} = Invites.create_invite(current_user, @invalid_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_invite/2 with valid data updates the invite" do
|
test "update_invite/2 with valid data updates the invite",
|
||||||
invite = invite_fixture()
|
%{invite: invite, current_user: current_user} do
|
||||||
assert {:ok, %Invite{} = invite} = Invites.update_invite(invite, @update_attrs)
|
assert {:ok, %Invite{} = new_invite} =
|
||||||
assert invite.name == "some updated name"
|
Invites.update_invite(invite, @update_attrs, current_user)
|
||||||
assert invite.token == "some updated token"
|
|
||||||
|
assert new_invite.name == "some updated name"
|
||||||
|
assert new_invite.token == new_invite.token
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_invite/2 with invalid data returns error changeset" do
|
test "update_invite/2 with invalid data returns error changeset",
|
||||||
invite = invite_fixture()
|
%{invite: invite, current_user: current_user} do
|
||||||
assert {:error, %Changeset{}} = Invites.update_invite(invite, @invalid_attrs)
|
assert {:error, %Changeset{}} = Invites.update_invite(invite, @invalid_attrs, current_user)
|
||||||
assert invite == Invites.get_invite!(invite.id)
|
assert invite == Invites.get_invite!(invite.id, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_invite/1 deletes the invite" do
|
test "delete_invite/1 deletes the invite", %{invite: invite, current_user: current_user} do
|
||||||
invite = invite_fixture()
|
assert {:ok, %Invite{}} = Invites.delete_invite(invite, current_user)
|
||||||
assert {:ok, %Invite{}} = Invites.delete_invite(invite)
|
assert_raise Ecto.NoResultsError, fn -> Invites.get_invite!(invite.id, current_user) end
|
||||||
assert_raise Ecto.NoResultsError, fn -> Invites.get_invite!(invite.id) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "change_invite/1 returns a invite changeset" do
|
test "change_invite/1 returns a invite changeset", %{invite: invite} do
|
||||||
invite = invite_fixture()
|
|
||||||
assert %Changeset{} = Invites.change_invite(invite)
|
assert %Changeset{} = Invites.change_invite(invite)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user