|
|
|
@ -3,11 +3,16 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRolesTest do
|
|
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
|
|
setup do
|
|
|
|
|
user = generate(user(role: :moderator))
|
|
|
|
|
%{user: user}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "create action" do
|
|
|
|
|
test "an author's role must belongs to an author" do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
|
test "an author's role must belongs to an author", %{user: user} do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
assert {:ok, author_role} = Metadata.create_author_role(author.id, 1, "role")
|
|
|
|
|
assert {:ok, author_role} = Metadata.create_author_role(author.id, 1, "role", actor: user)
|
|
|
|
|
|
|
|
|
|
{:ok, author_role} =
|
|
|
|
|
author_role
|
|
|
|
@ -16,22 +21,22 @@ defmodule DecentralisedBookIndex.Metadata.AuthorRolesTest do
|
|
|
|
|
assert author.id == author_role.author_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "an author's role can be blank" do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
|
test "an author's role can be blank", %{user: user} do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
{:ok, author_role} = Metadata.create_author_role(author.id, 1, "")
|
|
|
|
|
{:ok, author_role} = Metadata.create_author_role(author.id, 1, "", actor: user)
|
|
|
|
|
|
|
|
|
|
refute author_role.role
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "author's avatar image" do
|
|
|
|
|
test "update avatar image" do
|
|
|
|
|
test "update avatar image", %{user: user} do
|
|
|
|
|
avatar_url = "/images/avatar.avif"
|
|
|
|
|
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
assert {:ok, author} = Metadata.assign_author_avatar_image(author, avatar_url)
|
|
|
|
|
assert {:ok, author} = Metadata.assign_author_avatar_image(author, avatar_url, actor: user)
|
|
|
|
|
|
|
|
|
|
assert author.avatar_url == avatar_url
|
|
|
|
|
end
|
|
|
|
|