pass tags test
This commit is contained in:
parent
3c8851616a
commit
c1b04bd14c
@ -1,83 +1,75 @@
|
|||||||
defmodule Cannery.TagsTest do
|
defmodule Cannery.TagsTest do
|
||||||
use Cannery.DataCase
|
@moduledoc """
|
||||||
|
Tests the Tags context
|
||||||
|
"""
|
||||||
|
|
||||||
alias Cannery.{AccountsFixtures, Tags}
|
use Cannery.DataCase
|
||||||
|
alias Cannery.{Tags, Tags.Tag}
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
|
|
||||||
|
@moduletag :tags_test
|
||||||
|
|
||||||
|
@valid_attrs %{
|
||||||
|
"bg_color" => "some bg-color",
|
||||||
|
"name" => "some name",
|
||||||
|
"text_color" => "some text-color"
|
||||||
|
}
|
||||||
|
@update_attrs %{
|
||||||
|
"bg_color" => "some updated bg-color",
|
||||||
|
"name" => "some updated name",
|
||||||
|
"text_color" => "some updated text-color"
|
||||||
|
}
|
||||||
|
@invalid_attrs %{
|
||||||
|
"bg_color" => nil,
|
||||||
|
"name" => nil,
|
||||||
|
"text_color" => nil
|
||||||
|
}
|
||||||
|
|
||||||
describe "tags" do
|
describe "tags" do
|
||||||
alias Cannery.Tags.Tag
|
setup do
|
||||||
|
current_user = user_fixture()
|
||||||
@valid_attrs %{
|
[tag: tag_fixture(current_user), current_user: current_user]
|
||||||
"bg_color" => "some bg-color",
|
|
||||||
"name" => "some name",
|
|
||||||
"text_color" => "some text-color"
|
|
||||||
}
|
|
||||||
@update_attrs %{
|
|
||||||
"bg_color" => "some updated bg-color",
|
|
||||||
"name" => "some updated name",
|
|
||||||
"text_color" => "some updated text-color"
|
|
||||||
}
|
|
||||||
@invalid_attrs %{
|
|
||||||
"bg_color" => nil,
|
|
||||||
"name" => nil,
|
|
||||||
"text_color" => nil
|
|
||||||
}
|
|
||||||
|
|
||||||
def tag_fixture(attrs \\ %{}) do
|
|
||||||
%{id: user_id} = AccountsFixtures.user_fixture()
|
|
||||||
|
|
||||||
{:ok, tag} =
|
|
||||||
attrs
|
|
||||||
|> Map.put("user_id", user_id)
|
|
||||||
|> Enum.into(@valid_attrs)
|
|
||||||
|> Tags.create_tag()
|
|
||||||
|
|
||||||
tag
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "list_tags/0 returns all tags" do
|
test "list_tags/0 returns all tags", %{tag: tag, current_user: current_user} do
|
||||||
tag = tag_fixture()
|
assert Tags.list_tags(current_user) == [tag]
|
||||||
assert Tags.list_tags() == [tag]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get_tag!/1 returns the tag with given id" do
|
test "get_tag!/1 returns the tag with given id", %{tag: tag, current_user: current_user} do
|
||||||
tag = tag_fixture()
|
assert Tags.get_tag!(tag.id, current_user) == tag
|
||||||
assert Tags.get_tag!(tag.id) == tag
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_tag/1 with valid data creates a tag" do
|
test "create_tag/1 with valid data creates a tag", %{tag: tag, current_user: current_user} do
|
||||||
assert {:ok, %Tag{} = tag} = Tags.create_tag(@valid_attrs)
|
assert {:ok, %Tag{} = tag} = Tags.create_tag(@valid_attrs, current_user)
|
||||||
assert tag.bg_color == "some bg-color"
|
assert tag.bg_color == "some bg-color"
|
||||||
assert tag.name == "some name"
|
assert tag.name == "some name"
|
||||||
assert tag.text_color == "some text-color"
|
assert tag.text_color == "some text-color"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create_tag/1 with invalid data returns error changeset" do
|
test "create_tag/1 with invalid data returns error changeset",
|
||||||
assert {:error, %Changeset{}} = Tags.create_tag(@invalid_attrs)
|
%{current_user: current_user} do
|
||||||
|
assert {:error, %Changeset{}} = Tags.create_tag(@invalid_attrs, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_tag/2 with valid data updates the tag" do
|
test "update_tag/2 with valid data updates the tag", %{tag: tag, current_user: current_user} do
|
||||||
tag = tag_fixture()
|
assert {:ok, %Tag{} = tag} = Tags.update_tag(tag, @update_attrs, current_user)
|
||||||
assert {:ok, %Tag{} = tag} = Tags.update_tag(tag, @update_attrs)
|
|
||||||
assert tag.bg_color == "some updated bg-color"
|
assert tag.bg_color == "some updated bg-color"
|
||||||
assert tag.name == "some updated name"
|
assert tag.name == "some updated name"
|
||||||
assert tag.text_color == "some updated text-color"
|
assert tag.text_color == "some updated text-color"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update_tag/2 with invalid data returns error changeset" do
|
test "update_tag/2 with invalid data returns error changeset",
|
||||||
tag = tag_fixture()
|
%{tag: tag, current_user: current_user} do
|
||||||
assert {:error, %Changeset{}} = Tags.update_tag(tag, @invalid_attrs)
|
assert {:error, %Changeset{}} = Tags.update_tag(tag, @invalid_attrs, current_user)
|
||||||
assert tag == Tags.get_tag!(tag.id)
|
assert tag == Tags.get_tag!(tag.id, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_tag/1 deletes the tag" do
|
test "delete_tag/1 deletes the tag", %{tag: tag, current_user: current_user} do
|
||||||
tag = tag_fixture()
|
assert {:ok, %Tag{}} = Tags.delete_tag(tag, current_user)
|
||||||
assert {:ok, %Tag{}} = Tags.delete_tag(tag)
|
assert_raise Ecto.NoResultsError, fn -> Tags.get_tag!(tag.id, current_user) end
|
||||||
assert_raise Ecto.NoResultsError, fn -> Tags.get_tag!(tag.id) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "change_tag/1 returns a tag changeset" do
|
test "change_tag/1 returns a tag changeset", %{tag: tag} do
|
||||||
tag = tag_fixture()
|
|
||||||
assert %Changeset{} = Tags.change_tag(tag)
|
assert %Changeset{} = Tags.change_tag(tag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user