2024-09-12 08:32:18 +12:00
|
|
|
defmodule Ash.Test.Resource.BuilderTest do
|
|
|
|
@moduledoc false
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
|
|
|
alias Ash.Resource.Builder
|
|
|
|
|
|
|
|
defmodule Change do
|
|
|
|
use Ash.Resource.Change
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def init(opts) do
|
|
|
|
{:ok, opts}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def change(%Ash.Changeset{} = changeset, _opts, _context) do
|
|
|
|
changeset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule Validation do
|
|
|
|
use Ash.Resource.Validation
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def init(opts) do
|
|
|
|
{:ok, opts}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def validate(%Ash.Changeset{} = _changeset, _opts, _context) do
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "resource builder" do
|
|
|
|
test "build action change" do
|
2024-09-12 11:59:58 +12:00
|
|
|
assert {:ok, %Ash.Resource.Change{}} =
|
|
|
|
Builder.build_action_change({Ash.Test.Resource.BuilderTest.Change, []})
|
2024-09-12 08:32:18 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
test "build action validation" do
|
2024-09-12 11:59:58 +12:00
|
|
|
assert {:ok, %Ash.Resource.Validation{}} =
|
|
|
|
Builder.build_action_validation({Ash.Test.Resource.BuilderTest.Change, []})
|
2024-09-12 08:32:18 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|