chore-tracker/test/chore_tracker/chores_test.exs
2024-08-08 00:55:01 +02:00

181 lines
6.7 KiB
Elixir

defmodule ChoreTracker.ChoresTest do
use ChoreTracker.DataCase
alias ChoreTracker.Chores
describe "chores" do
alias ChoreTracker.Chores.Chore
import ChoreTracker.ChoresFixtures
@invalid_attrs %{name: nil, description: nil, period: nil, emoji: nil, period_unit: nil, starts_at: nil}
test "list_chores/0 returns all chores" do
chore = chore_fixture()
assert Chores.list_chores() == [chore]
end
test "get_chore!/1 returns the chore with given id" do
chore = chore_fixture()
assert Chores.get_chore!(chore.id) == chore
end
test "create_chore/1 with valid data creates a chore" do
valid_attrs = %{name: "some name", description: "some description", period: 42, emoji: "some emoji", period_unit: :hour, starts_at: ~D[2024-08-06]}
assert {:ok, %Chore{} = chore} = Chores.create_chore(valid_attrs)
assert chore.name == "some name"
assert chore.description == "some description"
assert chore.period == 42
assert chore.emoji == "some emoji"
assert chore.period_unit == :hour
assert chore.starts_at == ~D[2024-08-06]
end
test "create_chore/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Chores.create_chore(@invalid_attrs)
end
test "update_chore/2 with valid data updates the chore" do
chore = chore_fixture()
update_attrs = %{name: "some updated name", description: "some updated description", period: 43, emoji: "some updated emoji", period_unit: :day, starts_at: ~D[2024-08-07]}
assert {:ok, %Chore{} = chore} = Chores.update_chore(chore, update_attrs)
assert chore.name == "some updated name"
assert chore.description == "some updated description"
assert chore.period == 43
assert chore.emoji == "some updated emoji"
assert chore.period_unit == :day
assert chore.starts_at == ~D[2024-08-07]
end
test "update_chore/2 with invalid data returns error changeset" do
chore = chore_fixture()
assert {:error, %Ecto.Changeset{}} = Chores.update_chore(chore, @invalid_attrs)
assert chore == Chores.get_chore!(chore.id)
end
test "delete_chore/1 deletes the chore" do
chore = chore_fixture()
assert {:ok, %Chore{}} = Chores.delete_chore(chore)
assert_raise Ecto.NoResultsError, fn -> Chores.get_chore!(chore.id) end
end
test "change_chore/1 returns a chore changeset" do
chore = chore_fixture()
assert %Ecto.Changeset{} = Chores.change_chore(chore)
end
end
describe "chore_logs" do
alias ChoreTracker.Chores.ChoreLog
import ChoreTracker.ChoresFixtures
@invalid_attrs %{chore_id: nil, user_id: nil}
test "list_chore_logs/0 returns all chore_logs" do
chore_log = chore_log_fixture()
assert Chores.list_chore_logs() == [chore_log]
end
test "get_chore_log!/1 returns the chore_log with given id" do
chore_log = chore_log_fixture()
assert Chores.get_chore_log!(chore_log.id) == chore_log
end
test "create_chore_log/1 with valid data creates a chore_log" do
valid_attrs = %{chore_id: 42, user_id: 42}
assert {:ok, %ChoreLog{} = chore_log} = Chores.create_chore_log(valid_attrs)
assert chore_log.chore_id == 42
assert chore_log.user_id == 42
end
test "create_chore_log/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Chores.create_chore_log(@invalid_attrs)
end
test "update_chore_log/2 with valid data updates the chore_log" do
chore_log = chore_log_fixture()
update_attrs = %{chore_id: 43, user_id: 43}
assert {:ok, %ChoreLog{} = chore_log} = Chores.update_chore_log(chore_log, update_attrs)
assert chore_log.chore_id == 43
assert chore_log.user_id == 43
end
test "update_chore_log/2 with invalid data returns error changeset" do
chore_log = chore_log_fixture()
assert {:error, %Ecto.Changeset{}} = Chores.update_chore_log(chore_log, @invalid_attrs)
assert chore_log == Chores.get_chore_log!(chore_log.id)
end
test "delete_chore_log/1 deletes the chore_log" do
chore_log = chore_log_fixture()
assert {:ok, %ChoreLog{}} = Chores.delete_chore_log(chore_log)
assert_raise Ecto.NoResultsError, fn -> Chores.get_chore_log!(chore_log.id) end
end
test "change_chore_log/1 returns a chore_log changeset" do
chore_log = chore_log_fixture()
assert %Ecto.Changeset{} = Chores.change_chore_log(chore_log)
end
end
describe "chore_assignees" do
alias ChoreTracker.Chores.ChoreAssignee
import ChoreTracker.ChoresFixtures
@invalid_attrs %{chore_id: nil, user_id: nil}
test "list_chore_assignees/0 returns all chore_assignees" do
chore_assignee = chore_assignee_fixture()
assert Chores.list_chore_assignees() == [chore_assignee]
end
test "get_chore_assignee!/1 returns the chore_assignee with given id" do
chore_assignee = chore_assignee_fixture()
assert Chores.get_chore_assignee!(chore_assignee.id) == chore_assignee
end
test "create_chore_assignee/1 with valid data creates a chore_assignee" do
valid_attrs = %{chore_id: 42, user_id: 42}
assert {:ok, %ChoreAssignee{} = chore_assignee} = Chores.create_chore_assignee(valid_attrs)
assert chore_assignee.chore_id == 42
assert chore_assignee.user_id == 42
end
test "create_chore_assignee/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Chores.create_chore_assignee(@invalid_attrs)
end
test "update_chore_assignee/2 with valid data updates the chore_assignee" do
chore_assignee = chore_assignee_fixture()
update_attrs = %{chore_id: 43, user_id: 43}
assert {:ok, %ChoreAssignee{} = chore_assignee} = Chores.update_chore_assignee(chore_assignee, update_attrs)
assert chore_assignee.chore_id == 43
assert chore_assignee.user_id == 43
end
test "update_chore_assignee/2 with invalid data returns error changeset" do
chore_assignee = chore_assignee_fixture()
assert {:error, %Ecto.Changeset{}} = Chores.update_chore_assignee(chore_assignee, @invalid_attrs)
assert chore_assignee == Chores.get_chore_assignee!(chore_assignee.id)
end
test "delete_chore_assignee/1 deletes the chore_assignee" do
chore_assignee = chore_assignee_fixture()
assert {:ok, %ChoreAssignee{}} = Chores.delete_chore_assignee(chore_assignee)
assert_raise Ecto.NoResultsError, fn -> Chores.get_chore_assignee!(chore_assignee.id) end
end
test "change_chore_assignee/1 returns a chore_assignee changeset" do
chore_assignee = chore_assignee_fixture()
assert %Ecto.Changeset{} = Chores.change_chore_assignee(chore_assignee)
end
end
end