You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

defmodule DecentralisedBookIndex.Metadata.BookTest do
use DecentralisedBookIndex.DataCase, async: true
alias DecentralisedBookIndex.Metadata
describe "books and registries relationship" do
test "a new book get new registry by default" do
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
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)
assert book.book_editions_registry_id == registry.id
end
test "a new book to a registry via a related book record" do
author_roles = author_roles()
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
assert {:ok, book} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", author_roles, related_book.id)
assert related_book.book_editions_registry_id == book.book_editions_registry_id
end
test "a new book to a registry via a empty related book record" do
author_roles = author_roles()
assert {:error, _} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", author_roles, nil)
end
end
describe "books alternatives names" do
test "new book has no alternatives names" do
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)
assert alternatives_names = []
end
test "book has related book so they has one alternative name" do
author_roles = author_roles()
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
{:ok, book} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", author_roles, related_book.id)
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
assert alternatives_names = [related_book]
end
end
end