Update the action to get the author's books including aliases.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 4 months ago
parent d6eef962de
commit 9f15260275

@ -83,8 +83,10 @@ defmodule DecentralisedBookIndex.Metadata.Book do
prepare fn query, context -> prepare fn query, context ->
author = query.arguments.author author = query.arguments.author
{:ok, author_ids} = Metadata.get_author_ids(author)
Metadata.Book Metadata.Book
|> Ash.Query.filter(expr(exists(author_roles, author_id == ^author.id))) |> Ash.Query.filter(expr(exists(author_roles, author_id in ^author_ids)))
end end
end end
end end

@ -72,5 +72,39 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
assert {:ok, books} = Metadata.get_author_books(author) assert {:ok, books} = Metadata.get_author_books(author)
end end
test "get the list contains aliases' books" do
{:ok, author} = Metadata.create_author("Author", "An description")
{:ok, alias1} =
Metadata.add_author_to_related_alias_registry("Author2", "An description2", author.id)
{:ok, alias2} =
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id)
author_roles = [
%{order: 1, author_id: author.id, role: ""}
]
{:ok, book} = Metadata.create_book("Book", "1234567890", "An description", author_roles)
author_roles = [
%{order: 1, author_id: alias1.id, role: ""}
]
{:ok, book2} = Metadata.create_book("Book2", "1234567890", "An description", author_roles)
author_roles = [
%{order: 1, author_id: alias2.id, role: ""}
]
{:ok, book3} = Metadata.create_book("Book3", "1234567890", "An description", author_roles)
assert {:ok, books} = Metadata.get_author_books(author)
book_ids = Enum.map(books, & &1.id)
assert book.id in book_ids
assert book2.id in book_ids
assert book3.id in book_ids
end
end end
end end

Loading…
Cancel
Save