|
|
@ -1,7 +1,10 @@
|
|
|
|
defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|
|
|
defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|
|
|
use DecentralisedBookIndex.DataCase, async: true
|
|
|
|
use DecentralisedBookIndex.DataCase, async: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ExUnitProperties
|
|
|
|
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata.Book
|
|
|
|
|
|
|
|
|
|
|
|
describe "create new book via the form" do
|
|
|
|
describe "create new book via the form" do
|
|
|
|
test "just name and description" do
|
|
|
|
test "just name and description" do
|
|
|
@ -69,4 +72,52 @@ defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
|
|
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
|
|
|
assert {:ok, user} = AshPhoenix.Form.submit(form, params: valid_params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "validation" do
|
|
|
|
|
|
|
|
property "the book form is valid if the page count > 0" do
|
|
|
|
|
|
|
|
user = generate(user())
|
|
|
|
|
|
|
|
book = generate(book())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
valid_count_generator =
|
|
|
|
|
|
|
|
StreamData.integer()
|
|
|
|
|
|
|
|
|> StreamData.map(fn n -> abs(n)+1 end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check all(page_count <- valid_count_generator) do
|
|
|
|
|
|
|
|
valid_params = %{
|
|
|
|
|
|
|
|
"page_count" => page_count,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form =
|
|
|
|
|
|
|
|
AshPhoenix.Form.for_update(book, :update,
|
|
|
|
|
|
|
|
as: "book",
|
|
|
|
|
|
|
|
actor: user
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, _book} = AshPhoenix.Form.submit(form, params: valid_params)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
property "the book form is invalid if the page count <= 0" do
|
|
|
|
|
|
|
|
user = generate(user())
|
|
|
|
|
|
|
|
book = generate(book())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalid_count_generator =
|
|
|
|
|
|
|
|
StreamData.integer()
|
|
|
|
|
|
|
|
|> StreamData.map(fn n -> -abs(n) end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check all(page_count <- invalid_count_generator) do
|
|
|
|
|
|
|
|
invalid_params = %{
|
|
|
|
|
|
|
|
"page_count" => page_count,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form =
|
|
|
|
|
|
|
|
AshPhoenix.Form.for_update(book, :update,
|
|
|
|
|
|
|
|
as: "book",
|
|
|
|
|
|
|
|
actor: user
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert {:error, _error} = AshPhoenix.Form.submit(form, params: invalid_params)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|