forked from ash-project/ash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_test.exs
More file actions
49 lines (44 loc) · 1.54 KB
/
array_test.exs
File metadata and controls
49 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
defmodule Ash.Test.Type.ArrayTest do
@moduledoc false
use ExUnit.Case, async: true
@default_constraints [
nil_items?: false,
remove_nil_items?: false,
empty_values: [""]
]
test "it errors when containing a nil value" do
assert {:error, [[message: "no nil values", index: 1]]} =
Ash.Type.apply_constraints(
{:array, :string},
["something", nil],
@default_constraints
)
end
test "it errors when containing an empty string (which is converted to nil by the string type)" do
assert {:error, [[message: "no nil values", index: 1]]} =
Ash.Type.apply_constraints(
{:array, :string},
["something", ""],
@default_constraints
)
end
test "it removes nil values instead of erroring with remove_nil_items?: true" do
assert {:ok, ["something", "something else"]} =
Ash.Type.apply_constraints(
{:array, :string},
["something", nil, nil, "something else"],
Keyword.put(@default_constraints, :remove_nil_items?, true)
)
end
test "it errors when array length is below min_length constraint" do
assert {:error, [message: "must have %{min} or more items", min: 1]} =
Ash.Type.apply_constraints(
{:array, :string},
[""],
Keyword.merge(@default_constraints,
min_length: 1,
remove_nil_items?: true
)
)
end
end