Add generators for user, author and author_roles for tests.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed

This commit is contained in:
2025-03-10 21:51:35 +02:00
parent 02d35ee056
commit e3da0dc129
3 changed files with 73 additions and 30 deletions
@@ -5,22 +5,14 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
describe "books and registries relationship" do
test "a new book get new registry by default" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
assert {:ok, book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
assert book.book_editions_registry_id != nil
end
test "a new book belongs to a registry if specified" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
assert {:ok, registry} = Metadata.create_book_editions_registry()
assert {:ok, book} = Metadata.create_book("Book", "1234567890", "An description", author_roles, registry.id)
@@ -28,11 +20,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
end
test "a new book to a registry via a related book record" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
@@ -43,11 +31,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
end
test "a new book to a registry via a empty related book record" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
assert {:error, _} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", author_roles, nil)
@@ -56,11 +40,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
describe "books alternatives names" do
test "new book has no alternatives names" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
{:ok, book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
@@ -68,11 +48,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
end
test "book has related book so they has one alternative name" do
{:ok, author} = Metadata.create_author("Author", "An description")
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
author_roles = author_roles()
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)