Refactor the Book generator to add authors and a related book to opts.
This commit is contained in:
@@ -94,29 +94,9 @@ defmodule DecentralisedBookIndex.Metadata.BookTest do
|
|||||||
{:ok, alias2} =
|
{: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)
|
||||||
|
|
||||||
author_roles = [
|
book = generate(book(authors: [author]))
|
||||||
%{order: 1, author_id: author.id, role: ""}
|
book2 = generate(book(authors: [alias1]))
|
||||||
]
|
book3 = generate(book(authors: [alias2]))
|
||||||
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)
|
|
||||||
|
|
||||||
author_roles2 = [
|
|
||||||
%{order: 1, author_id: alias1.id, role: ""}
|
|
||||||
]
|
|
||||||
bids2 = bids()
|
|
||||||
publisher2 = generate(publisher())
|
|
||||||
|
|
||||||
{:ok, book2} = Metadata.create_book("Book2", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids2, author_roles2, publisher2.id)
|
|
||||||
|
|
||||||
author_roles3 = [
|
|
||||||
%{order: 1, author_id: alias2.id, role: ""}
|
|
||||||
]
|
|
||||||
bids3 = bids()
|
|
||||||
publisher3 = generate(publisher())
|
|
||||||
|
|
||||||
{:ok, book3} = Metadata.create_book("Book3", "An description", "English", "Paperback", 256, ~D[2025-03-04], bids3, author_roles3, publisher3.id)
|
|
||||||
|
|
||||||
assert {:ok, books} = Metadata.get_author_books(author)
|
assert {:ok, books} = Metadata.get_author_books(author)
|
||||||
|
|
||||||
|
|||||||
@@ -56,11 +56,16 @@ defmodule DecentralisedBookIndex.Generators do
|
|||||||
generate(user())
|
generate(user())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
count =
|
authors =
|
||||||
opts[:count] || 2
|
opts[:authors] ||
|
||||||
|
for id <- 1..2 do
|
||||||
|
generate(author(actor: actor)) #.id
|
||||||
|
end
|
||||||
|
|
||||||
for order <- 1..count do
|
count = min(opts[:count], length(authors))
|
||||||
%{order: order, author_id: generate(author(actor: actor)).id, role: ""}
|
|
||||||
|
for {order, author} <- Enum.zip(1..count, authors) do
|
||||||
|
%{order: order, author_id: author.id, role: ""}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -128,10 +133,12 @@ defmodule DecentralisedBookIndex.Generators do
|
|||||||
bids()
|
bids()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
authors = opts[:authors] || nil
|
||||||
|
|
||||||
author_roles =
|
author_roles =
|
||||||
opts[:author_roles] ||
|
opts[:author_roles] ||
|
||||||
once(:default_author_roles, fn ->
|
once(:default_author_roles, fn ->
|
||||||
author_roles()
|
author_roles(authors: authors)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
publisher_id =
|
publisher_id =
|
||||||
@@ -140,6 +147,15 @@ defmodule DecentralisedBookIndex.Generators do
|
|||||||
generate(publisher()).id
|
generate(publisher()).id
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
related_book = opts[:related_book] || nil
|
||||||
|
|
||||||
|
book_editions_registry_id =
|
||||||
|
if related_book do
|
||||||
|
related_book.book_editions_registry_id
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
changeset_generator(
|
changeset_generator(
|
||||||
Metadata.Book,
|
Metadata.Book,
|
||||||
:create,
|
:create,
|
||||||
@@ -153,7 +169,7 @@ defmodule DecentralisedBookIndex.Generators do
|
|||||||
bids: bids,
|
bids: bids,
|
||||||
author_roles: author_roles,
|
author_roles: author_roles,
|
||||||
publisher_id: publisher_id,
|
publisher_id: publisher_id,
|
||||||
book_editions_registry_id: nil,
|
book_editions_registry_id: book_editions_registry_id,
|
||||||
],
|
],
|
||||||
overrides: opts,
|
overrides: opts,
|
||||||
actor: actor
|
actor: actor
|
||||||
|
|||||||
Reference in New Issue
Block a user