|
|
|
@ -3,40 +3,45 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
|
|
setup do
|
|
|
|
|
user = generate(user(role: :moderator))
|
|
|
|
|
%{user: user}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "books and registries relationship" do
|
|
|
|
|
test "a new book get new registry by default" do
|
|
|
|
|
test "a new book get new registry by default", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id)
|
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, nil, actor: user)
|
|
|
|
|
assert book.book_editions_registry_id != nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "a new book belongs to a registry if specified" do
|
|
|
|
|
test "a new book belongs to a registry if specified", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
assert {:ok, registry} = Metadata.create_book_editions_registry()
|
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description","English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, registry.id)
|
|
|
|
|
assert {:ok, registry} = Metadata.create_book_editions_registry(actor: user)
|
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description","English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, registry.id, actor: user)
|
|
|
|
|
assert book.book_editions_registry_id == registry.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "a new book to a registry via a related book record" do
|
|
|
|
|
test "a new book to a registry via a related book record", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id)
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} =
|
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id)
|
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
test "a new book to a registry via a empty related book record", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
@ -47,25 +52,25 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "books alternatives names" do
|
|
|
|
|
test "new book has no alternatives names" do
|
|
|
|
|
test "new book has no alternatives names", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id)
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, nil, actor: user)
|
|
|
|
|
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
|
|
|
|
|
test "book has related book so they has one alternative name", %{user: user} do
|
|
|
|
|
author_roles = author_roles()
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id)
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
{:ok, book} =
|
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id)
|
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, related_book.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
|
|
|
|
assert alternatives_names = [related_book]
|
|
|
|
@ -73,8 +78,8 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "author's books" do
|
|
|
|
|
test "get the list via author's id" do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
|
test "get the list via author's id", %{user: user} do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
bids = bids()
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
@ -82,17 +87,17 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id)
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids, author_roles, publisher.id, nil, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
assert {:ok, books} = Metadata.get_author_books(author)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "get the list contains aliases' books" do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
|
test "get the list contains aliases' books", %{user: user} do
|
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description", nil, nil, actor: user)
|
|
|
|
|
{:ok, alias1} =
|
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", author.id)
|
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author2", "An description2", author.id, nil, actor: user)
|
|
|
|
|
{:ok, alias2} =
|
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id)
|
|
|
|
|
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id, nil, actor: user)
|
|
|
|
|
|
|
|
|
|
book = generate(book(authors: [author]))
|
|
|
|
|
book2 = generate(book(authors: [alias1]))
|
|
|
|
@ -109,7 +114,7 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "get a book by book id" do
|
|
|
|
|
test "get by bid" do
|
|
|
|
|
test "get by bid", %{user: user} do
|
|
|
|
|
expected_book = generate(book())
|
|
|
|
|
|
|
|
|
|
[%Metadata.BookId{type: type, bid: bid} | _] = expected_book.bids
|
|
|
|
@ -120,12 +125,12 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "book's cover image" do
|
|
|
|
|
test "update cover image" do
|
|
|
|
|
test "update cover image", %{user: user} do
|
|
|
|
|
cover_image_url = "/images/book.avif"
|
|
|
|
|
|
|
|
|
|
book = generate(book())
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} = Metadata.assign_book_cover_image(book, cover_image_url)
|
|
|
|
|
assert {:ok, book} = Metadata.assign_book_cover_image(book, cover_image_url, actor: user)
|
|
|
|
|
assert book.cover_image_url == cover_image_url
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|