|
|
@ -3,45 +3,50 @@ defmodule DecentralisedBookIndex.Metadata.AuthorTest do
|
|
|
|
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setup do
|
|
|
|
|
|
|
|
user = generate(user(role: :moderator))
|
|
|
|
|
|
|
|
%{user: user}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "authors and registries relationship" do
|
|
|
|
describe "authors and registries relationship" do
|
|
|
|
test "a new author get new registry by default" do
|
|
|
|
test "a new author get new registry by default", %{user: user} do
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
assert author.author_alias_registry_id != nil
|
|
|
|
assert author.author_alias_registry_id != nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "a new author belongs to a registry if specified" do
|
|
|
|
test "a new author belongs to a registry if specified", %{user: user} do
|
|
|
|
assert {:ok, registry} = Metadata.create_author_alias_registry()
|
|
|
|
assert {:ok, registry} = Metadata.create_author_alias_registry(actor: user)
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", nil, registry.id)
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", nil, registry.id, actor: user)
|
|
|
|
assert author.author_alias_registry_id == registry.id
|
|
|
|
assert author.author_alias_registry_id == registry.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "a new author to a registry via a related author record" do
|
|
|
|
test "a new author to a registry via a related author record", %{user: user} do
|
|
|
|
{:ok, related_author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, related_author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, author} =
|
|
|
|
assert {:ok, author} =
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", related_author.id)
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", related_author.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
assert related_author.author_alias_registry_id == author.author_alias_registry_id
|
|
|
|
assert related_author.author_alias_registry_id == author.author_alias_registry_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "a new author to a registry via a empty related author record" do
|
|
|
|
test "a new author to a registry via a empty related author record", %{user: user} do
|
|
|
|
assert {:error, _} =
|
|
|
|
assert {:error, _} =
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", nil)
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", nil, actor: user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "authors alternatives names" do
|
|
|
|
describe "authors alternatives names" do
|
|
|
|
test "new author has no alternatives names" do
|
|
|
|
test "new author has no alternatives names", %{user: user} do
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
|
|
|
assert alternatives_names = []
|
|
|
|
assert alternatives_names = []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "author has related author so they has one alternative name" do
|
|
|
|
test "author has related author so they has one alternative name", %{user: user} do
|
|
|
|
{:ok, related_author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, related_author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, author} =
|
|
|
|
{:ok, author} =
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", related_author.id)
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", related_author.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_author_alternative_names(author)
|
|
|
|
assert alternatives_names = [related_author]
|
|
|
|
assert alternatives_names = [related_author]
|
|
|
@ -49,19 +54,19 @@ defmodule DecentralisedBookIndex.Metadata.AuthorTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "author's ids" do
|
|
|
|
describe "author's ids" do
|
|
|
|
test "the list has the author's id" do
|
|
|
|
test "the list has the author's id", %{user: user} do
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, ids} = Metadata.get_author_ids(author)
|
|
|
|
assert {:ok, ids} = Metadata.get_author_ids(author, actor: user)
|
|
|
|
assert author.id in ids
|
|
|
|
assert author.id in ids
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "the list has the aliases' ids" do
|
|
|
|
test "the list has the aliases' ids", %{user: user} do
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
{:ok, alias1} =
|
|
|
|
{:ok, alias1} =
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", author.id)
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", author.id, nil, actor: user)
|
|
|
|
{:ok, alias2} =
|
|
|
|
{:ok, alias2} =
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id)
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, ids} = Metadata.get_author_ids(author)
|
|
|
|
assert {:ok, ids} = Metadata.get_author_ids(author)
|
|
|
|
|
|
|
|
|
|
|
@ -72,15 +77,15 @@ defmodule DecentralisedBookIndex.Metadata.AuthorTest do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "authors and avatar_url" do
|
|
|
|
describe "authors and avatar_url" do
|
|
|
|
test "a new author has no avatar by default" do
|
|
|
|
test "a new author has no avatar by default", %{user: user} do
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
assert author.avatar_url == nil
|
|
|
|
assert author.avatar_url == nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "a new author has a avatar" do
|
|
|
|
test "a new author has a avatar", %{user: user} do
|
|
|
|
avatar_url = "/images/avatar.png"
|
|
|
|
avatar_url = "/images/avatar.png"
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", avatar_url)
|
|
|
|
assert {:ok, author} = Metadata.create_author("Author", "An description", avatar_url, nil, actor: user)
|
|
|
|
assert author.avatar_url == avatar_url
|
|
|
|
assert author.avatar_url == avatar_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|