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