basic admin endgame view and add (#3)
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
defmodule Chesstrainer.TagsTest do
|
||||
use Chesstrainer.DataCase
|
||||
|
||||
alias Chesstrainer.Tags
|
||||
|
||||
describe "tags" do
|
||||
alias Chesstrainer.Tags.Tag
|
||||
|
||||
import Chesstrainer.TagsFixtures
|
||||
|
||||
@invalid_attrs %{name: nil, category: nil}
|
||||
|
||||
test "list_tags/0 returns all tags" do
|
||||
tag = tag_fixture()
|
||||
assert Tags.list_tags() == [tag]
|
||||
end
|
||||
|
||||
test "get_tag!/1 returns the tag with given id" do
|
||||
tag = tag_fixture()
|
||||
assert Tags.get_tag!(tag.id) == tag
|
||||
end
|
||||
|
||||
test "create_tag/1 with valid data creates a tag" do
|
||||
valid_attrs = %{name: "some name", category: "some category"}
|
||||
|
||||
assert {:ok, %Tag{} = tag} = Tags.create_tag(valid_attrs)
|
||||
assert tag.name == "some name"
|
||||
assert tag.category == "some category"
|
||||
end
|
||||
|
||||
test "create_tag/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Tags.create_tag(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_tag/2 with valid data updates the tag" do
|
||||
tag = tag_fixture()
|
||||
update_attrs = %{name: "some updated name", category: "some updated category"}
|
||||
|
||||
assert {:ok, %Tag{} = tag} = Tags.update_tag(tag, update_attrs)
|
||||
assert tag.name == "some updated name"
|
||||
assert tag.category == "some updated category"
|
||||
end
|
||||
|
||||
test "update_tag/2 with invalid data returns error changeset" do
|
||||
tag = tag_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Tags.update_tag(tag, @invalid_attrs)
|
||||
assert tag == Tags.get_tag!(tag.id)
|
||||
end
|
||||
|
||||
test "delete_tag/1 deletes the tag" do
|
||||
tag = tag_fixture()
|
||||
assert {:ok, %Tag{}} = Tags.delete_tag(tag)
|
||||
assert_raise Ecto.NoResultsError, fn -> Tags.get_tag!(tag.id) end
|
||||
end
|
||||
|
||||
test "change_tag/1 returns a tag changeset" do
|
||||
tag = tag_fixture()
|
||||
assert %Ecto.Changeset{} = Tags.change_tag(tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
defmodule Chesstrainer.TagsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Chesstrainer.Tags` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a unique tag name.
|
||||
"""
|
||||
def unique_tag_name, do: "some name#{System.unique_integer([:positive])}"
|
||||
|
||||
@doc """
|
||||
Generate a tag.
|
||||
"""
|
||||
def tag_fixture(attrs \\ %{}) do
|
||||
{:ok, tag} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
category: "some category",
|
||||
name: unique_tag_name()
|
||||
})
|
||||
|> Chesstrainer.Tags.create_tag()
|
||||
|
||||
tag
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user