|
|
@ -7,28 +7,31 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
test "a new book get new registry by default" do
|
|
|
|
test "a new book get new registry by default" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
assert book.book_editions_registry_id != nil
|
|
|
|
assert book.book_editions_registry_id != nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
test "a new book belongs to a registry if specified" do
|
|
|
|
test "a new book belongs to a registry if specified" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, registry} = Metadata.create_book_editions_registry()
|
|
|
|
assert {:ok, registry} = Metadata.create_book_editions_registry()
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, registry.id)
|
|
|
|
assert {:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id, registry.id)
|
|
|
|
assert book.book_editions_registry_id == registry.id
|
|
|
|
assert book.book_editions_registry_id == registry.id
|
|
|
|
end
|
|
|
|
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" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} =
|
|
|
|
assert {:ok, book} =
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, related_book.id)
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, related_book.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert related_book.book_editions_registry_id == book.book_editions_registry_id
|
|
|
|
assert related_book.book_editions_registry_id == book.book_editions_registry_id
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -36,9 +39,10 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
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" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
assert {:error, _} =
|
|
|
|
assert {:error, _} =
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, nil)
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -46,8 +50,9 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
test "new book has no alternatives names" do
|
|
|
|
test "new book has no alternatives names" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
|
|
|
assert alternatives_names = []
|
|
|
|
assert alternatives_names = []
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -55,11 +60,12 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
test "book has related book so they has one alternative name" do
|
|
|
|
test "book has related book so they has one alternative name" do
|
|
|
|
author_roles = author_roles()
|
|
|
|
author_roles = author_roles()
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
{:ok, related_book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book} =
|
|
|
|
{:ok, book} =
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, related_book.id)
|
|
|
|
Metadata.add_book_to_related_editions_registry("Book2", "An description2", bids, author_roles, publisher.id, related_book.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
|
|
|
assert {:ok, alternatives_names} = Metadata.get_book_alternative_editions(book)
|
|
|
|
assert alternatives_names = [related_book]
|
|
|
|
assert alternatives_names = [related_book]
|
|
|
@ -70,12 +76,13 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
test "get the list via author's id" do
|
|
|
|
test "get the list via author's id" do
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
author_roles = [
|
|
|
|
author_roles = [
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, books} = Metadata.get_author_books(author)
|
|
|
|
assert {:ok, books} = Metadata.get_author_books(author)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -91,22 +98,25 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
bids = bids()
|
|
|
|
bids = bids()
|
|
|
|
|
|
|
|
publisher = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
{:ok, book} = Metadata.create_book("Book", "An description", bids, author_roles, publisher.id)
|
|
|
|
|
|
|
|
|
|
|
|
author_roles = [
|
|
|
|
author_roles = [
|
|
|
|
%{order: 1, author_id: alias1.id, role: ""}
|
|
|
|
%{order: 1, author_id: alias1.id, role: ""}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
bids2 = bids()
|
|
|
|
bids2 = bids()
|
|
|
|
|
|
|
|
publisher2 = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book2} = Metadata.create_book("Book2", "An description", bids, author_roles)
|
|
|
|
{:ok, book2} = Metadata.create_book("Book2", "An description", bids, author_roles, publisher2.id)
|
|
|
|
|
|
|
|
|
|
|
|
author_roles = [
|
|
|
|
author_roles = [
|
|
|
|
%{order: 1, author_id: alias2.id, role: ""}
|
|
|
|
%{order: 1, author_id: alias2.id, role: ""}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
bids3 = bids()
|
|
|
|
bids3 = bids()
|
|
|
|
|
|
|
|
publisher3 = generate(publisher())
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, book3} = Metadata.create_book("Book3", "An description", bids, author_roles)
|
|
|
|
{:ok, book3} = Metadata.create_book("Book3", "An description", bids, author_roles, publisher3.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, books} = Metadata.get_author_books(author)
|
|
|
|
assert {:ok, books} = Metadata.get_author_books(author)
|
|
|
|
|
|
|
|
|
|
|
@ -120,20 +130,9 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|
|
|
|
|
|
|
|
|
|
|
describe "get a book by book id" do
|
|
|
|
describe "get a book by book id" do
|
|
|
|
test "get by bid" do
|
|
|
|
test "get by bid" do
|
|
|
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
|
|
|
expected_book = generate(book())
|
|
|
|
|
|
|
|
|
|
|
|
type = "isbn10"
|
|
|
|
|
|
|
|
bid = "1234567890"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bids = [
|
|
|
|
|
|
|
|
%{order: 1, type: type, bid: bid}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
author_roles = [
|
|
|
|
|
|
|
|
%{order: 1, author_id: author.id, role: ""}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, expected_book} = Metadata.create_book("Book", "An description", bids, author_roles)
|
|
|
|
[%Metadata.BookId{type: type, bid: bid} | _] = expected_book.bids
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, book} = Metadata.get_book_by_bid(type, bid)
|
|
|
|
assert {:ok, book} = Metadata.get_book_by_bid(type, bid)
|
|
|
|
assert expected_book.id == book.id
|
|
|
|
assert expected_book.id == book.id
|
|
|
|