Update Author resource and test for the form.
This commit is contained in:
@@ -3,27 +3,65 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
||||
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
|
||||
describe "create new author via the form" do
|
||||
test "just name and description" do
|
||||
setup do
|
||||
user = generate(user(role: :moderator))
|
||||
%{user: user}
|
||||
end
|
||||
|
||||
describe "form submiting" do
|
||||
test "user can't submit" do
|
||||
user = generate(user())
|
||||
|
||||
valid_params = %{
|
||||
"name" => "Oleh",
|
||||
"description" => "A cool author",
|
||||
}
|
||||
|
||||
|
||||
assert_raise Ash.Error.Forbidden, fn ->
|
||||
form = \
|
||||
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||
as: "author",
|
||||
actor: user
|
||||
)
|
||||
|> AshPhoenix.Form.ensure_can_submit!()
|
||||
end
|
||||
end
|
||||
|
||||
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||
test "moderator can submit", %{user: user} do
|
||||
valid_params = %{
|
||||
"name" => "Oleh",
|
||||
"description" => "A cool author",
|
||||
}
|
||||
|
||||
assert form =
|
||||
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||
as: "author",
|
||||
actor: user
|
||||
)
|
||||
|> AshPhoenix.Form.ensure_can_submit!()
|
||||
end
|
||||
end
|
||||
|
||||
describe "create new author via the form" do
|
||||
test "just name and description", %{user: user} do
|
||||
valid_params = %{
|
||||
"name" => "Oleh",
|
||||
"description" => "A cool author",
|
||||
}
|
||||
|
||||
form =
|
||||
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
||||
as: "author",
|
||||
actor: user
|
||||
)
|
||||
|
||||
assert {:ok, author} = 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())
|
||||
test "update author's name", %{user: user} do
|
||||
author = generate(author())
|
||||
|
||||
valid_params = %{
|
||||
@@ -37,7 +75,7 @@ defmodule DecentralisedBookIndex.Metadata.Forms.AuthorFormTest do
|
||||
actor: user
|
||||
)
|
||||
|
||||
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||
assert {:ok, author} = AshPhoenix.Form.submit(form, params: valid_params)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user