homeman-elixir/test/homeman/accounts_test.exs
2024-01-21 23:48:10 -06:00

182 lines
6.3 KiB
Elixir

defmodule Homeman.AccountsTest do
use Homeman.DataCase
alias Homeman.Accounts
describe "users" do
alias Homeman.Accounts.User
import Homeman.AccountsFixtures
@invalid_attrs %{name: nil, color: nil, avatar_url: nil}
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
valid_attrs = %{name: "some name", color: "some color", avatar_url: "some avatar_url"}
assert {:ok, %User{} = user} = Accounts.create_user(valid_attrs)
assert user.name == "some name"
assert user.color == "some color"
assert user.avatar_url == "some avatar_url"
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()
update_attrs = %{name: "some updated name", color: "some updated color", avatar_url: "some updated avatar_url"}
assert {:ok, %User{} = user} = Accounts.update_user(user, update_attrs)
assert user.name == "some updated name"
assert user.color == "some updated color"
assert user.avatar_url == "some updated avatar_url"
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 "todos" do
alias Homeman.Accounts.Todo
import Homeman.AccountsFixtures
@invalid_attrs %{description: nil, emoji: nil, completed_at: nil}
test "list_todos/0 returns all todos" do
todo = todo_fixture()
assert Accounts.list_todos() == [todo]
end
test "get_todo!/1 returns the todo with given id" do
todo = todo_fixture()
assert Accounts.get_todo!(todo.id) == todo
end
test "create_todo/1 with valid data creates a todo" do
valid_attrs = %{description: "some description", emoji: "some emoji", completed_at: ~N[2024-01-21 05:40:00]}
assert {:ok, %Todo{} = todo} = Accounts.create_todo(valid_attrs)
assert todo.description == "some description"
assert todo.emoji == "some emoji"
assert todo.completed_at == ~N[2024-01-21 05:40:00]
end
test "create_todo/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_todo(@invalid_attrs)
end
test "update_todo/2 with valid data updates the todo" do
todo = todo_fixture()
update_attrs = %{description: "some updated description", emoji: "some updated emoji", completed_at: ~N[2024-01-22 05:40:00]}
assert {:ok, %Todo{} = todo} = Accounts.update_todo(todo, update_attrs)
assert todo.description == "some updated description"
assert todo.emoji == "some updated emoji"
assert todo.completed_at == ~N[2024-01-22 05:40:00]
end
test "update_todo/2 with invalid data returns error changeset" do
todo = todo_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_todo(todo, @invalid_attrs)
assert todo == Accounts.get_todo!(todo.id)
end
test "delete_todo/1 deletes the todo" do
todo = todo_fixture()
assert {:ok, %Todo{}} = Accounts.delete_todo(todo)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_todo!(todo.id) end
end
test "change_todo/1 returns a todo changeset" do
todo = todo_fixture()
assert %Ecto.Changeset{} = Accounts.change_todo(todo)
end
end
describe "tasks" do
alias Homeman.Accounts.Task
import Homeman.AccountsFixtures
@invalid_attrs %{description: nil, phase: nil, emoji: nil, completed_at: nil}
test "list_tasks/0 returns all tasks" do
task = task_fixture()
assert Accounts.list_tasks() == [task]
end
test "get_task!/1 returns the task with given id" do
task = task_fixture()
assert Accounts.get_task!(task.id) == task
end
test "create_task/1 with valid data creates a task" do
valid_attrs = %{description: "some description", phase: "some phase", emoji: "some emoji", completed_at: ~N[2024-01-21 05:40:00]}
assert {:ok, %Task{} = task} = Accounts.create_task(valid_attrs)
assert task.description == "some description"
assert task.phase == "some phase"
assert task.emoji == "some emoji"
assert task.completed_at == ~N[2024-01-21 05:40:00]
end
test "create_task/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Accounts.create_task(@invalid_attrs)
end
test "update_task/2 with valid data updates the task" do
task = task_fixture()
update_attrs = %{description: "some updated description", phase: "some updated phase", emoji: "some updated emoji", completed_at: ~N[2024-01-22 05:40:00]}
assert {:ok, %Task{} = task} = Accounts.update_task(task, update_attrs)
assert task.description == "some updated description"
assert task.phase == "some updated phase"
assert task.emoji == "some updated emoji"
assert task.completed_at == ~N[2024-01-22 05:40:00]
end
test "update_task/2 with invalid data returns error changeset" do
task = task_fixture()
assert {:error, %Ecto.Changeset{}} = Accounts.update_task(task, @invalid_attrs)
assert task == Accounts.get_task!(task.id)
end
test "delete_task/1 deletes the task" do
task = task_fixture()
assert {:ok, %Task{}} = Accounts.delete_task(task)
assert_raise Ecto.NoResultsError, fn -> Accounts.get_task!(task.id) end
end
test "change_task/1 returns a task changeset" do
task = task_fixture()
assert %Ecto.Changeset{} = Accounts.change_task(task)
end
end
end