Refactor the Book generator to add authors and a related book to opts.
This commit is contained in:
@@ -56,11 +56,16 @@ defmodule DecentralisedBookIndex.Generators do
|
||||
generate(user())
|
||||
end)
|
||||
|
||||
count =
|
||||
opts[:count] || 2
|
||||
authors =
|
||||
opts[:authors] ||
|
||||
for id <- 1..2 do
|
||||
generate(author(actor: actor)) #.id
|
||||
end
|
||||
|
||||
for order <- 1..count do
|
||||
%{order: order, author_id: generate(author(actor: actor)).id, role: ""}
|
||||
count = min(opts[:count], length(authors))
|
||||
|
||||
for {order, author} <- Enum.zip(1..count, authors) do
|
||||
%{order: order, author_id: author.id, role: ""}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,10 +133,12 @@ defmodule DecentralisedBookIndex.Generators do
|
||||
bids()
|
||||
end)
|
||||
|
||||
authors = opts[:authors] || nil
|
||||
|
||||
author_roles =
|
||||
opts[:author_roles] ||
|
||||
once(:default_author_roles, fn ->
|
||||
author_roles()
|
||||
author_roles(authors: authors)
|
||||
end)
|
||||
|
||||
publisher_id =
|
||||
@@ -140,6 +147,15 @@ defmodule DecentralisedBookIndex.Generators do
|
||||
generate(publisher()).id
|
||||
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(
|
||||
Metadata.Book,
|
||||
:create,
|
||||
@@ -153,7 +169,7 @@ defmodule DecentralisedBookIndex.Generators do
|
||||
bids: bids,
|
||||
author_roles: author_roles,
|
||||
publisher_id: publisher_id,
|
||||
book_editions_registry_id: nil,
|
||||
book_editions_registry_id: book_editions_registry_id,
|
||||
],
|
||||
overrides: opts,
|
||||
actor: actor
|
||||
|
||||
Reference in New Issue
Block a user