Add tests for the Book and Author forms.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
5f786cfb4b
commit
e98a98b2c1
@ -0,0 +1,43 @@
|
|||||||
|
defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
||||||
|
use DecentralisedBookIndex.DataCase, async: true
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
|
||||||
|
describe "create new author via the form" do
|
||||||
|
test "just name and description" do
|
||||||
|
user = generate(user())
|
||||||
|
valid_params = %{
|
||||||
|
"name" => "Oleh",
|
||||||
|
"description" => "A cool author",
|
||||||
|
}
|
||||||
|
|
||||||
|
form = \
|
||||||
|
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||||
|
as: "author",
|
||||||
|
actor: user
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update existing author via the form" do
|
||||||
|
test "update author's name" do
|
||||||
|
user = generate(user())
|
||||||
|
author = generate(author())
|
||||||
|
|
||||||
|
valid_params = %{
|
||||||
|
"name" => "Another Oleh",
|
||||||
|
"description" => "A cool author",
|
||||||
|
}
|
||||||
|
|
||||||
|
form =
|
||||||
|
AshPhoenix.Form.for_update(author, :update,
|
||||||
|
as: "author",
|
||||||
|
actor: user
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,72 @@
|
|||||||
|
defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
||||||
|
use DecentralisedBookIndex.DataCase, async: true
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
|
||||||
|
describe "create new book via the form" do
|
||||||
|
test "just name and description" do
|
||||||
|
user = generate(user())
|
||||||
|
bids = bids(actor: user)
|
||||||
|
author_roles = author_roles(actor: user)
|
||||||
|
|
||||||
|
valid_params = %{
|
||||||
|
"title" => "Book",
|
||||||
|
"description" => "A cool author",
|
||||||
|
"format" => "Paper",
|
||||||
|
"language" => "English",
|
||||||
|
"page_count" => 600,
|
||||||
|
"published" => ~D[2025-03-06],
|
||||||
|
"author_roles" => author_roles,
|
||||||
|
"bids" => bids
|
||||||
|
}
|
||||||
|
|
||||||
|
form = \
|
||||||
|
AshPhoenix.Form.for_create(Metadata.Book, :create,
|
||||||
|
as: "book",
|
||||||
|
actor: user
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update existing book via the form" do
|
||||||
|
test "update name" do
|
||||||
|
user = generate(user())
|
||||||
|
book = generate(book())
|
||||||
|
|
||||||
|
valid_params = %{
|
||||||
|
"title" => "Another Book",
|
||||||
|
"description" => "A cool book",
|
||||||
|
}
|
||||||
|
|
||||||
|
form =
|
||||||
|
AshPhoenix.Form.for_update(book, :update,
|
||||||
|
as: "book",
|
||||||
|
actor: user
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update bids and authors" do
|
||||||
|
user = generate(user())
|
||||||
|
book = generate(book())
|
||||||
|
bids = bids(actor: user)
|
||||||
|
author_roles = author_roles(actor: user)
|
||||||
|
|
||||||
|
valid_params = %{
|
||||||
|
"author_roles" => author_roles,
|
||||||
|
"bids" => bids
|
||||||
|
}
|
||||||
|
|
||||||
|
form =
|
||||||
|
AshPhoenix.Form.for_update(book, :update,
|
||||||
|
as: "book",
|
||||||
|
actor: user
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue