ash/test/api/api_test.exs
Zach Daniel 1ab5a35d7f
improvement: support an api option to use Ash.Resource (#715)
* improvement: support an `api` option to `use Ash.Resource`
improvement: add functions to `Ash` for resources w/ configured apis
improvement: default code_interface.define_for to resource's ash api
2023-10-20 06:07:34 -04:00

47 lines
945 B
Elixir

defmodule Ash.Test.Resource.ApiTest do
@moduledoc false
use ExUnit.Case, async: true
defmodule Api do
use Ash.Api
resources do
allow_unregistered? true
end
end
defmodule Foo do
use Ash.Resource, api: Api
actions do
defaults [:create, :read]
end
attributes do
uuid_primary_key :id
end
end
test "cannot define a resource that points to an api that doesn't accept it" do
assert_raise RuntimeError, ~r/api does not accept this resource/, fn ->
defmodule NoResourcesApi do
use Ash.Api
end
defmodule Bar do
use Ash.Resource, api: NoResourcesApi
attributes do
uuid_primary_key :id
end
end
end
end
test "a resource defined with an api can be used with functions in `Ash`" do
assert %Foo{} =
Foo
|> Ash.Changeset.for_create(:create)
|> Ash.create!()
end
end