diff --git a/test/decentralised_book_index/metadata/book_test.exs b/test/decentralised_book_index/metadata/book_test.exs index 7f99ed2..7960f94 100644 --- a/test/decentralised_book_index/metadata/book_test.exs +++ b/test/decentralised_book_index/metadata/book_test.exs @@ -5,43 +5,79 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do 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") + {:ok, author} = Metadata.create_author("Author", "An description") + + author_roles = [ + %{order: 1, author_id: author.id, role: ""} + ] + + 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: ""} + ] + assert {:ok, registry} = Metadata.create_book_editions_registry() - assert {:ok, book} = Metadata.create_book("Book", "1234567890", "An description", registry.id) + 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 - {:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description") + {:ok, author} = Metadata.create_author("Author", "An description") + + author_roles = [ + %{order: 1, author_id: author.id, role: ""} + ] + + {: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", related_book.id) + 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 + {:ok, author} = Metadata.create_author("Author", "An description") + + author_roles = [ + %{order: 1, author_id: author.id, role: ""} + ] + assert {:error, _} = - Metadata.add_book_to_related_editions_registry("Book2", "1234567891", "An description2", nil) + 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 - {:ok, book} = Metadata.create_book("Book", "1234567890", "An description") + {:ok, author} = Metadata.create_author("Author", "An description") + + author_roles = [ + %{order: 1, author_id: author.id, role: ""} + ] + + {: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 - {:ok, related_book} = Metadata.create_book("Book", "1234567890", "An description") + {:ok, author} = Metadata.create_author("Author", "An description") + + author_roles = [ + %{order: 1, author_id: author.id, role: ""} + ] + + {: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", related_book.id) + 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]