2019-12-07 21:38:35 +13:00
|
|
|
defmodule Ash.Test.Resource.ApiTest do
|
2020-06-02 17:47:25 +12:00
|
|
|
@moduledoc false
|
2019-12-07 21:38:35 +13:00
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
2023-10-20 23:07:34 +13:00
|
|
|
defmodule Api do
|
|
|
|
use Ash.Api
|
2019-12-07 21:38:35 +13:00
|
|
|
|
2023-10-20 23:07:34 +13:00
|
|
|
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
|
2019-12-07 21:38:35 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-10-20 23:07:34 +13:00
|
|
|
|
|
|
|
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
|
2019-12-07 21:38:35 +13:00
|
|
|
end
|