· 7 years ago · Jan 31, 2019, 09:38 PM
1defmodule YourOperation do
2 use Exop.Operation
3
4 parameter(:users, type: :list, list_item: [type: :map, inner: %{email: [type: :string, format: ~r/@/]}])
5
6 def process(_params), do: #smth
7end
8
9
10defmodule YourTest do
11 use ExUnit.Case, async: true
12 use ExUnitProperties
13
14 property "YourOperation does smth" do
15 domains = ["gmail.com", "hotmail.com", "yahoo.com"]
16
17 email_generator =
18 gen all name <- string(:alphanumeric),
19 name != "",
20 domain <- member_of(domains) do
21 name <> "@" <> domain
22 end
23
24 custom_generators = %{users: [%{email: email_generator}]}
25
26 check all params <- ExopData.generate(YourOperation, generators: custom_generators) do
27 assert YourOperation.run(params) == {:ok, _some_result}
28 end
29 end
30end
31
32#iex> YourOperation |> ExopData.generate(generators: %{users: [%{email: email_generator}]}) |> Enum.take(2)
33[
34 %{users: [%{email: "efsT6Px@hotmail.com"}]},
35 %{users: [%{email: "swEowmk7mW0VmkJDF@yahoo.com"}]}
36]