Add the validation for Book's page count to be greater than 0.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
defmodule DecentralisedBookIndex.Metadata.Forms.BookFormTest do
|
||||
use DecentralisedBookIndex.DataCase, async: true
|
||||
|
||||
import ExUnitProperties
|
||||
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
alias DecentralisedBookIndex.Metadata.Book
|
||||
|
||||
describe "create new book via the form" 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)
|
||||
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
|
||||
|
||||
@@ -189,7 +189,7 @@ defmodule DecentralisedBookIndex.Generators do
|
||||
description: sequence(:description, &"Description #{&1}"),
|
||||
language: sequence(:language, &"Language #{&1}"),
|
||||
format: sequence(:format, &"Format #{&1}"),
|
||||
page_count: sequence(:page_count, & &1),
|
||||
page_count: sequence(:page_count, &(abs(&1)+1)),
|
||||
published: sequence(:published, &Date.add(~D[2025-03-04], &1)),
|
||||
bids: bids,
|
||||
author_roles: author_roles,
|
||||
|
||||
Reference in New Issue
Block a user