ash_postgres/test/ash_postgres_test.exs
Zach Daniel 37cc01957d
improvement!: 3.0 (#227)
* WIP

* chore: fix mix.lock merge issues

* improvement: upgrade to 3.0

* chore: remove `repo.to_tenant`

* chore: continue removal of unnecessary helper

* chore: use `Ash.ToTenant`
2024-03-27 16:52:28 -04:00

36 lines
933 B
Elixir

defmodule AshPostgresTest do
use AshPostgres.RepoCase, async: false
test "transaction metadata is given to on_transaction_begin" do
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "title"})
|> Ash.create!()
assert_receive %{
type: :create,
metadata: %{action: :create, actor: nil, resource: AshPostgres.Test.Post}
}
end
test "filter policies are applied" do
post =
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "good"})
|> Ash.create!()
assert_raise Ash.Error.Forbidden, fn ->
post
|> Ash.Changeset.for_update(:update, %{title: "bad"},
authorize?: true,
actor: %{id: Ash.UUID.generate()}
)
|> Ash.update!()
|> Map.get(:title)
end
post
|> Ash.Changeset.for_update(:update, %{title: "okay"}, authorize?: true)
|> Ash.update!()
|> Map.get(:title)
end
end