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} =
|
||||
Metadata.add_author_to_related_alias_registry("Author3", "An description3", author.id)
|
||||
|
||||
author_roles = [
|
||||
%{order: 1, author_id: author.id, role: ""}
|
||||
]
|
||||
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)
|
||||
book = generate(book(authors: [author]))
|
||||
book2 = generate(book(authors: [alias1]))
|
||||
book3 = generate(book(authors: [alias2]))
|
||||
|
||||
assert {:ok, books} = Metadata.get_author_books(author)
|
||||
|
||||
|
||||
@@ -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