Add actions to support books' editions.

This commit is contained in:
2025-03-08 22:07:09 +02:00
parent a7c6d6770c
commit 74f4e99957
3 changed files with 130 additions and 3 deletions
@@ -0,0 +1,50 @@
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
assert {:ok, book} = Metadata.create_book("Book", "1234567890", "An description")
assert book.book_editions_registry_id != nil
end
test "a new book belongs to a registry if specified" do
assert {:ok, registry} = Metadata.create_book_editions_registry()
assert {:ok, book} = Metadata.create_book("Book", "1234567890", "An description", registry.id)
assert book.book_editions_registry_id == registry.id
end
test "a new book to a registry via a related book record" do
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description")
assert {:ok, book} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", 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
assert {:error, _} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", nil)
end
end
describe "books alternatives names" do
test "new book has no alternatives names" do
{:ok, book} = Metadata.create_book("Book", "1234567890", "An description")
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
{:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description")
{:ok, book} =
Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", related_book.id)
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
assert alternatives_names = [related_book]
end
end
end