mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
test: add tests for integers
This commit is contained in:
parent
be91d777f1
commit
7cb007d32d
1 changed files with 40 additions and 0 deletions
40
test/type/integer_test.exs
Normal file
40
test/type/integer_test.exs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
defmodule Ash.Test.Type.IntegerTest do
|
||||||
|
@moduledoc false
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
require Ash.Query
|
||||||
|
|
||||||
|
describe "atomic validation" do
|
||||||
|
test "valid value" do
|
||||||
|
{:atomic, expr} = Ash.Type.Integer.cast_atomic(1, min: 0, max: 2)
|
||||||
|
|
||||||
|
assert Ash.Expr.eval!(expr) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
test "invalid values" do
|
||||||
|
assert_raise Ash.Error.Changes.InvalidChanges, ~r/must be greater than or equal to 2/, fn ->
|
||||||
|
{:atomic, expr} = Ash.Type.Integer.cast_atomic(1, min: 2, max: 4)
|
||||||
|
Ash.Expr.eval!(expr)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raise Ash.Error.Changes.InvalidChanges, ~r/must be less than or equal to 4/, fn ->
|
||||||
|
{:atomic, expr} = Ash.Type.Integer.cast_atomic(5, min: 2, max: 4)
|
||||||
|
Ash.Expr.eval!(expr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "validation" do
|
||||||
|
test "valid value" do
|
||||||
|
assert {:ok, 1} = Ash.Type.Integer.cast_input(1, min: 0, max: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "invalid values" do
|
||||||
|
assert {:error, [[message: "must be more than or equal to %{min}", min: 2]]} =
|
||||||
|
Ash.Type.Integer.apply_constraints(1, min: 2, max: 4)
|
||||||
|
|
||||||
|
assert {:error, [[message: "must be less than or equal to %{max}", max: 4]]} =
|
||||||
|
Ash.Type.Integer.apply_constraints(5, min: 2, max: 4)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue